Skip to content

Commit

Permalink
Compatibility improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mesaprotector committed Dec 23, 2024
1 parent 8004d8c commit 1b6ee24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions addcomment
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
if [ "`pgrep -fax '/bin/bash /lib/waitcomment.sh' | wc -l`" = 0 ]; then
#!/usr/bin/env bash
source /etc/sudo-comment.conf
tty="`tty | cut -d '/' -f 3-`"
if [ ! -p "$tmpdir/$tty" ]; then
echo "No waitcomment process"
exit
fi
source /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
Expand Down
9 changes: 4 additions & 5 deletions waitcomment.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash
#!/usr/bin/env bash
if [ "`/bin/id -u`" != "0" ]; then
echo "Not running as root"
exit
fi

# Sets working directories and sources config. Exits if mytmpdir is unset.
tmpdir="/tmp/sudo-comment"
source /etc/sudo-comment.conf
_tmpdir="`echo "$tmpdir" | sed -s 's/\/$//g'`"
tmpdir="$_tmpdir"
tmpdir="${_tmpdir:-/tmp/sudo-comment}"
mkdir "$tmpdir" 2>/dev/null
mkdir "$tmpdir"/pts 2>/dev/null
for ((i=0;i<100;i++)); do
Expand Down Expand Up @@ -123,11 +122,11 @@ if grep -qE "$p_track|>" <<< "$curr_command"; then
echo "$mytmpdir" > "$tmpdir/$curr_shell"
output="`cat "$tmpdir/$curr_shell"`"

# Appends tmpfile to the comment log IF return traffic says to.
# Formats and appends to commentlog IF return traffic says to.
if [ "$output" = "OK" ]; then
tail -n +$((lines+1)) "$mytmpdir"/comment.tmp \
| fold -s > "$mytmpdir"/tail.tmp
sed -i 's/^/# /2g' "$mytmpdir"/tail.tmp
sed -i '2,$s/^/# /' "$mytmpdir"/tail.tmp
cat "$mytmpdir"/head.tmp "$mytmpdir"/tail.tmp > \
"$mytmpdir"/comment.tmp
cat "$mytmpdir"/comment.tmp >> "$commentlog"
Expand Down

0 comments on commit 1b6ee24

Please # to comment.