Skip to content

Instantly share code, notes, and snippets.

@aleskxyz
Last active August 17, 2024 07:57
Show Gist options
  • Select an option

  • Save aleskxyz/b1b8caf2eeae28fb320bceb26a360350 to your computer and use it in GitHub Desktop.

Select an option

Save aleskxyz/b1b8caf2eeae28fb320bceb26a360350 to your computer and use it in GitHub Desktop.
List of Exclusively Installed Yum Packages
#!/bin/bash
if command -v dnf &> /dev/null; then
PM="dnf"
elif command -v yum &> /dev/null; then
PM="yum"
else
echo "Neither yum nor dnf found."
exit 1
fi
if [ "$PM" == "dnf" ]; then
history_list_cmd="dnf --noplugins history list"
history_info_cmd="dnf --noplugins history info"
else
history_list_cmd="yum --noplugins history list all"
history_info_cmd="yum --noplugins history info"
fi
rpm_list=""
package_list=""
for id in $($history_list_cmd 2> /dev/null | grep -v System | sed 's/^ *//;s/ *| */|/g' | grep -E "^[0-9]+\|" | awk -F '|' '$4 == "Install" || $4 ~ /I/' | cut -d '|' -f1); do
result=$($history_info_cmd $id 2> /dev/null | awk '/Packages Altered/{flag=1; next} flag' | awk '$1 == "Install"' | awk '{print $2}')
if [ -n "$result" ]; then
rpm_list+="$result"$'\n'
fi
done
rpm_list=$(echo "$rpm_list" | sed '/^$/d')
while IFS= read -r package; do
package_name=$(rpm -q --queryformat '%{NAME}\n' "$package" 2>/dev/null)
if [ $? -eq 0 ]; then
package_list+="$package_name"$'\n'
fi
done <<< "$rpm_list"
package_list=$(echo "$package_list" | sort | uniq | sed '/^$/d')
echo "$package_list"
@aleskxyz
Copy link
Copy Markdown
Author

aleskxyz commented Jun 3, 2024

This script extracts and lists packages exclusively installed via Yum package manager. It parses the Yum history to identify packages that were installed without dependencies or updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment