Skip to content

Instantly share code, notes, and snippets.

@miyaokamarina
Last active April 6, 2021 23:59
Show Gist options
  • Save miyaokamarina/722bdfd51f43eb2ab8bfb11a9a981676 to your computer and use it in GitHub Desktop.
Save miyaokamarina/722bdfd51f43eb2ab8bfb11a9a981676 to your computer and use it in GitHub Desktop.
Arch package list generator

Known bugs

  • Incorrectly handles packages with Provides field.

Usage

  • ./native.sh > native.txt
  • ./external.sh > external.txt
#!/usr/bin/bash
################################################################################
# #
# Well, generate minimal list of currently installed AUR packages. #
# #
################################################################################
pacman -Qqemtt | sort
#!/usr/bin/bash
########################################################################################################################
# #
# Generate minimal native packages and groups list to reproduce current installation. #
# #
########################################################################################################################
native=$( pacman -Qqn | sort ) # ← All packages installed from Arch repos (excluding AUR, ofc).
explicit=$( pacman -Qqentt | sort ) # ← Explicitly installed packages excluding AUR that aren't direct dependencies.
installedGroups="" # ← Groups with all packages installed.
grouped="" # ← Packages from installed groups.
# ↓ All groups:
groups=$(curl -s "https://archlinux.org/groups/" | pup '.results a text{}')
# ↓ Iterate over groups:
while read name; do
# ↓ Packages in group:
group=$(curl -s "https://archlinux.org/groups/x86_64/${name}/" | pup '.results a text{}' | sort | uniq)
# ↓ Packages that are both in current group and in installed packages list:
common=$(comm -12 <(echo "${native}") <(echo "${group}") | sort)
# ↓ Check if all packages from group are installed:
if [ "${common}" = "${group}" ]; then
grouped=$( cat <<< "${grouped}"; cat <<< "${group}" )
installedGroups=$( cat <<< "${installedGroups}"; cat <<< "${name}" )
fi
done <<< $(echo "${groups}")
# ↓ Remove grouped packages from explitcitly installed list:
woGrouped=$(comm -23 <(echo "${explicit}") <(sort <<< "${grouped}"))
# ↓ Add group names, remove blank lines (idk if they may be or not may be, but idc):
wGroups=$((cat <<< "${woGrouped}"; cat <<< "${installedGroups}") | sort | awk "NF")
echo "${wGroups}" # ← Print result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment