aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/help-me.bash30
1 files changed, 21 insertions, 9 deletions
diff --git a/scripts/help-me.bash b/scripts/help-me.bash
index 0d8a84b..1dd65ed 100755
--- a/scripts/help-me.bash
+++ b/scripts/help-me.bash
@@ -128,7 +128,7 @@ EOF
cat <<EOF
new-session -s help
rename-window user
-new-window -dn root tmux -S /run/help-root attach
+new-window -dn root tmux -S "$tmpdir/help-root" attach
EOF
else
cat <<EOF
@@ -141,9 +141,10 @@ EOF
exit_cleanup()
{
set +e # avoid getting error stopping the script to do all cleanup
- tmux -L help kill-server 2>/dev/null
- tmux -S /run/help-root kill-server 2>/dev/null
- rm -f /run/help-root
+ tmux -L help kill-server 2>/dev/null
+ if [ -z "$tmpdir" ]; then return; fi
+ tmux -S "$tmpdir/help-root" kill-server 2>/dev/null
+ rm -rf -- "$tmpdir"
}
run_tmux()
@@ -151,12 +152,13 @@ run_tmux()
( # subshell for chdir, easier when openning new tmux panes
cd ~ || true # not mandatory, just easier within tmux
if ! tmux -L help has-session -t help 2>/dev/null; then
- local tmpfile="$(sudo mktemp)"
+ local tmpfile="$tmpdir/help-root.tmux.conf"
+ sudo -v
generate_tmux_conf 0 | sudo tee "$tmpfile" >/dev/null
- sudo -i tmux -S /run/help-root -f "$tmpfile" start
+ sudo -i tmux -S "$tmpdir/help-root" -f "$tmpfile" start
sudo rm -f -- "$tmpfile"
- sudo chown $USER /run/help-root
- # mktemp is not necessary when not using sudo
+ sudo chown $USER "$tmpdir/help-root"
+ # tmpfile is not necessary when not using sudo
tmux -L help -f <(generate_tmux_conf 1) start
fi
)
@@ -327,8 +329,15 @@ make_connection_to_local_ssh_server()
main()
{
- exec > >(tee /tmp/help.log) 2>&1
+ # log
+ local logfile="$(mktemp --tmpdir --suffix=.log help.XXXXXXXXXX)"
+ exec > >(tee "$logfile") 2>&1
+ echo_notice "logfile: $logfile"
+
+ # global var tmpdir
+ tmpdir="$(mktemp -d)"
trap exit_cleanup EXIT INT
+
ensure_script_requirement
get_user_consent
ensure_required_packages_are_installed
@@ -338,6 +347,9 @@ main()
ensure_tmux_is_running
open_xterm_with_tmux_inside
make_connection_to_local_ssh_server
+
+ # if all was ok, remove the log file, logfile not in trap
+ rm -f -- "$logfile"
}
# run all the stuff