Created
July 20, 2013 17:48
-
-
Save sprig/6045846 to your computer and use it in GitHub Desktop.
Reinstall the whole tree a given package depends on.
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/bash | |
set -o errexit | |
## Some packages kill the proces sdue to cyclic dependencies, etc. | |
IGNORE="<[-.a-zA-Z0-9]*> dpkg perl-base libaudit1 libdb5.1" | |
## User entered packages to search dependencies for. | |
DEPS=$@ | |
## Get unique (sorted) list out of the given space delimited list. | |
unique () { | |
echo $@|tr ' ' '\n'|sort -u|tr '\n' ' ' | |
} | |
## Get the dependencies of the given packages. | |
depends () { | |
apt-cache depends $@|grep Depends|awk -F ":" '{print $2}' | |
} | |
## Get the list of dependencies | |
until [ "$DEPS" = "$NEWDEPS" ]; do | |
DEPS=$(unique "$DEPS $NEWDEPS") | |
NEWDEPS=$(unique "$DEPS $(depends $DEPS)") | |
done | |
## Remove cycles | |
for pkg in $(echo $IGNORE|tr ' ' '\n'); do | |
remvar="s/$pkg[:0-9a-zA-Z]*//g" | |
echo $remvar | |
DEPS=$(echo $DEPS|sed "$remvar") | |
done | |
echo "Will attempt to reinstall: $DEPS" | |
echo | |
echo "Continue? y/[n]?" | |
## Prompt | |
while [[ $yes != "y" ]] | |
do | |
read yes | |
case $yes in | |
"y" ) | |
echo "Proceeding" | |
;; | |
"yes" ) | |
echo "Proceeding" | |
yes="y" | |
;; | |
"n" ) | |
echo "Aborting." | |
exit | |
;; | |
"no" ) | |
echo "Aborting." | |
exit | |
;; | |
"" ) | |
echo "Aborting." | |
exit | |
;; | |
* ) | |
echo "Did not understand. Continue? y/[n]?" | |
;; | |
esac | |
done | |
## Reinstall everything, including dependencies. | |
sudo aptitude reinstall $DEPS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment