Skip to content

Instantly share code, notes, and snippets.

@qub1750ul
Created June 15, 2018 15:16
Show Gist options
  • Save qub1750ul/66271e20a2ae714663b0ff7dc1b4996e to your computer and use it in GitHub Desktop.
Save qub1750ul/66271e20a2ae714663b0ff7dc1b4996e to your computer and use it in GitHub Desktop.
A garbage collector for pacman
#!/usr/bin/sh
# Create a database directory that
# ignore pacman database lock without forcefully unlock it
pacmanDb=/var/lib/pacman
noLockDb=/tmp/pacman-garbageCollector
mkdir -p $noLockDb/local $noLockDb/sync
mount --bind $pacmanDb/local $noLockDb/local
mount --bind $pacmanDb/sync $noLockDb/sync
orphanPkgs="$( pacman -Qdt | grep -Eoe '^.+\ ' )"
if [ -n "$orphanPkgs" ] ; then
pacman --noconfirm -Rsnb $noLockDb $orphanPkgs
fi
paccache -qrk 3
paccache -qruk 0
umount $noLockDb/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment