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.

Revisions

  1. aleskxyz revised this gist Jun 4, 2024. 1 changed file with 3 additions and 22 deletions.
    25 changes: 3 additions & 22 deletions list_installed_packages.sh
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,8 @@
    #!/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}')
    for id in $(yum --noplugins history list all 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=$(yum --noplugins history info $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
    @@ -38,4 +19,4 @@ done <<< "$rpm_list"

    package_list=$(echo "$package_list" | sort | uniq | sed '/^$/d')

    echo "$package_list"
    echo "$package_list"
  2. aleskxyz revised this gist Jun 4, 2024. 1 changed file with 22 additions and 3 deletions.
    25 changes: 22 additions & 3 deletions list_installed_packages.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,27 @@
    #!/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 $(yum --noplugins history list all 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=$(yum --noplugins history info $id 2> /dev/null | awk '/Packages Altered/{flag=1; next} flag' | awk '$1 == "Install"' | awk '{print $2}')
    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
    @@ -19,4 +38,4 @@ done <<< "$rpm_list"

    package_list=$(echo "$package_list" | sort | uniq | sed '/^$/d')

    echo "$package_list"
    echo "$package_list"
  3. aleskxyz revised this gist Jun 4, 2024. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions list_installed_packages.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,8 @@
    #!/bin/bash

    rpm_list=""
    package_list=""

    for id in $(yum history list all 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=$(yum history info $id 2> /dev/null | awk '/Packages Altered/{flag=1; next} flag' | awk '$1 == "Install"' | awk '{print $2}')
    for id in $(yum --noplugins history list all 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=$(yum --noplugins history info $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
    @@ -21,4 +19,4 @@ done <<< "$rpm_list"

    package_list=$(echo "$package_list" | sort | uniq | sed '/^$/d')

    echo "$package_list"
    echo "$package_list"
  4. aleskxyz revised this gist Jun 3, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions list_installed_packages.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #!/bin/bash

    rpm_list=""
    package_list=""

  5. aleskxyz created this gist Jun 3, 2024.
    22 changes: 22 additions & 0 deletions list_installed_packages.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    rpm_list=""
    package_list=""

    for id in $(yum history list all 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=$(yum history info $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"