pkgfoster: small refactoring

This commit is contained in:
John McQuah 2023-11-29 01:07:03 +00:00
parent 15a8fcc3f3
commit 56a8fc12d4
2 changed files with 11 additions and 16 deletions

View File

@ -29,6 +29,6 @@ affected ports using
.B prt\-get update \-fr .B prt\-get update \-fr
(see \fBprt\-get\fP(8) for more detailed examples). (see \fBprt\-get\fP(8) for more detailed examples).
.SH AUTHORS .SH AUTHORS
Jukka Heino <jukka@karsikkopuu.net> Jukka Heino <jukka@karsikkopuu.net>, John McQuah <jmcquah@disroot.org>
.SH SEE ALSO .SH SEE ALSO
\fBprt\-cache\fP(8), \fBprt\-get\fP(8), \fBPkgfile\fP(5), \fBrevdep\fP(1) \fBprt\-cache\fP(8), \fBprt\-get\fP(8), \fBPkgfile\fP(5), \fBrevdep\fP(1)

View File

@ -12,6 +12,7 @@
# #
PRT_GET=prt-cache PRT_GET=prt-cache
RECHECK=1
if [ $UID = 0 ]; then if [ $UID = 0 ]; then
PKGRM=pkgrm PKGRM=pkgrm
@ -32,35 +33,29 @@ if [ ! -f "$CONF" ]; then
touch "$CONF" touch "$CONF"
fi fi
echo "Checking packages for orphans..." while [ $RECHECK = 1 ] ; do
echo
while true ; do echo "(Re-)checking packages for orphans..."
RECHECK=0 RECHECK=0
orphans=$(comm -23 <($PRT_GET listorphans | sort) \ mapfile -t orphans < <(comm -23 <($PRT_GET listorphans | sort) \
<(cat <(find "$BASE" -maxdepth 1 -type d -printf "%f\n") "$CONF" \ <(cat <(find "$BASE" -maxdepth 1 -type d -printf "%f\n") "$CONF" \
| sort -u) | tr '\n' ' ') | sort -u) )
for PACKAGE in ${orphans[@]}; do for PACKAGE in ${orphans[@]}; do
echo echo
$PRT_GET info $PACKAGE $PRT_GET info "$PACKAGE"
echo echo
echo -n "Uninstall $PACKAGE? (y/N) " echo -n "Uninstall $PACKAGE? (y/N) "
read ANSWER read -r ANSWER
if [ "$ANSWER" = "y" ] ; then if [ "$ANSWER" = "y" ] ; then
$PKGRM $PACKAGE $PKGRM "$PACKAGE"
RECHECK=1 RECHECK=1
else else
echo $PACKAGE >> "$CONF" echo "$PACKAGE" >> "$CONF"
fi fi
done done
if [ "$RECHECK" = "0" ] ; then
exit 0
fi
echo
echo "Re-checking packages for new orphans..."
done done