From 8248b008c247a91fe077558c9182baee33a045bc Mon Sep 17 00:00:00 2001 From: mesaprotector Date: Sun, 15 Dec 2024 21:58:54 -0800 Subject: [PATCH] Fixed permissions issues with new head and tail files. --- addcomment | 36 ++++++++++++++++++++++++++++++++++++ waitcomment.sh | 1 + 2 files changed, 37 insertions(+) diff --git a/addcomment b/addcomment index 7d7da37..57a4c53 100644 --- a/addcomment +++ b/addcomment @@ -33,3 +33,39 @@ else echo "OK" > "$tmpdir"/"$tty" echo "Comment added" fi +#!/bin/bash +if [ "`ps ax | awk '$5 ~ /\/bin\/bash/' | awk '$6 ~ \ +/\/lib\/waitcomment.sh/' | wc -l`" = "0" ]; then + echo "No waitcomment process" + exit +fi +. /etc/sudo-comment.conf +tty="`tty | cut -d '/' -f 3-`" +mytmpdir="`cat "$tmpdir/$tty"`" +echo "Comment on an edit? [y/yp/N] " +read -r comment +if [ "$comment" = "N" ]; then + echo "N/A" > "$tmpdir"/"$tty" + echo "No comment added" +elif [ "$comment" = "yp" ]; then + echo -e "=POSTDATED=" >> "$mytmpdir"/comment.tmp + lines="`cat "$mytmpdir"/comment.tmp | wc -l`" + sed '1s/^/@@ /' "$mytmpdir"/comment.tmp > "$mytmpdir"/head.tmp + eval "$editor" "$mytmpdir"/comment.tmp + tail -n +$((lines+1)) "$mytmpdir"/comment.tmp \ + | fold -s | sed 's/^/# /' > "$mytmpdir"/tail.tmp + cat "$mytmpdir"/head.tmp "$mytmpdir"/tail.tmp > "$mytmpdir"/comment.tmp + rm "$mytmpdir"/head.tmp "$mytmpdir"/tail.tmp + echo "OK" > "$tmpdir"/"$tty" + echo "Comment added" +else + lines="`cat "$mytmpdir"/comment.tmp | wc -l`" + sed '1s/^/@@ /' "$mytmpdir"/comment.tmp > "$mytmpdir"/head.tmp + eval "$editor" "$mytmpdir"/comment.tmp + tail -n +$((lines+1)) "$mytmpdir"/comment.tmp \ + | fold -s | sed 's/^/# /' > "$mytmpdir"/tail.tmp + cat "$mytmpdir"/head.tmp "$mytmpdir"/tail.tmp > "$mytmpdir"/comment.tmp + rm "$mytmpdir"/head.tmp "$mytmpdir"/tail.tmp + echo "OK" > "$tmpdir"/"$tty" + echo "Comment added" +fi diff --git a/waitcomment.sh b/waitcomment.sh index a4f5cba..1776a23 100644 --- a/waitcomment.sh +++ b/waitcomment.sh @@ -83,6 +83,7 @@ if grep -qE "$p_track|>" <<< "$curr_command"; then # addcomment normally runs unprivileged so these files need to be # world-writable. + chmod 777 "$mytmpdir" chmod 666 "$mytmpdir"/comment.tmp chmod 666 "$tmpdir/$curr_shell"