aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-06 10:38:33 +0200
committerDanilo M. <danix@danix.xyz>2026-05-06 10:38:33 +0200
commit75e82034a7d26d16587c31a3fc3ae0ddd6210071 (patch)
treef649ce6ded4c88f3b89ac27e877eb265ec2d50e1
parent620a2f461943adc3f8df4010f32a53742f09a741 (diff)
downloaddots-backup-75e82034a7d26d16587c31a3fc3ae0ddd6210071.tar.gz
dots-backup-75e82034a7d26d16587c31a3fc3ae0ddd6210071.zip
feat: skip system files on restore when not root
Warn and skip system/ entries during restore if EUID != 0. Dry-run shows what would be restored (with "needs root" note) so user can decide whether to re-run as root.
-rwxr-xr-xdot-backup.sh22
1 files changed, 21 insertions, 1 deletions
diff --git a/dot-backup.sh b/dot-backup.sh
index 5130012..0e22d70 100755
--- a/dot-backup.sh
+++ b/dot-backup.sh
@@ -214,11 +214,27 @@ do_restore() {
echo -e "${YELLOW}Restoring dotfiles from: ${BLUE}$DEFAULT_OUTPUT_DIR${NC}\n"
+ local system_skipped=0
+
for i in "${DOTFILES[@]}"; do
if beginswith "/" "$i"; then
- # system file
+ # system file — requires root
local backup_path="${DEFAULT_OUTPUT_DIR}/system/${i#/}"
local dest="$i"
+ if [[ "$EUID" -ne 0 ]]; then
+ if [[ -e "$backup_path" ]]; then
+ if [[ "$DRY_RUN" == true ]]; then
+ echo -e "${YELLOW}$dest${NC}"
+ echo -e "\t ${YELLOW}[dry-run] would restore: $backup_path → $dest (needs root)${NC}"
+ else
+ echo -e "${YELLOW}SKIP (needs root): $dest${NC}"
+ (( system_skipped++ )) || true
+ fi
+ else
+ log_verbose "\t ${YELLOW}SKIP (not in backup): $i${NC}"
+ fi
+ continue
+ fi
else
local backup_path="${DEFAULT_OUTPUT_DIR}/home/$i"
local dest="${HOME}/$i"
@@ -253,6 +269,10 @@ do_restore() {
fi
done
+ if [[ "$system_skipped" -gt 0 ]]; then
+ echo -e "\n${YELLOW}Warning: $system_skipped system file(s) skipped — re-run as root to restore them.${NC}"
+ fi
+
if [[ "$DRY_RUN" == true ]]; then
echo -e "\n${YELLOW}Dry run complete. Nothing restored.${NC}"
else