Skip to content

Instantly share code, notes, and snippets.

@89luca89
Last active November 13, 2023 15:05
Show Gist options
  • Save 89luca89/36ec98bf3e3f3a5d201f29b938241ddd to your computer and use it in GitHub Desktop.
Save 89luca89/36ec98bf3e3f3a5d201f29b938241ddd to your computer and use it in GitHub Desktop.
This script will compare current package list on a system with the "ideal" one of a fresh install of the same system.
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
sudo "$0" "$@"
exit
fi
GREEN='\033[1m\033[32m'
YELLOW='\033[1m\033[33m'
CLEAR='\033[0m'
print_yellow() {
printf "${YELLOW}"
printf "%s\n" "$@"
printf "${CLEAR}"
}
print_green() {
printf "${GREEN}"
printf "%s\n" "$@"
printf "${CLEAR}"
}
print_green "Checking updates..."
zypper ref
#
BASE_PATTERNS="$(rpm -qa --qf "%{NAME}\n" | grep ^patterns | sort -u)"
# Add basic packages added by Yast during installation
BASE_PATTERNS="$BASE_PATTERNS
MicroOS-release
NetworkManager
btrfsprogs
cryptsetup
e2fsprogs
glibc
grub2
grub2-branding-openSUSE
grub2-i386-pc
grub2-i386-pc-extras
grub2-snapper-plugin
grub2-x86_64-efi
grub2-x86_64-efi-extras
irqbalance
kernel-default
kernel-firmware-all
kexec-tools
numactl
openssh
os-prober
pam
rpm
snapper
transactional-update
"
if grep -qi amd /proc/cpuinfo; then
BASE_PATTERNS="$BASE_PATTERNS
ucode-amd"
elif grep -qi intel /proc/cpuinfo; then
BASE_PATTERNS="$BASE_PATTERNS
ucode-intel"
fi
print_green "Reconstructing system state..."
BASE_PACKAGES="$(zypper \
--installroot /tmp/ \
install -y --dry-run --force-resolution --replacefiles --force $BASE_PATTERNS |
grep -A1 'packages are going to be installed' | tail -n+2 | tr ' ' '\n' | sort -u)"
print_green "Retrieving installed packages..."
INSTALLED_PACKAGES="$(rpm -qa --qf "%{NAME}\n" | grep -Ev '^(gpg-pubkey)' | sort -u)"
EXTRA=$(diff <(echo "$BASE_PACKAGES" | sort -u) <(echo "$INSTALLED_PACKAGES") |
grep '>' | cut -d'>' -f2- | sed -r '/^\s*$/d')
MISSING=$(diff <(echo "$BASE_PACKAGES" | sort -u) <(echo "$INSTALLED_PACKAGES") |
grep '<' | cut -d'<' -f2- | sed -r '/^\s*$/d')
print_green "Computing diff..."
print_yellow "######## EXTRA"
echo "$EXTRA"
print_yellow "######## MISSING"
echo "$MISSING"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment