mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 14:36:05 +00:00
feat(v2.4.2): bot non-interactive install.sh actions
- install.sh: new bot_action_dispatch entry point for --action=X --json CLI invocation from the bot/scripts - install.sh: bot_action_change_template — reuses download_template + deploy_template_to_nginx, updates config.json template_id - install.sh: bot_action_change_lite_domain — regenerates telemt TOML with new fake-TLS mask domain, restarts telemt - bot.py: run_bot_action() subprocess wrapper parses JSON result - bot.py: cb_pro_confirm now performs real change-template when already in pro mode (fresh install still routes to CLI) - bot.py: cb_lite_domain now performs real change-lite-domain when already in lite mode - version -> 2.4.2
This commit is contained in:
156
lib/common.sh
Normal file → Executable file
156
lib/common.sh
Normal file → Executable file
@@ -3,7 +3,7 @@
|
||||
# Colors, logging, spinner, system helpers, v1 compat, i18n-aware
|
||||
|
||||
# ── Version ───────────────────────────────────────────────────────────────────
|
||||
GOTELEGRAM_VERSION="2.4.1"
|
||||
GOTELEGRAM_VERSION="2.4.2"
|
||||
GOTELEGRAM_NAME="GoTelegram"
|
||||
|
||||
# ── Пути ──────────────────────────────────────────────────────────────────────
|
||||
@@ -247,25 +247,149 @@ install_pkg() {
|
||||
esac
|
||||
}
|
||||
|
||||
# ── Зависимости GoTelegram ──────────────────────────────────────────────────
|
||||
# Полный список внешних команд, которые скрипт использует. Для каждой команды
|
||||
# указан пакет на apt и dnf/yum (имена различаются: например dig = dnsutils на
|
||||
# Debian, bind-utils на RHEL).
|
||||
#
|
||||
# КРИТИЧЕСКИЕ (без них скрипт просто не работает):
|
||||
# jq — парсинг config.json, templates_catalog.json
|
||||
# curl — скачивание telemt и проверки HTTPS
|
||||
# openssl — генерация секретов, шифрование бекапов, SSL проверка
|
||||
# git — клонирование шаблонов через download_template
|
||||
# xxd — hex-encode домена для fake-TLS секрета (ee-prefix)
|
||||
# tar — распаковка telemt архива и бекапы
|
||||
# dig — DNS-проверка домена в Pro-режиме
|
||||
#
|
||||
# ЖЕЛАТЕЛЬНЫЕ (есть fallback, но с ними лучше):
|
||||
# qrencode — QR-коды для прокси-ссылок
|
||||
# bc — красивое форматирование чисел в статистике
|
||||
#
|
||||
# Pro-режим доустанавливает nginx/certbot через install_nginx/install_certbot
|
||||
# (они большие и нужны только если пользователь выбрал Pro).
|
||||
|
||||
# Маппинг команды -> (apt_pkg, dnf_pkg). apt_pkg_for_cmd <cmd>
|
||||
apt_pkg_for_cmd() {
|
||||
case "$1" in
|
||||
dig) echo "dnsutils" ;;
|
||||
xxd) echo "xxd" ;; # Ubuntu 22+: отдельный пакет, fallback ниже
|
||||
nslookup) echo "dnsutils" ;;
|
||||
host) echo "dnsutils" ;;
|
||||
ss) echo "iproute2" ;;
|
||||
netstat) echo "net-tools" ;;
|
||||
*) echo "$1" ;; # команда == имя пакета
|
||||
esac
|
||||
}
|
||||
|
||||
dnf_pkg_for_cmd() {
|
||||
case "$1" in
|
||||
dig|nslookup|host) echo "bind-utils" ;;
|
||||
xxd) echo "vim-common" ;;
|
||||
ss) echo "iproute" ;;
|
||||
netstat) echo "net-tools" ;;
|
||||
*) echo "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
ensure_deps() {
|
||||
local missing=()
|
||||
for cmd in curl jq openssl git qrencode; do
|
||||
if ! command -v "$cmd" &>/dev/null; then
|
||||
missing+=("$cmd")
|
||||
fi
|
||||
# Критические зависимости — без них скрипт не работает
|
||||
local critical=(curl jq openssl git xxd tar dig)
|
||||
# Желательные — есть fallback, устанавливать всё равно, но не падать если не смогли
|
||||
local optional=(qrencode bc)
|
||||
|
||||
local missing_critical=() missing_optional=() cmd
|
||||
for cmd in "${critical[@]}"; do
|
||||
command -v "$cmd" &>/dev/null || missing_critical+=("$cmd")
|
||||
done
|
||||
if [ ${#missing[@]} -gt 0 ]; then
|
||||
if type tf &>/dev/null; then
|
||||
log_step "$(tf deps_installing "${missing[*]}")"
|
||||
else
|
||||
log_step "Installing dependencies: ${missing[*]}"
|
||||
fi
|
||||
case "$(get_pkg_manager)" in
|
||||
apt) apt-get update -qq && apt-get install -y -qq "${missing[@]}" ;;
|
||||
dnf) dnf install -y -q "${missing[@]}" ;;
|
||||
yum) yum install -y -q "${missing[@]}" ;;
|
||||
for cmd in "${optional[@]}"; do
|
||||
command -v "$cmd" &>/dev/null || missing_optional+=("$cmd")
|
||||
done
|
||||
|
||||
local all_missing=("${missing_critical[@]}" "${missing_optional[@]}")
|
||||
[ ${#all_missing[@]} -eq 0 ] && return 0
|
||||
|
||||
# Собираем список пакетов для выбранного менеджера
|
||||
local pkg_mgr pkg pkgs=()
|
||||
pkg_mgr=$(get_pkg_manager)
|
||||
|
||||
for cmd in "${all_missing[@]}"; do
|
||||
case "$pkg_mgr" in
|
||||
apt) pkg=$(apt_pkg_for_cmd "$cmd") ;;
|
||||
dnf|yum) pkg=$(dnf_pkg_for_cmd "$cmd") ;;
|
||||
*) pkg="$cmd" ;;
|
||||
esac
|
||||
pkgs+=("$pkg")
|
||||
done
|
||||
|
||||
# Убираем дубликаты (например dig+nslookup оба = dnsutils)
|
||||
local uniq_pkgs=()
|
||||
for pkg in "${pkgs[@]}"; do
|
||||
local found=0 p
|
||||
for p in "${uniq_pkgs[@]}"; do
|
||||
[ "$p" = "$pkg" ] && { found=1; break; }
|
||||
done
|
||||
[ "$found" = "0" ] && uniq_pkgs+=("$pkg")
|
||||
done
|
||||
|
||||
if type tf &>/dev/null; then
|
||||
log_step "$(tf deps_installing "${all_missing[*]}")"
|
||||
else
|
||||
log_step "Installing dependencies: ${all_missing[*]} (packages: ${uniq_pkgs[*]})"
|
||||
fi
|
||||
|
||||
case "$pkg_mgr" in
|
||||
apt)
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq 2>/dev/null
|
||||
apt-get install -y -qq "${uniq_pkgs[@]}" 2>/dev/null
|
||||
;;
|
||||
dnf) dnf install -y -q "${uniq_pkgs[@]}" 2>/dev/null ;;
|
||||
yum) yum install -y -q "${uniq_pkgs[@]}" 2>/dev/null ;;
|
||||
*)
|
||||
log_error "Unknown package manager — install manually: ${uniq_pkgs[*]}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Фолбэки для xxd: на некоторых системах нужен vim-common вместо xxd
|
||||
if ! command -v xxd &>/dev/null && [ "$pkg_mgr" = "apt" ]; then
|
||||
apt-get install -y -qq vim-common 2>/dev/null
|
||||
fi
|
||||
|
||||
# Повторная проверка критических команд
|
||||
local still_missing=()
|
||||
for cmd in "${critical[@]}"; do
|
||||
command -v "$cmd" &>/dev/null || still_missing+=("$cmd")
|
||||
done
|
||||
|
||||
if [ ${#still_missing[@]} -gt 0 ]; then
|
||||
log_error "Critical dependencies still missing: ${still_missing[*]}"
|
||||
log_error "Install manually and re-run gotelegram"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Опциональные — только предупреждение
|
||||
local still_missing_opt=()
|
||||
for cmd in "${optional[@]}"; do
|
||||
command -v "$cmd" &>/dev/null || still_missing_opt+=("$cmd")
|
||||
done
|
||||
if [ ${#still_missing_opt[@]} -gt 0 ]; then
|
||||
log_warning "Optional deps missing (features degraded): ${still_missing_opt[*]}"
|
||||
fi
|
||||
|
||||
log_success "Dependencies ready"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Быстрая проверка — только смотрит что критические установлены, ничего не ставит.
|
||||
# Возвращает 0 если всё ок, 1 если что-то отсутствует. Используется на старте
|
||||
# main() чтобы не дёргать apt-get update при каждом запуске меню.
|
||||
check_deps_present() {
|
||||
local cmd
|
||||
for cmd in curl jq openssl git xxd tar dig; do
|
||||
command -v "$cmd" &>/dev/null || return 1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
check_port() {
|
||||
|
||||
Reference in New Issue
Block a user