Skip to content

Instantly share code, notes, and snippets.

@daryltucker
Last active September 24, 2025 23:38
Show Gist options
  • Save daryltucker/fc54f760eeba0993ba299b5d6d99eeb2 to your computer and use it in GitHub Desktop.
Save daryltucker/fc54f760eeba0993ba299b5d6d99eeb2 to your computer and use it in GitHub Desktop.
Find all Packages installed from BAD_REPO and find replacements on GOOD_REPO
#!/bin/bash
# vim: set filetype=sh :
# @daryltucker #WorkedForMe
# Find all Packages installed from BAD_REPO and find replacements on GOOD_REPO
# This is my chance to say the ROCm ecosystem is absolute trash
# Otherwise, this script can be useful for other situations, so I'm publishing it.
# I had to manipulate REPO URLs for `apt-cache policy` matching :\
#BAD_REPO="https://repo.radeon.com/graphics/7.0.1/ubuntu/"
BAD_REPO="https://repo.radeon.com/rocm/apt/7.0.1"
#GOOD_REPO="https://repo.radeon.com/amdgpu/6.4.2.1/ubuntu/"
GOOD_REPO="https://repo.radeon.com/rocm/apt/6.4"
# Generate a List of ALL System Packages
dpkg --get-selections | grep -E '\sinstall$' | awk '{print $1}' > installed_packages.txt
# Create a list of BAD_REPO Packages
while read package; do
if apt-cache policy "$package" | grep "$BAD_REPO"; then
echo "Found BAD_REPO Package: $package"
echo "$package" >> bad_packages.txt
else
echo "$package is fine..."
fi
done < installed_packages.txt
echo "Generated bad_packages.txt"
# Create a list of GOOD_REPO Packages and their Versions
packages_to_downgrade=()
while read package; do
# Get available version from GOOD_REPO
available_version=$(apt-cache policy "$package" | grep -B 1 "$GOOD_REPO" | awk '{print $2}' | grep -v "$GOOD_REPO")
if [ -n "$available_version" ]; then
echo "Found version $available_version in GOOD_REPO repo. "
packages_to_downgrade+=("$package=$available_version")
fi
done < bad_packages.txt
# Clean Up
rm installed_packages.txt bad_packages.txt
# Explain if we didn't find anything...
if [ ${#packages_to_downgrade[@]} -eq 0 ]; then
echo "No installed packages found that need to be downgraded."
exit 0
fi
# Print Results
cat <<EOF | tee
Run the following command to downgrade the packages:
sudo apt install ${packages_to_downgrade[@]} --allow-downgrades
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment