From a140c2d0cc4a899278c5f087462673ffc50a0fa8 Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Fri, 19 Jul 2024 15:10:15 +0200 Subject: [PATCH] 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 --- recipes-core/base-files/base-files/user-backup.txt | 2 +- scripts/installer/lib/backup.sh | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/recipes-core/base-files/base-files/user-backup.txt b/recipes-core/base-files/base-files/user-backup.txt index 2f0790cd..aaaf03c0 100644 --- a/recipes-core/base-files/base-files/user-backup.txt +++ b/recipes-core/base-files/base-files/user-backup.txt @@ -5,6 +5,7 @@ # # - 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" @@ -12,7 +13,6 @@ # - 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. diff --git a/scripts/installer/lib/backup.sh b/scripts/installer/lib/backup.sh index 89e50117..cb059a16 100644 --- a/scripts/installer/lib/backup.sh +++ b/scripts/installer/lib/backup.sh @@ -98,6 +98,8 @@ 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 "#"*) @@ -105,16 +107,22 @@ parse_file() { ;; "-"*) 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