From 41f01f9ed6707f770f49eca8e25e0734d3252b90 Mon Sep 17 00:00:00 2001 From: mesaprotector Date: Sun, 22 Dec 2024 21:45:46 -0800 Subject: [PATCH] Comment improvements --- waitcomment.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/waitcomment.sh b/waitcomment.sh index c800d4e..817e409 100755 --- a/waitcomment.sh +++ b/waitcomment.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Check if running as root; if not, exit. if [ "`/bin/id -u`" != "0" ]; then echo "Not running as root" exit @@ -22,7 +23,7 @@ if [ -z "$mytmpdir" ]; then exit fi -# Grabs the last ten lines of the sudo logfile (my location) to tmpfile. +# Grabs the last ten lines of the sudo logfile to tmpfile. tail -n10 "$sudolog" > "$mytmpdir"/comment_pre.tmp tac "$mytmpdir"/comment_pre.tmp | awk '!flag; /TTY/{flag = 1};' \ | tac > "$mytmpdir"/comment.tmp @@ -65,7 +66,7 @@ curr_shell="`head -n1 "$mytmpdir"/comment.tmp | cut -d ';' -f 1-1 \ | grep -o TTY.* | cut -c 5- | tr -d ' '`" # Creates a named pipe to communicate with addcomment process. -if [ -f "$tmpdir/$curr_shell" ]; then +if [ -p "$tmpdir/$curr_shell" ]; then cat "$tmpdir/$curr_shell" echo "EXIT" > "$tmpdir/$curr_shell" else @@ -110,8 +111,9 @@ if grep -qE "$p_track|>" <<< "$curr_command"; then touch "$mytmpdir"/tail.tmp # addcomment normally runs unprivileged so these files need to - # be world-writable. TODO: assign ownership to run_by_user or - # run_as_user according to shell process. + # be world-writable. For this grave shell scripting sin we pray + # to great lord Satan. TODO: explore assigning ownership with + # run_by_user or run_as_user. Not convinced it's an improvement. chmod 666 "$mytmpdir"/comment.tmp chmod 666 "$tmpdir/$curr_shell"