Skip to content

Instantly share code, notes, and snippets.

@F1lou
Last active September 1, 2017 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save F1lou/c7cb839dfed6e86268045bba9ca86685 to your computer and use it in GitHub Desktop.
Save F1lou/c7cb839dfed6e86268045bba9ca86685 to your computer and use it in GitHub Desktop.
Automatic removal of orphaned packages after uninstallation in SliTaz
#!/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
@F1lou
Copy link
Author

F1lou commented Sep 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment