From 958985df83823d363988c7f1bdc927d057acca31 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 22 Jul 2023 11:19:16 -0700 Subject: [PATCH 1/2] added remote shell detection --- functions.sh | 7 +++++++ is_remote.sh | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 is_remote.sh diff --git a/functions.sh b/functions.sh index 72ce02c..b8714ea 100644 --- a/functions.sh +++ b/functions.sh @@ -114,3 +114,10 @@ function rv() { printf ' RV=%d \e[0m\n' $RV >&2 } +function hexy() { + python3 -c 'import sys +for v in sys.argv[1:]: + print("{:02x}".format(int(v)), end="") +print("") +' $* +} diff --git a/is_remote.sh b/is_remote.sh new file mode 100644 index 0000000..5b0b8da --- /dev/null +++ b/is_remote.sh @@ -0,0 +1,21 @@ +# Detect if the current session is running on a remote server by listing parent +# processes of this shell and checking for things like sshd/tailscaled. Runs +# first because multiple other things rely on this. + + +function __is_remote() { + # names of daemon processes a remote shell might be a child process of + remote_daemons=( + sshd + ) + + is_remote=() + parent_procs="$(pstree -s $$)" + for d in ${remote_daemons[@]}; do + if [[ "$parent_procs" =~ "$d" ]]; then + return 1 + fi + done + + return 0 +} From 26b26706023f9b209328ba2203c283b73011e224 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 22 Jul 2023 11:27:54 -0700 Subject: [PATCH 2/2] added a flatg to auto-reload the newly compiled script --- 0-builder | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/0-builder b/0-builder index 78e9974..8aa183b 100644 --- a/0-builder +++ b/0-builder @@ -69,7 +69,11 @@ echo "##################" >> $COMPILED_SRC echo "# Reloader Script" >> $COMPILED_SRC echo """################## function __rebuild_bashrcd() { - bash """$SELF_SRC""" + bash \""""$SELF_SRC"""\" + if [[ \$? -eq 0 && \"\${1}\" == '-a' ]]; then + echo "Automatically loading compiled script." + source \""""$(readlink -f "$COMPILED_SRC")"""\" + fi } """ >> $COMPILED_SRC