sudo destore
This commit is contained in:
@ -1,19 +1,31 @@
|
|||||||
destore() {
|
destore() {
|
||||||
for dst in "$@"; do
|
for dst in "$@"; do
|
||||||
|
local MAYBESUDO=""
|
||||||
|
if test ! -w "$(realpath --no-symlinks $dst)" \
|
||||||
|
|| test ! -w "$(basename "$(realpath --no-symlinks $dst)")"; then
|
||||||
|
MAYBESUDO="sudo"
|
||||||
|
sudo true || {
|
||||||
|
>&2 echo "ERROR: could not destore '$dst' due to lack of sudo"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
test -L "$dst" || continue
|
test -L "$dst" || continue
|
||||||
# TODO: assert dst is in the store
|
# TODO: assert dst is in the store
|
||||||
src="$(realpath "$dst")"
|
src="$(realpath "$dst")"
|
||||||
if test -d "$src"; then
|
if test -d "$src"; then
|
||||||
(set -x
|
(set -x
|
||||||
rm -v "$dst"
|
$MAYBESUDO rm -v "$dst"
|
||||||
cp -r --dereference --one-file-system "$src/" "$dst/"
|
$MAYBESUDO cp -r --dereference --one-file-system "$src/" "$dst/"
|
||||||
chmod -R +rw "$dst"
|
$MAYBESUDO chmod -R +rw "$dst"
|
||||||
|
$MAYBESUDO chown "$UID" -R "$dst"
|
||||||
)
|
)
|
||||||
elif test -f "$src"; then
|
elif test -f "$src"; then
|
||||||
(set -x
|
(set -x
|
||||||
rm -v "$dst"
|
$MAYBESUDO rm -v "$dst"
|
||||||
cp -v "$src" "$dst"
|
$MAYBESUDO cp -v "$src" "$dst"
|
||||||
chmod -v +rw "$dst"
|
$MAYBESUDO chmod -v +rw "$dst"
|
||||||
|
$MAYBESUDO chown -v "$UID" -v "$dst"
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user