From ae769186d1e0535e328c5d9a0a7beeccd95c6e52 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Mon, 13 May 2024 19:58:54 -0400 Subject: [PATCH] Updated suse/opensuse restore agent. --- scripts/os_suse | 114 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 2 deletions(-) diff --git a/scripts/os_suse b/scripts/os_suse index b11bef8..6116fd2 100755 --- a/scripts/os_suse +++ b/scripts/os_suse @@ -7,7 +7,10 @@ hook_before() { pushd "$restoreDir" || exit 2 rpm -qa | sort > Package.versions.list - rpm -qa --queryformat '%{NAME}\n' | sort > Package.list + rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort > Package.all.list + zypper se -i | awk '/^i\+/ { print $3 }' | sort > Package.list + zypper lr -e Backup.repos + zypper ll | awk '/.*\| package.*/ { print $3 }' > Package.lock cat > restore.sh < /tmp/Package.new.list + echo "Here's a list of packages that would be removed:" + comm -13 Package.all.list /tmp/Package.new.list + + read -p "Do you want to omit any removals or cancel? [N, y, c] " -n 1 -sr promptRmVerify + if [[ "\$promptRmVerify" =~ ^[Yy]$ ]]; then + echo + read -p "What do you want to omit, seperated by spaces? " -r promptOmit + omitrm="\$(echo "\$promptOmit" | tr ' ' '|')" + echo + elif [[ "\$promptRmVerify" =~ ^[Cc]$ ]]; then + echo -e "\nCancelling" + omitrm="CANCEL" + else + omitrm="" + echo + fi + + if [[ "\$omitrm" != "CANCEL" ]]; then + comm -13 Package.all.list /tmp/Package.new.list | egrep -v "(\$omitrm)" | xargs zypper remove + fi +else + echo -e "Cancelled\n" +fi + +# Package Locks +if [[ -r "Package.lock" && "$(wc -l --total=only Package.list)" -gt 0 ]]; then + echo + echo "==============================" + echo "PACKAGE LOCKS" + echo "==============================" + echo + echo "The following packages are found to be locked:" + cat Package.lock + echo + read -p "Do you want to lock these packages per the backup? [Y/n] " -n 1 -sr promptLock + if [[ "\$promptLock" =~ ^[Yy]$ ]]; then + echo "Yes" + cat Package.lock | xargs zypper addlock + else + echo -e "Cancelled\n" + fi +fi EOF popd || exit 2