#!/bin/bash restoreDir="/etc/restore" hook_before() { mkdir -p "$restoreDir" || exit 1 pushd "$restoreDir" || exit 2 rpm -qa | sort > Package.versions.list rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort > Package.all.list zypper se -i -t pattern | awk '/^i\+/ { print $3 }' | sort > Pattern.list zypper se -i -t package | 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 } hook_after() { : } hook_fail() { : } hook_final() { : } case "$1" in before) hook_before || exit $?;; after) hook_after || exit $?;; fail) hook_fail || exit $?;; finally) hook_final || exit $?;; esac