Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer: add globbing for backup configuration #229

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
installer: add globbing for backup configuration
Globbing can be quite useful when selecting the paths to preserve across
operating system updates. So far, the backup/restore mechanism did not
support wildcards. This change enables globbing as supported by the
busybox /bin/sh.

Note that the code is intentionally kept simple; among other things,
busybox sh does not support pushd and arrays.

Signed-off-by: Roger Luethi <[email protected]>
ideaship committed Jan 9, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 729f5ac1c99ec8631257677a3b1ff138d0a762bd
2 changes: 1 addition & 1 deletion recipes-core/base-files/base-files/user-backup.txt
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@
#
# - absolute paths to files or directories to keep:
# e.g. "/etc/default/user-backup.txt"
# or, using wildcards: "/home/*/.ssh/"
#
# - prefixed paths with a "-" for configuration files to NOT keep:
# e.g. "-/etc/hostname"
#
# - comments, like this block, prefixed with #.
#
# Limitations:
# - You cannot use wildcards.
# - Symlinks are not supported and will be ignored.
# - Do NOT keep ("-") has higher priority than keep. When both are
# present, the file will not be kept, regardless of the order.
12 changes: 10 additions & 2 deletions scripts/installer/lib/backup.sh
Original file line number Diff line number Diff line change
@@ -98,23 +98,31 @@ parse_file() {
return 0
fi

# Switch to src directory to make globbing (wildcard expansion) work
cd "$3" || exit 1
while read -r line; do
case "$line" in
"#"*)
# comment
;;
"-"*)
if [ "$2" = "-" ]; then
remove_from_backup "${line:1}" $3 $4
# Globbing after removing the leading '-'
for fpath in ./${line:1}; do
remove_from_backup "${fpath}" $3 $4
done
fi
;;
/*)
if [ "$2" = "+" ]; then
add_to_backup "$line" $3 $4
for fpath in ./${line}; do
add_to_backup "$fpath" $3 $4
done
fi
;;
esac
done < $1
cd -
}

# $1 src $2 dst