Documentation/scripts/pkgfoster

62 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2022-05-28 12:49:20 -04:00
#!/bin/bash
#
# pkgfoster 2005-11-27
# Jukka Heino <jukka@karsikkopuu.net>
#
# pkgfoster is a simple script you can use to clean up orphaned packages (i.e.
# packages which do not appear in the "Depends on: " line of any other installed
# package). It uses prt-cache by default, so remember to build the cache with
# "prt-get cache". You can also use normal prt-get by modifying the PRT_GET
# variable. The file ~/.config/pkgfoster.keep contains a list of all packages
# you've decided to keep. Packages from core are never considered for deletion.
2022-05-28 12:49:20 -04:00
#
PRT_GET=prt-cache
2023-11-28 20:07:03 -05:00
RECHECK=1
2022-05-28 12:49:20 -04:00
if [ $UID = 0 ]; then
PKGRM=pkgrm
else
if command -v doas; then
PKGRM="doas pkgrm"
elif command -v sudo; then
PKGRM="sudo pkgrm"
else
PKGRM="su -c pkgrm"
fi
fi
BASE=$(awk '/^[[:space:]]*prtdir.*\/core/ {print $2}' /etc/prt-get.conf)
CONF="${XDG_CONFIG_HOME:="$HOME/.config"}/pkgfoster.keep"
if [ ! -f "$CONF" ]; then
mkdir -p "${XDG_CONFIG_HOME}"
touch "$CONF"
fi
2022-05-28 12:49:20 -04:00
2023-11-28 20:07:03 -05:00
while [ $RECHECK = 1 ] ; do
echo
echo "(Re-)checking packages for orphans..."
2022-05-28 12:49:20 -04:00
RECHECK=0
2023-11-28 20:07:03 -05:00
mapfile -t orphans < <(comm -23 <($PRT_GET listorphans | sort) \
<(cat <(find "$BASE" -maxdepth 1 -type d -printf "%f\n") "$CONF" \
2023-11-28 20:07:03 -05:00
| sort -u) )
2022-05-28 12:49:20 -04:00
for PACKAGE in ${orphans[@]}; do
echo
2023-11-28 20:07:03 -05:00
$PRT_GET info "$PACKAGE"
2022-05-28 12:49:20 -04:00
echo
echo -n "Uninstall $PACKAGE? (y/N) "
2023-11-28 20:07:03 -05:00
read -r ANSWER
2022-05-28 12:49:20 -04:00
if [ "$ANSWER" = "y" ] ; then
2023-11-28 20:07:03 -05:00
$PKGRM "$PACKAGE"
2022-05-28 12:49:20 -04:00
RECHECK=1
else
2023-11-28 20:07:03 -05:00
echo "$PACKAGE" >> "$CONF"
2022-05-28 12:49:20 -04:00
fi
done
done