sudo destore
This commit is contained in:
@ -1,19 +1,31 @@
|
||||
destore() {
|
||||
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
|
||||
# TODO: assert dst is in the store
|
||||
src="$(realpath "$dst")"
|
||||
if test -d "$src"; then
|
||||
(set -x
|
||||
rm -v "$dst"
|
||||
cp -r --dereference --one-file-system "$src/" "$dst/"
|
||||
chmod -R +rw "$dst"
|
||||
$MAYBESUDO rm -v "$dst"
|
||||
$MAYBESUDO cp -r --dereference --one-file-system "$src/" "$dst/"
|
||||
$MAYBESUDO chmod -R +rw "$dst"
|
||||
$MAYBESUDO chown "$UID" -R "$dst"
|
||||
)
|
||||
elif test -f "$src"; then
|
||||
(set -x
|
||||
rm -v "$dst"
|
||||
cp -v "$src" "$dst"
|
||||
chmod -v +rw "$dst"
|
||||
$MAYBESUDO rm -v "$dst"
|
||||
$MAYBESUDO cp -v "$src" "$dst"
|
||||
$MAYBESUDO chmod -v +rw "$dst"
|
||||
$MAYBESUDO chown -v "$UID" -v "$dst"
|
||||
)
|
||||
fi
|
||||
done
|
||||
|
Reference in New Issue
Block a user