Skip to content

Commit 3a0d61f

Browse files
committed
Release v1.3.1: update option, SSH MAC fix, DNS/Xray hardening
New: - Update option in TUI menu (10) and --update flag - SSH MAC compatibility fix for Bitvise/older clients (non-ETM fallbacks) Hardened: - DNS: EXIT trap, resolv.conf backup + lock, fallback nameservers - microsocks: proactive GLIBC check, dpkg lock wait - NoizDNS: self-hosted binaries, file-based validation - 3x-ui: bcrypt password handling, port via binary, JSON login validation - sshd_config: backup + sshd -t validation + auto-rollback
1 parent ecbb36f commit 3a0d61f

1 file changed

Lines changed: 121 additions & 6 deletions

File tree

dnstm-setup.sh

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# dnstm-setup v1.3
3+
# dnstm-setup v1.3.1
44
# Interactive DNS Tunnel Setup
55
# Sets up Slipstream + DNSTT + NoizDNS tunnels for censorship-resistant internet access
66
#
@@ -10,7 +10,7 @@
1010

1111
set -euo pipefail
1212

13-
VERSION="1.3"
13+
VERSION="1.3.1"
1414
TOTAL_STEPS=12
1515

1616
# ─── Safety: ensure DNS is never left broken on exit ──────────────────────────
@@ -503,6 +503,7 @@ show_help() {
503503
echo " --users Manage SSH tunnel users (add, list, update, delete)"
504504
echo " --mtu <value> Set DNSTT MTU size (512-1400, default: 1232)"
505505
echo " --harden Apply service and resolver hardening to an existing setup"
506+
echo " --update Check for updates and install latest version"
506507
echo " --uninstall Remove all installed components"
507508
echo ""
508509
echo -e "${BOLD}WHAT THIS SCRIPT SETS UP${NC}"
@@ -1944,6 +1945,100 @@ do_add_tunnel() {
19441945

19451946
# ─── --uninstall ────────────────────────────────────────────────────────────────
19461947

1948+
do_update() {
1949+
print_header "Update dnstm-setup"
1950+
1951+
local REPO_URL="https://raw.githubusercontent.com/SamNet-dev/dnstm-setup/master/dnstm-setup.sh"
1952+
local current_version="$VERSION"
1953+
1954+
# Find the script path early so we can bail if it's not writable
1955+
local script_path
1956+
script_path=$(readlink -f "$0" 2>/dev/null || realpath "$0" 2>/dev/null || echo "$0")
1957+
if [[ ! -f "$script_path" ]]; then
1958+
print_fail "Cannot determine script location. Run update manually:"
1959+
print_info "curl -sO ${REPO_URL} && chmod +x dnstm-setup.sh"
1960+
echo ""
1961+
read -rp " Press Enter to return to menu..." _
1962+
return 1
1963+
fi
1964+
1965+
# Download to temp file
1966+
print_info "Checking for updates..."
1967+
local tmp_file="${script_path}.tmp"
1968+
if ! curl -fsSL --max-time 15 -o "$tmp_file" "$REPO_URL" 2>/dev/null; then
1969+
print_fail "Could not reach GitHub. Check your internet connection."
1970+
rm -f "$tmp_file" 2>/dev/null || true
1971+
echo ""
1972+
read -rp " Press Enter to return to menu..." _
1973+
return 1
1974+
fi
1975+
1976+
# Validate: must be a bash script
1977+
if ! head -1 "$tmp_file" 2>/dev/null | grep -q "bash"; then
1978+
print_fail "Downloaded file is not a valid script"
1979+
rm -f "$tmp_file"
1980+
echo ""
1981+
read -rp " Press Enter to return to menu..." _
1982+
return 1
1983+
fi
1984+
1985+
# Extract remote version
1986+
local remote_version
1987+
remote_version=$(grep -m1 '^VERSION=' "$tmp_file" | sed 's/VERSION="//;s/"//')
1988+
1989+
if [[ -z "$remote_version" ]]; then
1990+
print_warn "Could not detect remote version"
1991+
rm -f "$tmp_file"
1992+
echo ""
1993+
read -rp " Press Enter to return to menu..." _
1994+
return 1
1995+
fi
1996+
1997+
echo -e " Current version: ${YELLOW}v${current_version}${NC}"
1998+
echo -e " Latest version: ${GREEN}v${remote_version}${NC}"
1999+
echo ""
2000+
2001+
if [[ "$current_version" == "$remote_version" ]]; then
2002+
print_ok "You are already on the latest version."
2003+
rm -f "$tmp_file"
2004+
echo ""
2005+
read -rp " Press Enter to return to menu..." _
2006+
return 0
2007+
fi
2008+
2009+
if ! prompt_yn "Update to v${remote_version}?" "y"; then
2010+
print_info "Update cancelled."
2011+
rm -f "$tmp_file"
2012+
echo ""
2013+
read -rp " Press Enter to return to menu..." _
2014+
return 0
2015+
fi
2016+
2017+
# Fix CRLF line endings if any
2018+
sed -i 's/\r$//' "$tmp_file" 2>/dev/null || true
2019+
2020+
# Replace script
2021+
chmod +x "$tmp_file"
2022+
mv -f "$tmp_file" "$script_path"
2023+
2024+
# Also update /usr/local/bin if installed there
2025+
if [[ -f /usr/local/bin/dnstm-setup ]] && [[ "$script_path" != "/usr/local/bin/dnstm-setup" ]]; then
2026+
cp -f "$script_path" /usr/local/bin/dnstm-setup
2027+
chmod +x /usr/local/bin/dnstm-setup
2028+
fi
2029+
2030+
echo ""
2031+
print_ok "Updated to v${remote_version}!"
2032+
print_info "Restarting with new version..."
2033+
echo ""
2034+
sleep 1
2035+
2036+
# Signal the parent menu loop to re-exec (write a marker file)
2037+
local update_marker="/tmp/.dnstm-update-reexec"
2038+
echo "$script_path" > "$update_marker"
2039+
exit 0
2040+
}
2041+
19472042
do_uninstall() {
19482043
banner
19492044

@@ -3619,13 +3714,14 @@ do_manage() {
36193714
echo -e " ${BOLD}9)${NC} Change DNSTT MTU ${DIM}(change MTU on existing DNSTT tunnels)${NC}"
36203715
echo ""
36213716
echo -e " ${DIM}──────────────────────────────────────────────${NC}"
3622-
echo -e " ${BOLD}${RED}10)${NC} ${RED}Uninstall everything${NC}"
3717+
echo -e " ${BOLD}10)${NC} Update script ${DIM}(check for new versions)${NC}"
3718+
echo -e " ${BOLD}${RED}11)${NC} ${RED}Uninstall everything${NC}"
36233719
echo ""
36243720
echo -e " ${BOLD}0)${NC} Exit"
36253721
echo ""
36263722

36273723
local choice=""
3628-
read -rp " Select [0-10]: " choice || break
3724+
read -rp " Select [0-11]: " choice || break
36293725

36303726
case "$choice" in
36313727
1)
@@ -3656,6 +3752,16 @@ do_manage() {
36563752
( trap - INT; do_change_mtu ) || true
36573753
;;
36583754
10)
3755+
( trap - INT; do_update ) || true
3756+
# If update wrote the re-exec marker, restart with new version
3757+
if [[ -f /tmp/.dnstm-update-reexec ]]; then
3758+
local reexec_path
3759+
reexec_path=$(cat /tmp/.dnstm-update-reexec)
3760+
rm -f /tmp/.dnstm-update-reexec
3761+
exec bash "$reexec_path" --manage
3762+
fi
3763+
;;
3764+
11)
36593765
( trap - INT; do_uninstall ) || true
36603766
# If uninstall succeeded, dnstm is gone — exit menu
36613767
hash -d dnstm 2>/dev/null || true
@@ -3674,7 +3780,7 @@ do_manage() {
36743780
continue
36753781
;;
36763782
*)
3677-
print_warn "Invalid choice. Enter 0-10."
3783+
print_warn "Invalid choice. Enter 0-11."
36783784
sleep 1
36793785
continue
36803786
;;
@@ -5205,6 +5311,7 @@ step_summary() {
52055311
echo " - Manage SSH tunnel users"
52065312
echo " - Change DNSTT MTU"
52075313
echo " - View status, logs, and share URLs"
5314+
echo " - Update to latest version"
52085315
echo " - Harden or uninstall"
52095316
echo ""
52105317

@@ -5742,6 +5849,7 @@ ADD_DOMAIN_MODE=false
57425849
ADD_DOMAIN_ARG=""
57435850
ADD_XRAY_MODE=false
57445851
HARDEN_ONLY_MODE=false
5852+
UPDATE_MODE=false
57455853
MANAGE_USERS_MODE=false
57465854
DNSTT_MTU=1232
57475855

@@ -5802,6 +5910,10 @@ while [[ $# -gt 0 ]]; do
58025910
HARDEN_ONLY_MODE=true
58035911
shift
58045912
;;
5913+
--update)
5914+
UPDATE_MODE=true
5915+
shift
5916+
;;
58055917
--mtu)
58065918
if [[ -n "${2:-}" ]] && [[ "$2" =~ ^[0-9]+$ ]] && [[ "$2" -ge 512 ]] && [[ "$2" -le 1400 ]]; then
58075919
DNSTT_MTU="$2"
@@ -5825,9 +5937,10 @@ mode_count=0
58255937
[[ "$ADD_DOMAIN_MODE" == true ]] && ((mode_count++)) || true
58265938
[[ "$ADD_XRAY_MODE" == true ]] && ((mode_count++)) || true
58275939
[[ "$HARDEN_ONLY_MODE" == true ]] && ((mode_count++)) || true
5940+
[[ "$UPDATE_MODE" == true ]] && ((mode_count++)) || true
58285941
[[ "$MANAGE_USERS_MODE" == true ]] && ((mode_count++)) || true
58295942
if [[ $mode_count -gt 1 ]]; then
5830-
echo "Error: --add-domain, --add-xray, --harden, and --users cannot be combined."
5943+
echo "Error: --add-domain, --add-xray, --harden, --update, and --users cannot be combined."
58315944
exit 1
58325945
fi
58335946

@@ -5854,6 +5967,8 @@ main() {
58545967

58555968
if [[ "$HARDEN_ONLY_MODE" == true ]]; then
58565969
do_harden
5970+
elif [[ "$UPDATE_MODE" == true ]]; then
5971+
do_update
58575972
elif [[ "$ADD_DOMAIN_MODE" == true ]]; then
58585973
do_add_domain
58595974
elif [[ "$ADD_XRAY_MODE" == true ]]; then

0 commit comments

Comments
 (0)