fix non-existent file case

This commit is contained in:
Joel Beckmeyer 2021-01-31 14:38:31 -05:00
parent cf5f037f49
commit 69fc00861e

View File

@ -9,13 +9,18 @@ done
mkdir -p /tmp/doasedit/$destfile_pfx
srcfile="$(realpath $1)"
doas cp $srcfile /tmp/doasedit/$destfile_pfx/edit
doas chown -R $USER:$USER /tmp/doasedit/$destfile_pfx/edit
doas cp $srcfile /tmp/doasedit/$destfile_pfx/file
if [ -f "$srcfile" ]; then
doas cp $srcfile /tmp/doasedit/$destfile_pfx/edit
doas chown -R $USER:$USER /tmp/doasedit/$destfile_pfx/edit
doas cp $srcfile /tmp/doasedit/$destfile_pfx/file
else
# create file with "regular" system permissions (root:root 644)
touch /tmp/doasedit/$destfile_pfx/file
doas chown root:root /tmp/doasedit/$destfile_pfx/file
fi
$EDITOR /tmp/doasedit/$destfile_pfx/edit
cat /tmp/doasedit/$destfile_pfx/edit | doas tee /tmp/doasedit/$destfile_pfx/file 1>/dev/null
if cmp -s "/tmp/doasedit/$destfile_pfx/file" "$srcfile"; then