joininbox/scripts/set.conf.sh

45 lines
857 B
Bash
Raw Permalink Normal View History

#!/bin/bash
2021-03-21 00:31:58 +00:00
EDITFILE="$1"
USER="$2"
if [ ${#USER} -eq 0 ];then
USER=joinmarket
fi
if [ ${#EDITFILE} -eq 0 ]; then
echo "# Please specify a file to edit"
else
2021-03-21 00:31:58 +00:00
echo "Opening $EDITFILE"
fi
# temp conf
trap 'rm -f "$conf"' EXIT
conf=$(mktemp -p /dev/shm/)
dialog \
2021-03-21 00:31:58 +00:00
--title "Editing the $EDITFILE" \
--editbox "$EDITFILE" 200 200 2> "$conf"
# make decision
pressed=$?
case $pressed in
0)
2020-06-16 15:27:15 +01:00
dialog --title "Finished editing" \
--msgbox "
Saving to:
2021-03-21 00:31:58 +00:00
$EDITFILE" 7 56
sudo -u $USER tee "$EDITFILE" 1>/dev/null < "$conf"
shred "$conf"
exit 0;;
1)
shred "$conf"
2021-03-21 00:31:58 +00:00
DIALOGRC=/home/joinmarket/.dialogrc.onerror dialog --title "Finished editing" \
2020-06-16 15:27:15 +01:00
--msgbox "
Cancelled editing:
2021-03-21 00:31:58 +00:00
$EDITFILE" 7 56
echo "# Cancelled"
exit 1;;
255)
shred "$conf"
[ -s "$conf" ] && cat "$conf" || echo "ESC pressed."
2021-03-21 00:31:58 +00:00
exit 1;;
esac