Last active
September 1, 2017 15:09
Automatic removal of orphaned packages after uninstallation in SliTaz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
findorphans() | |
{ | |
DEPENDENCIES="" | |
ORPHANLIST="" | |
for PACKAGE in /var/lib/tazpkg/installed/* # look at all PACKAGES installed | |
do | |
. $PACKAGE/receipt # source the receipt, where the dependency informations are contained | |
for DEPENDENCY in $DEPENDS # write every dependency to a ... | |
do | |
DEPENDENCIES="${DEPENDENCIES}$DEPENDENCY\n" # ... list of all packages, that installed packages depend upon in the string "DEPENDENCIES" | |
done | |
done | |
for PACKAGE in /var/lib/tazpkg/installed/* # look at all the packages again | |
do | |
ORPHAN=$(basename $PACKAGE) # select the actual package name | |
if [ -z "$(echo -e $DEPENDENCIES | grep -x $ORPHAN)" ]; then # check if the package is part of the DEPENDENCIES list | |
ORPHANLIST="${ORPHANLIST}$ORPHAN\n" # if not, then it is an orphan and added to ORPHANLIST | |
fi | |
done | |
echo $ORPHANLIST # ORPHANLIST is returned to the calling routine | |
} | |
unorphan() | |
{ | |
NEWORPHANS=1 # set a parameter for recursive loops | |
while [ $NEWORPHANS = 1 ]; # check if this loop is still valid | |
do | |
NEWORPHANS=0 # reset to no further loops as an assumption | |
ORPHANS_AFTER=$(findorphans) # call findorphans and put all the orphans found in ORPHANS_AFTER | |
for ORPHAN in $(echo -e $ORPHANS_AFTER) # check each orphaned package stored in ORPHANS_AFTER ... | |
do | |
if [ -z "$(echo -e $ORPHANS_BEFORE | grep -x $ORPHAN)" ]; then # ... if it has already been part of the orphans stored in ORPHANS_BEFORE already | |
echo y | tazpkg -r "$ORPHAN" # if not, then it is a new orphan caused by an actual removal and should be removed, too | |
NEWORPHANS=1 # after a removal, new orphans could have been produced, which makes another loop necessary | |
fi | |
done | |
done | |
} | |
# this is the actual beginning of the script | |
ORPHANS_BEFORE=$(findorphans) # call findorphans and put all the orphans found in ORPHANS_BEFORE | |
tazpkg -r $1 # remove the package named in the shell | |
unorphan # trigger the finding and removal of new orphans | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference: http://forum.slitaz.org/topic/package-management-and-orphaned-packages/page/2#post-45182