ops installer: take secrets from ~/.brovops-sub and ~/.brovops-token
So the install can run non-interactively over SSH: the files are moved into /etc/brov-ops and deleted; hidden prompts remain as the fallback in a terminal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-4
@@ -6,8 +6,10 @@
|
||||
# /etc/brov-ops (root, 600). Telegram and Claude go through a local proxy core (mihomo in
|
||||
# proxy mode on 127.0.0.1:7890 — only this service uses it, the VM itself is not tunnelled).
|
||||
#
|
||||
# Asks (hidden input) for the VLESS subscription URL and the Telegram bot token on the
|
||||
# first run. The first person to send /start to the bot becomes its owner.
|
||||
# Secrets on the first run: the VLESS subscription URL and the Telegram bot token are taken
|
||||
# from ~/.brovops-sub and ~/.brovops-token of the user running sudo (moved into
|
||||
# /etc/brov-ops and deleted), or asked for with hidden input when run from a terminal.
|
||||
# The first person to send /start to the bot becomes its owner.
|
||||
|
||||
set -e
|
||||
[ "$(id -u)" -eq 0 ] || { echo "Запусти через sudo: sudo sh $0"; exit 1; }
|
||||
@@ -38,13 +40,19 @@ if [ "$(sha256sum /usr/local/bin/mihomo 2>/dev/null | cut -d' ' -f1)" != "$MIHOM
|
||||
install -m 755 "$TMP/mihomo" /usr/local/bin/mihomo
|
||||
rm -rf "$TMP"
|
||||
fi
|
||||
USER_HOME=$(getent passwd "${SUDO_USER:-root}" | cut -d: -f6)
|
||||
take_file() { # ~/.brovops-<name> → stdout, then removed
|
||||
f="$USER_HOME/.brovops-$1"
|
||||
[ -f "$f" ] && [ ! -L "$f" ] && { cat "$f"; rm -f "$f"; }
|
||||
}
|
||||
ask_secret() { # prompt → stdout, input not echoed
|
||||
printf "%s" "$1" > /dev/tty
|
||||
stty -echo < /dev/tty; read -r v < /dev/tty; stty echo < /dev/tty; echo > /dev/tty
|
||||
printf "%s" "$v"
|
||||
}
|
||||
if [ ! -s $PROXY_DIR/vless.sub ]; then
|
||||
ask_secret "Ссылка подписки VLESS (ввод скрыт): " > $PROXY_DIR/vless.sub
|
||||
take_file sub > $PROXY_DIR/vless.sub
|
||||
[ -s $PROXY_DIR/vless.sub ] || ask_secret "Ссылка подписки VLESS (ввод скрыт): " > $PROXY_DIR/vless.sub
|
||||
[ -s $PROXY_DIR/vless.sub ] || { echo "✗ подписка не введена"; exit 1; }
|
||||
fi
|
||||
SUB=$(head -n1 $PROXY_DIR/vless.sub | tr -d '\r\n ')
|
||||
@@ -102,7 +110,8 @@ if [ ! -f $ETC/config.env ]; then
|
||||
-e "s|^WHISPER_MODEL=.*|WHISPER_MODEL=$WHISPER|" "$HERE/deploy/config.env.example" > $ETC/config.env
|
||||
fi
|
||||
if ! grep -q "^TELEGRAM_TOKEN=." $ETC/config.env; then
|
||||
TOK=$(ask_secret "Токен бота от @BotFather (ввод скрыт): ")
|
||||
TOK=$(take_file token)
|
||||
[ -n "$TOK" ] || TOK=$(ask_secret "Токен бота от @BotFather (ввод скрыт): ")
|
||||
if [ -n "$TOK" ]; then
|
||||
grep -v "^TELEGRAM_TOKEN=" $ETC/config.env > $ETC/config.env.new
|
||||
echo "TELEGRAM_TOKEN=$TOK" >> $ETC/config.env.new
|
||||
|
||||
Reference in New Issue
Block a user