Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable root + macos install #1571

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 79 additions & 75 deletions packages/dart/sshnoports/bundles/shell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ is_root() {
[ "$(id -u)" -eq 0 ]
}

is_darwin() {
[ "$(uname)" = 'Darwin' ]
}

unset binary_dir
user_home=$HOME
define_env() {
script_dir="$(dirname -- "$(readlink -f -- "$0")")"
bin_dir="/usr/local/bin"
systemd_dir="/etc/systemd/system"
if is_root; then
if is_darwin; then
echo "Installing as root is not available on MacOS"
exit 1
fi
user="$SUDO_USER"
if [ -z "$user" ]; then
user="root"
Expand All @@ -30,10 +38,6 @@ define_env() {
user_ssh_dir="$user_home/.ssh"
}

is_darwin() {
[ "$(uname)" = 'Darwin' ]
}

sedi() {
if is_darwin; then
sed -i '' "$@"
Expand Down Expand Up @@ -237,17 +241,17 @@ systemd() {
exit 1
fi
case "$1" in
--help)
usage
exit 0
;;
sshnpd) install_systemd_sshnpd ;;
srvd) install_systemd_srvd ;;
*)
echo "Unknown systemd unit: $1"
usage
exit 1
;;
--help)
usage
exit 0
;;
sshnpd) install_systemd_sshnpd ;;
srvd) install_systemd_srvd ;;
*)
echo "Unknown systemd unit: $1"
usage
exit 1
;;
esac
setup_authorized_keys
}
Expand Down Expand Up @@ -281,16 +285,16 @@ launchd() {
exit 1
fi
case "$1" in
--help)
usage
exit 0
;;
sshnpd) install_launchd_sshnpd ;;
*)
echo "Unknown launchd unit: $1"
usage
exit 1
;;
--help)
usage
exit 0
;;
sshnpd) install_launchd_sshnpd ;;
*)
echo "Unknown launchd unit: $1"
usage
exit 1
;;
esac
setup_authorized_keys
}
Expand Down Expand Up @@ -361,17 +365,17 @@ install_headless_srvd() {

headless() {
case "$1" in
--help | '')
usage
exit 0
;;
sshnpd) install_headless_sshnpd ;;
srvd) install_headless_srvd ;;
*)
echo "Error: Unknown headless job: $1"
usage
exit 1
;;
--help | '')
usage
exit 0
;;
sshnpd) install_headless_sshnpd ;;
srvd) install_headless_srvd ;;
*)
echo "Error: Unknown headless job: $1"
usage
exit 1
;;
esac
setup_authorized_keys
}
Expand Down Expand Up @@ -442,17 +446,17 @@ install_tmux_srvd() {

tmux() {
case "$1" in
--help | '')
usage
exit 0
;;
sshnpd) install_tmux_sshnpd ;;
srvd) install_tmux_srvd ;;
*)
echo "Unknown tmux service: $1"
usage
exit 1
;;
--help | '')
usage
exit 0
;;
sshnpd) install_tmux_sshnpd ;;
srvd) install_tmux_srvd ;;
*)
echo "Unknown tmux service: $1"
usage
exit 1
;;
esac
setup_authorized_keys
}
Expand All @@ -466,34 +470,34 @@ main() {

while [ $# -gt 0 ]; do
case "$1" in
-h)
usage
exit 0
;;
-b)
binary_dir="$2"
shift
;;
-u)
user="$2"
user_home=$(sudo -u "$user" sh -c 'echo $HOME')
shift
;;
at_activate | npt | sshnp | sshnpd | srv | srvd) install_single_binary "$1" ;;
binaries) install_base_binaries ;;
debug_srvd) install_debug_binary "${1#"debug_"}" ;; # strips debug_ prefix from the command input
debug) install_debug_binaries ;;
all) install_all_binaries ;;
systemd | launchd | headless | tmux)
command=$1
shift 1
$command "$@"
;;
*)
echo "Unknown command: $1"
usage
exit 1
;;
-h)
usage
exit 0
;;
-b)
binary_dir="$2"
shift
;;
-u)
user="$2"
user_home=$(sudo -u "$user" sh -c 'echo $HOME')
shift
;;
at_activate | npt | sshnp | sshnpd | srv | srvd) install_single_binary "$1" ;;
binaries) install_base_binaries ;;
debug_srvd) install_debug_binary "${1#"debug_"}" ;; # strips debug_ prefix from the command input
debug) install_debug_binaries ;;
all) install_all_binaries ;;
systemd | launchd | headless | tmux)
command=$1
shift 1
$command "$@"
;;
*)
echo "Unknown command: $1"
usage
exit 1
;;
esac
shift
done
Expand Down