Skip to content

Commit 2eb9c4f

Browse files
Refactor: Extract architecture detection into reusable function
- Create detect_architecture() function to map uname output to binary suffixes - Supports: 386, amd64, arm64, armv7 - Replace hardcoded 'amd64' with dynamic detection in: - do_manage_users() - step_install_dnstm() - step_ssh_user() - Improves compatibility with non-x86_64 systems
1 parent afb10e6 commit 2eb9c4f

1 file changed

Lines changed: 43 additions & 9 deletions

File tree

dnstm-setup.sh

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,34 @@ do_uninstall() {
906906
echo ""
907907
}
908908

909+
# ─── Architecture Detection ────────────────────────────────────────────────────
910+
911+
detect_architecture() {
912+
# Detect system architecture using uname and map it to binary suffix
913+
# Supports: 386, amd64, arm64, armv7
914+
local machine_arch
915+
machine_arch=$(uname -m)
916+
917+
case "$machine_arch" in
918+
x86_64|amd64)
919+
echo "amd64"
920+
;;
921+
i386|i686)
922+
echo "386"
923+
;;
924+
aarch64|arm64)
925+
echo "arm64"
926+
;;
927+
armv7l|armv7)
928+
echo "armv7"
929+
;;
930+
*)
931+
print_warn "Unsupported architecture: $machine_arch (defaulting to amd64)"
932+
echo "amd64"
933+
;;
934+
esac
935+
}
936+
909937
# ─── User Management TUI ──────────────────────────────────────────────────────
910938

911939
do_manage_users() {
@@ -921,11 +949,13 @@ do_manage_users() {
921949
# Install sshtun-user if not present
922950
if ! command -v sshtun-user &>/dev/null; then
923951
print_info "sshtun-user not found. Installing..."
924-
if curl -fsSL -o /usr/local/bin/sshtun-user https://github.com/net2share/sshtun-user/releases/latest/download/sshtun-user-linux-amd64; then
952+
local arch
953+
arch=$(detect_architecture)
954+
if curl -fsSL -o /usr/local/bin/sshtun-user "https://github.com/net2share/sshtun-user/releases/latest/download/sshtun-user-linux-${arch}"; then
925955
chmod +x /usr/local/bin/sshtun-user
926-
print_ok "Downloaded sshtun-user"
956+
print_ok "Downloaded sshtun-user for ${arch}"
927957
else
928-
print_fail "Failed to download sshtun-user. Check your internet connection."
958+
print_fail "Failed to download sshtun-user for ${arch} architecture. Check your internet connection."
929959
exit 1
930960
fi
931961

@@ -1360,11 +1390,13 @@ step_install_dnstm() {
13601390

13611391
# Download binary
13621392
print_info "Downloading dnstm..."
1363-
if curl -fsSL -o /usr/local/bin/dnstm https://github.com/net2share/dnstm/releases/latest/download/dnstm-linux-amd64; then
1393+
local arch
1394+
arch=$(detect_architecture)
1395+
if curl -fsSL -o /usr/local/bin/dnstm "https://github.com/net2share/dnstm/releases/latest/download/dnstm-linux-${arch}"; then
13641396
chmod +x /usr/local/bin/dnstm
1365-
print_ok "Downloaded dnstm binary"
1397+
print_ok "Downloaded dnstm binary for ${arch}"
13661398
else
1367-
print_fail "Failed to download dnstm"
1399+
print_fail "Failed to download dnstm for ${arch} architecture"
13681400
exit 1
13691401
fi
13701402

@@ -1772,11 +1804,13 @@ step_ssh_user() {
17721804
# Install sshtun-user if not present
17731805
if ! command -v sshtun-user &>/dev/null; then
17741806
print_info "Downloading sshtun-user..."
1775-
if curl -fsSL -o /usr/local/bin/sshtun-user https://github.com/net2share/sshtun-user/releases/latest/download/sshtun-user-linux-amd64; then
1807+
local arch
1808+
arch=$(detect_architecture)
1809+
if curl -fsSL -o /usr/local/bin/sshtun-user "https://github.com/net2share/sshtun-user/releases/latest/download/sshtun-user-linux-${arch}"; then
17761810
chmod +x /usr/local/bin/sshtun-user
1777-
print_ok "Downloaded sshtun-user"
1811+
print_ok "Downloaded sshtun-user for ${arch}"
17781812
else
1779-
print_fail "Failed to download sshtun-user"
1813+
print_fail "Failed to download sshtun-user for ${arch} architecture"
17801814
return
17811815
fi
17821816
else

0 commit comments

Comments
 (0)