Updated suse/opensuse restore agent.

This commit is contained in:
Eric Renfro 2024-05-13 19:58:54 -04:00
parent 9e0535e353
commit ae769186d1
Signed by: psi-jack
SSH key fingerprint: SHA256:1TKB8Z257L8EHK8GWNxKgMhD8a+FAR+f+j3nnlcuNVM

View file

@ -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 <<EOF
#!/bin/bash
@ -17,7 +20,114 @@ if [[ ! -f "Package.list" ]]; then
exit 1
fi
cat Package.list | xargs zypper install
if [[ -r "Backup.repos" ]]; then
echo
echo "=============================="
echo "INSTALL REPOS"
echo "=============================="
echo
read -p "Do you want to continue to install backup repositories? [Y/n] " -n 1 -sr promptRepos
if [[ "\$promptRepos" =~ ^[Yy]$ ]]; then
echo "Yes"
zypper ar Backup.repos
zypper --gpg-auto-import-keys refresh
else
echo -e "Cancelled\n"
fi
fi
if [[ -r "opi.conf" ]]; then
source "opi.conf"
if [[ -n "\$opimodules" ]]; then
echo
echo "=============================="
echo "INSTALL OPI"
echo "=============================="
echo
echo "About to install the following OPI modules:"
echo "\$opimodules"
echo
read -p "Do you want to continue to install these? [Y/n] " -n 1 -sr promptOPI
if [[ "\$promptOPI" =~ ^[Yy]$ ]]; then
echo "Yes"
zypper install -y opi
opi -nm \$opimodules
else
echo -e "Cancelled\n"
fi
fi
fi
#zypper dist-upgrade --from packman --allow-vendor-change
#zypper install --from packman ffmpeg gstreamer-plugins-{good,bad,ugly,libav} libavcodec vlc-codecs
echo
echo "=============================="
echo "INSTALL PACKAGES"
echo "=============================="
echo
read -p "About to install the system packages per the backup. Do you want to continue? [Y/n] " -n 1 -sr promptPkgs
if [[ "\$promptPkgs" =~ ^[Yy] ]]; then
echo "Yes"
cat Package.list | xargs zypper install
else
echo -e "Cancelled\n"
fi
# Removal uninstalled packages:
echo
echo "=============================="
echo "REMOVE PACKAGES"
echo "=============================="
echo
read -p "!!WARNING!! The next step is to remove packages that may not be desired. Do you want to continue? " -n 1 -sr promptRm
if [[ "\$promptRm" =~ ^[Yy]$ ]]; then
# Do the thing
echo "Yes"
rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort > /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