move paths to variables
This commit is contained in:
parent
e757865715
commit
3ec27a66b4
24
doasedit
24
doasedit
@ -18,27 +18,29 @@ while [ -d "/tmp/doasedit/$destfile_pfx" ]; do
|
|||||||
destfile_pfx="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)"
|
destfile_pfx="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)"
|
||||||
done
|
done
|
||||||
|
|
||||||
mkdir -p /tmp/doasedit/$destfile_pfx
|
tempdir="/tmp/doasedit/$destfile_pfx"
|
||||||
|
|
||||||
|
mkdir -p $tempdir
|
||||||
srcfile="$(doas realpath $1)"
|
srcfile="$(doas realpath $1)"
|
||||||
|
|
||||||
if doas [ -f "$srcfile" ]; then
|
if doas [ -f "$srcfile" ]; then
|
||||||
doas cp $srcfile /tmp/doasedit/$destfile_pfx/edit
|
doas cp $srcfile $tempdir/edit
|
||||||
doas chown -R $USER:$USER /tmp/doasedit/$destfile_pfx/edit
|
doas chown -R $USER:$USER $tempdir/edit
|
||||||
doas cp $srcfile /tmp/doasedit/$destfile_pfx/file
|
doas cp $srcfile $tempdir/file
|
||||||
else
|
else
|
||||||
# create file with "regular" system permissions (root:root 644)
|
# create file with "regular" system permissions (root:root 644)
|
||||||
touch /tmp/doasedit/$destfile_pfx/file
|
touch $tempdir/file
|
||||||
doas chown root:root /tmp/doasedit/$destfile_pfx/file
|
doas chown root:root $tempdir/file
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$EDITOR /tmp/doasedit/$destfile_pfx/edit
|
$EDITOR $tempdir/edit
|
||||||
|
|
||||||
cat /tmp/doasedit/$destfile_pfx/edit | doas tee /tmp/doasedit/$destfile_pfx/file 1>/dev/null
|
cat $tempdir/edit | doas tee $tempdir/file 1>/dev/null
|
||||||
|
|
||||||
if cmp -s "/tmp/doasedit/$destfile_pfx/file" "$srcfile"; then
|
if cmp -s "$tempdir/file" "$srcfile"; then
|
||||||
echo "Skipping write; no changes."
|
echo "Skipping write; no changes."
|
||||||
else
|
else
|
||||||
doas mv -f /tmp/doasedit/$destfile_pfx/file $srcfile
|
doas mv -f $tempdir/file $srcfile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf /tmp/doasedit/$destfile_pfx
|
rm -rf $tempdir
|
||||||
|
Loading…
Reference in New Issue
Block a user