69 lines
1.6 KiB
Plaintext
69 lines
1.6 KiB
Plaintext
|
#!/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 no other package depends on). 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. An array of packages to keep
|
||
|
# is stored in the FOSTERED variable. Packages from core are never considered
|
||
|
# for deletion.
|
||
|
#
|
||
|
|
||
|
PRT_GET=prt-cache
|
||
|
|
||
|
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.conf
|
||
|
[ -f $CONF ] && . $CONF || mkdir -p ${XDG_CONFIG_HOME}
|
||
|
|
||
|
echo "Checking packages for orphans..."
|
||
|
|
||
|
while true ; do
|
||
|
RECHECK=0
|
||
|
|
||
|
orphans=$(comm -13 <(cat <(find "$BASE" -maxdepth 1 -type d -printf "%f\n") \
|
||
|
<(for (( k=0; k<${#FOSTERED[@]}; k++ )); do echo "${FOSTERED[$k]}"; done) \
|
||
|
| sort -u) <($PRT_GET listorphans | sort) | tr '\n' ' ')
|
||
|
|
||
|
for PACKAGE in ${orphans[@]}; do
|
||
|
echo
|
||
|
$PRT_GET info $PACKAGE
|
||
|
echo
|
||
|
|
||
|
echo -n "Uninstall $PACKAGE? (y/N) "
|
||
|
read ANSWER
|
||
|
|
||
|
if [ "$ANSWER" = "y" ] ; then
|
||
|
$PKGRM $PACKAGE
|
||
|
RECHECK=1
|
||
|
else
|
||
|
FOSTERED=( $PACKAGE ${FOSTERED[@]} )
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
if [ "$RECHECK" = "0" ] ; then
|
||
|
echo -n "FOSTERED=(" > $CONF
|
||
|
for (( k=0; k<${#FOSTERED[@]}; k++ )); do
|
||
|
echo -n "${FOSTERED[$k]} " >> $CONF
|
||
|
done
|
||
|
echo ")" >> $CONF
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
echo
|
||
|
echo "Re-checking packages for new orphans..."
|
||
|
done
|