Skip to content

Commit

Permalink
Merge branch 'trunk' into npt_desktop-onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtlyCritchlow authored Nov 26, 2024
2 parents 1b7774d + 13b4f53 commit 48b90cf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 95 deletions.
36 changes: 16 additions & 20 deletions packages/c/sshnpd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#define FILENAME_BUFFER_SIZE 500
Expand Down Expand Up @@ -77,32 +78,27 @@ static bool is_child_process = false;

// Signal handling
static volatile sig_atomic_t should_run = 1;
// static void exit_handler(int sig) {
// atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n");
// if (should_run == 1) {
// atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received SIGINT, attempting a safe exit\n");
// should_run = 0;
// } else if (should_run == 0) {
// atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received SIGINT again, exiting forcefully\n");
// exit(1);
// }
// }
// static void child_exit_handler(int sig) {
// atlogger_log("child_exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n");
// int status;
// pid_t pid = waitpid(-1, &status, WNOHANG);
// if (pid > 0 && WIFEXITED(status)) {
// atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "pid %d exited\n", pid);
// }
// }
static void exit_handler(int sig) {
atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n", sig);
should_run = 0;
exit(1);
}
static void child_exit_handler(int sig) {
atlogger_log("child_exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n", sig);
int status;
pid_t pid = waitpid(-1, &status, WNOHANG);
if (pid > 0 && WIFEXITED(status)) {
atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "pid %d exited\n", pid);
}
}

int main(int argc, char **argv) {
int res = 0;
int exit_res = 0;

// Catch sigint and pass to the handler
// signal(SIGINT, exit_handler);
// signal(SIGCHLD, child_exit_handler);
signal(SIGINT, exit_handler);
signal(SIGCHLD, child_exit_handler);

// 1. Load default values
apply_default_values_to_sshnpd_params(&params);
Expand Down
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

0 comments on commit 48b90cf

Please sign in to comment.