From 49a5dec3531e06b7a41b82ef74703ab9416cee05 Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 4 Jan 2024 16:29:11 +0800 Subject: [PATCH 1/6] fix: if root, try to use SUDO_USER as the user --- packages/sshnoports/bundles/shell/install.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/sshnoports/bundles/shell/install.sh b/packages/sshnoports/bundles/shell/install.sh index 6e20b2f8d..f0561038c 100755 --- a/packages/sshnoports/bundles/shell/install.sh +++ b/packages/sshnoports/bundles/shell/install.sh @@ -1,22 +1,29 @@ #!/bin/sh # SYSTEM GIVENS # +is_root() { + [ "$(id -u)" -eq 0 ] +} + define_env() { script_dir="$(dirname -- "$( readlink -f -- "$0"; )")" bin_dir="/usr/local/bin" systemd_dir="/etc/systemd/system" - - user_home="$HOME" + if is_root; then + user="$SUDO_USER" + if [ -z "$user" ]; then + user="root" + fi + else + user="$USER" + fi + user_home=$(sudo -u "$user" sh -c 'echo $HOME') user_bin_dir="$user_home/.local/bin" user_sshnpd_dir="$user_home/.sshnpd" user_log_dir="$user_sshnpd_dir/logs" user_ssh_dir="$user_home/.ssh" } -is_root() { - [ "$(id -u)" -eq 0 ] -} - is_darwin() { [ "$(uname)" = 'Darwin' ] } @@ -85,6 +92,7 @@ install_single_binary() { cp "$script_dir/$1" "$dest/$1" echo "Installed $1 to $dest" if is_root & ! [ -f "$user_bin_dir/$1" ] ; then + mkdir -p "$user_bin_dir" ln -sf "$dest/$1" "$user_bin_dir/$1" echo "Linked $user_bin_dir/$1 to $dest" fi From ecd63a8f686e00398e8e6a1653f2acd1396b29b6 Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 4 Jan 2024 16:31:37 +0800 Subject: [PATCH 2/6] chore: add additional comments to sshnpd.sh headless template --- packages/sshnoports/bundles/shell/headless/sshnpd.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/sshnoports/bundles/shell/headless/sshnpd.sh b/packages/sshnoports/bundles/shell/headless/sshnpd.sh index 9c9e235bd..6d1df0720 100755 --- a/packages/sshnoports/bundles/shell/headless/sshnpd.sh +++ b/packages/sshnoports/bundles/shell/headless/sshnpd.sh @@ -2,6 +2,11 @@ # disable "var is referenced but not assigned" warning for template # shellcheck disable=SC2154 +# Uncomment the following lines to specify your own values, or modify them inline below +# device_atsign="@example_device" +# manager_atsign="@example_client" +# device_name="default" + sleep 10; # allow machine to bring up network export USER="$user" while true; do From f80e1efd77acff06d865995788de63daf1738abb Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 4 Jan 2024 16:35:43 +0800 Subject: [PATCH 3/6] chore: add var comments to sshrvd.sh --- packages/sshnoports/bundles/shell/headless/sshrvd.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/sshnoports/bundles/shell/headless/sshrvd.sh b/packages/sshnoports/bundles/shell/headless/sshrvd.sh index 7f02e288c..091c5eda3 100755 --- a/packages/sshnoports/bundles/shell/headless/sshrvd.sh +++ b/packages/sshnoports/bundles/shell/headless/sshrvd.sh @@ -2,6 +2,10 @@ # disable "var is referenced but not assigned" warning for template # shellcheck disable=SC2154 +# Uncomment the following lines to specify your own values, or modify them inline below +# atsign="@my_rvd" +# internet_address="127.0.0.1" + sleep 10; # allow machine to bring up network export USER="$user" while true; do From 610c957bf1a8889a7b62b91ed303676fe68184e4 Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 4 Jan 2024 16:36:08 +0800 Subject: [PATCH 4/6] chore: enable sshd as a requisite by default for sshnpd systemd service --- packages/sshnoports/bundles/shell/systemd/sshnpd.service | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/sshnoports/bundles/shell/systemd/sshnpd.service b/packages/sshnoports/bundles/shell/systemd/sshnpd.service index 167d10bb5..7fc0f965e 100644 --- a/packages/sshnoports/bundles/shell/systemd/sshnpd.service +++ b/packages/sshnoports/bundles/shell/systemd/sshnpd.service @@ -2,8 +2,8 @@ Description=Ssh No Ports Daemon After=network-online.target -# Uncomment the following line to make this unit fail if sshd isn't started -# Requisite=sshd.service +# Make this unit fail if sshd isn't started first +Requisite=sshd.service # Uncomment the following line to make this unit auto-start sshd if it isn't started # Requires=sshd.service @@ -13,7 +13,6 @@ User= Type=simple Restart=always RestartSec=3 -ExecStartPre=/bin/sleep 10 ExecStart=/usr/local/bin/sshnpd -a <@device_atsign> -m <@manager_atsign> -d -v [Install] From 3fc2ee731e5036929a8f7378d970d9ef8c9b933e Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 4 Jan 2024 16:36:32 +0800 Subject: [PATCH 5/6] fix: no need to sleep 10 with sshrvd systemd service --- packages/sshnoports/bundles/shell/systemd/sshrvd.service | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/sshnoports/bundles/shell/systemd/sshrvd.service b/packages/sshnoports/bundles/shell/systemd/sshrvd.service index d75231c21..04f9a019f 100644 --- a/packages/sshnoports/bundles/shell/systemd/sshrvd.service +++ b/packages/sshnoports/bundles/shell/systemd/sshrvd.service @@ -7,7 +7,6 @@ User= Type=simple Restart=always RestartSec=3 -ExecStartPre=/bin/sleep 10 ExecStart=/usr/local/bin/sshrvd -a <@atsign> -i [Install] From 0d304aeb8743a472ed5337903567e39bd24472fb Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 4 Jan 2024 16:40:03 +0800 Subject: [PATCH 6/6] chore: more tweaks --- packages/sshnoports/bundles/shell/systemd/sshnpd.service | 6 ++++++ packages/sshnoports/bundles/shell/systemd/sshrvd.service | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/sshnoports/bundles/shell/systemd/sshnpd.service b/packages/sshnoports/bundles/shell/systemd/sshnpd.service index 7fc0f965e..6a05c8085 100644 --- a/packages/sshnoports/bundles/shell/systemd/sshnpd.service +++ b/packages/sshnoports/bundles/shell/systemd/sshnpd.service @@ -9,10 +9,16 @@ Requisite=sshd.service # Requires=sshd.service [Service] +# TODO : set username User= Type=simple Restart=always RestartSec=3 + +# Uncomment the following line to sleep for 10 seconds before starting up the service +# ExecStartPre=/bin/sleep 10 + +# TODO : set device_atsign, manager_atsign, device_name ExecStart=/usr/local/bin/sshnpd -a <@device_atsign> -m <@manager_atsign> -d -v [Install] diff --git a/packages/sshnoports/bundles/shell/systemd/sshrvd.service b/packages/sshnoports/bundles/shell/systemd/sshrvd.service index 04f9a019f..45aea48d4 100644 --- a/packages/sshnoports/bundles/shell/systemd/sshrvd.service +++ b/packages/sshnoports/bundles/shell/systemd/sshrvd.service @@ -3,10 +3,16 @@ Description=Ssh No Ports Rendezvous Daemon After=network-online.target [Service] +# TODO : set username User= Type=simple Restart=always RestartSec=3 + +# Uncomment the following line to sleep for 10 seconds before starting up the service +# ExecStartPre=/bin/sleep 10 + +# TODO : set atsign, internet_address ExecStart=/usr/local/bin/sshrvd -a <@atsign> -i [Install]