Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
installer: add globbing for backup configuration
Browse files Browse the repository at this point in the history
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 Nov 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent afa2d90 commit a140c2d
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit a140c2d

Please sign in to comment.