add argument checking; fix case where user doesn't have read access to directory
This commit is contained in:
parent
69fc00861e
commit
00716fdadf
17
doasedit
17
doasedit
@ -1,15 +1,24 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
if [ ! -z "${2}" ]; then
|
||||||
|
echo "Expected only one argument"
|
||||||
|
exit 1
|
||||||
|
elif [ -z "${1}" ]; then
|
||||||
|
echo "No file path provided"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
destfile_pfx="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)"
|
set -euo pipefail
|
||||||
|
|
||||||
|
destfile_pfx="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)" || true
|
||||||
|
|
||||||
while [ -d "/tmp/doasedit/$destfile_pfx" ]; do
|
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
|
mkdir -p /tmp/doasedit/$destfile_pfx
|
||||||
srcfile="$(realpath $1)"
|
srcfile="$(doas realpath $1)"
|
||||||
|
|
||||||
if [ -f "$srcfile" ]; then
|
if doas [ -f "$srcfile" ]; then
|
||||||
doas cp $srcfile /tmp/doasedit/$destfile_pfx/edit
|
doas cp $srcfile /tmp/doasedit/$destfile_pfx/edit
|
||||||
doas chown -R $USER:$USER /tmp/doasedit/$destfile_pfx/edit
|
doas chown -R $USER:$USER /tmp/doasedit/$destfile_pfx/edit
|
||||||
doas cp $srcfile /tmp/doasedit/$destfile_pfx/file
|
doas cp $srcfile /tmp/doasedit/$destfile_pfx/file
|
||||||
|
Loading…
Reference in New Issue
Block a user