From fe3ebbe5930f8d73455381a6bc3f115e6e3abc20 Mon Sep 17 00:00:00 2001 From: dperegudov Date: Thu, 17 Sep 2026 11:42:11 +0300 Subject: [PATCH] add quick-install aftercheck --- quick-install.sh | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/quick-install.sh b/quick-install.sh index 1842c92..61c5f20 100644 --- a/quick-install.sh +++ b/quick-install.sh @@ -94,6 +94,113 @@ start_service() { systemctl status "$SERVICE_NAME" --no-pager || true } +# Extract a JSON string field value (flat JSON): json_get "" "" +json_get() { + printf '%s' "$1" \ + | grep -oE "\"$2\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" \ + | head -1 \ + | sed -E "s/^\"$2\"[[:space:]]*:[[:space:]]*\"//; s/\"$//" +} + +# Probe ip-api.com through a local SOCKS5 proxy on the given port. +# Prints 8 values separated by 0x1F: latency, status, country, regionName, +# city, timezone, isp, query. +probe_values() { + local port="$1" + local sep=$'\037' + local resp tsec body ms status country regionName city timezone isp query + + resp=$(curl -s --connect-timeout 8 --max-time 15 \ + --proxy "socks5h://127.0.0.1:${port}" \ + -w $'\n%{time_total}' "http://ip-api.com/json" 2>/dev/null) + + tsec=$(printf '%s' "$resp" | tail -n1) + body=$(printf '%s' "$resp" | sed '$d') + + if [ -z "$body" ] || ! printf '%s' "$body" | grep -q '"status"'; then + printf 'ERR%sno response%s-%s-%s-%s-%s-%s-' \ + "$sep" "$sep" "$sep" "$sep" "$sep" "$sep" "$sep" + return + fi + + ms=$(awk "BEGIN{printf \"%d\", ${tsec:-0}*1000}") + status=$(json_get "$body" status) + country=$(json_get "$body" country) + regionName=$(json_get "$body" regionName) + city=$(json_get "$body" city) + timezone=$(json_get "$body" timezone) + isp=$(json_get "$body" isp) + query=$(json_get "$body" query) + + printf '%sms%s%s%s%s%s%s%s%s%s%s%s%s%s%s' \ + "$ms" "$sep" "$status" "$sep" "$country" "$sep" "$regionName" \ + "$sep" "$city" "$sep" "$timezone" "$sep" "$isp" "$sep" "$query" +} + +# Pad a string with trailing spaces to a given display width (char count). +_pad() { + local s="$1" w="$2" len=${#1} i + printf '%s' "$s" + i=$len + while [ "$i" -lt "$w" ]; do printf ' '; i=$((i + 1)); done +} + +_dashes() { + local i=0 + while [ "$i" -lt "$1" ]; do printf -- '-'; i=$((i + 1)); done +} + +check_outbounds() { + if ! command -v curl >/dev/null 2>&1; then + echo "curl not found, cannot run checks." >&2 + return 1 + fi + + local labels=("ms до ответа" "status" "country" "regionName" "city" "timezone" "isp" "query") + local n=${#labels[@]} + local -a warp_col=() proton_col=() + local have_warp="$ENABLE_WARP" have_proton="$ENABLE_PROTON" + local w0=4 ww=4 wp=6 # widths of "поле" / "warp" / "proton" + local i + + if [ "$have_warp" -eq 1 ]; then + echo "Probing WARP (socks5://127.0.0.1:2080) ..." + IFS=$'\037' read -r -a warp_col <<< "$(probe_values 2080)" + fi + if [ "$have_proton" -eq 1 ]; then + echo "Probing Proton (socks5://127.0.0.1:3080) ..." + IFS=$'\037' read -r -a proton_col <<< "$(probe_values 3080)" + fi + + for ((i = 0; i < n; i++)); do + [ ${#labels[i]} -gt "$w0" ] && w0=${#labels[i]} + if [ "$have_warp" -eq 1 ]; then [ ${#warp_col[i]} -gt "$ww" ] && ww=${#warp_col[i]}; fi + if [ "$have_proton" -eq 1 ]; then [ ${#proton_col[i]} -gt "$wp" ] && wp=${#proton_col[i]}; fi + done + + _sep_line() { + printf '+'; _dashes $((w0 + 2)); printf '+' + [ "$have_warp" -eq 1 ] && { _dashes $((ww + 2)); printf '+'; } + [ "$have_proton" -eq 1 ] && { _dashes $((wp + 2)); printf '+'; } + printf '\n' + } + _row() { + printf '| '; _pad "$1" "$w0"; printf ' |' + [ "$have_warp" -eq 1 ] && { printf ' '; _pad "$2" "$ww"; printf ' |'; } + [ "$have_proton" -eq 1 ] && { printf ' '; _pad "$3" "$wp"; printf ' |'; } + printf '\n' + } + + echo "" + _sep_line + _row "поле" "warp" "proton" + _sep_line + for ((i = 0; i < n; i++)); do + _row "${labels[i]}" "${warp_col[i]:--}" "${proton_col[i]:--}" + done + _sep_line +} + echo "=== Sing-Box WARP Quick Installer ===" echo "" @@ -347,16 +454,30 @@ fi echo " Default route for non-SOCKS traffic: $DEFAULT_ROUTE" echo "" +SERVICE_STARTED=0 if [ "$REINSTALL" -eq 1 ]; then echo "Reinstall complete, starting service..." start_service + SERVICE_STARTED=1 else read -p "Start service now? (y/n) " -n 1 -r < /dev/tty echo if [[ $REPLY =~ ^[Yy]$ ]]; then start_service + SERVICE_STARTED=1 fi fi +echo "" +read -p "Проверить созданные ауты? (y/n) " -n 1 -r < /dev/tty +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + if [ "$SERVICE_STARTED" -eq 0 ] && ! systemctl is-active --quiet "$SERVICE_NAME"; then + echo "Service is not running — starting it for the check..." + start_service + fi + check_outbounds +fi + echo "" echo "Done!"