aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvg <vg@devys.org>2019-01-22 14:27:31 +0100
committervg <vg@devys.org>2019-01-22 14:27:31 +0100
commit5b1dd513482a7cead867628f130b7d559c535ad6 (patch)
tree7fda1a39a4ece4bf0660dbc818021f54aa6d2c9f
parent49bb0e1fabe13d68bea89b29f51f8f316e0b6cdf (diff)
downloadscripts-5b1dd513482a7cead867628f130b7d559c535ad6.tar.gz
scripts-5b1dd513482a7cead867628f130b7d559c535ad6.tar.bz2
scripts-5b1dd513482a7cead867628f130b7d559c535ad6.zip
update help-me.bash from piou's advice
-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