Created
May 11, 2013 06:45
-
-
Save proudzhu/5559124 to your computer and use it in GitHub Desktop.
A bash script checking aur (local) packages for needing rebuild
This file contains hidden or 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 | |
# | |
#This Script is original written by matthiaskrgr(https://github.com/matthiaskrgr/aurebuildcheck). | |
#Modified by proudzhu(https://github.com/proudzhu/dotfiles/bin/aurebuildcheck) | |
# | |
export LANG=C | |
#color used by cower | |
NC="\033[0m" | |
BOLDRED="\033[1;31m" | |
BOLDGREEN="\033[1;32m" | |
BOLDWHITE="\033[1;37m" | |
# functions and variables # | |
brokenpkgs="" | |
autoignored="" | |
# the core of the script # | |
TS=$(date +%s) # start timer | |
if [[ -z "$*" ]] ; then | |
localpackages=$(pacman -Qqm) | |
else | |
localpackages="$*" | |
fi | |
localpackagesamount=$(echo ${localpackages} | wc -w) | |
echo -e "Checking ${BOLDWHITE}${localpackagesamount}${NC} local package(s)...\n" | |
for package in $localpackages ; do | |
BROKEN="false" | |
echo -en "Checking ${BOLDWHITE}${package}${NC}..." | |
PkgArch=$(pacman -Qi $package 2>/dev/null | awk ' BEGIN {FS=" "}/^Architecture/{printf $3}') #use awk only instead of grep | |
if [[ ${PkgArch} == 'any' ]]; then #Skip package whose architecture is any | |
autoignored="${autoignored} ${package}" | |
echo -e " ${BOLDGREEN}[SKIPPED]${NC}" | |
continue | |
fi | |
packagefiles=$(pacman -Qql $package | egrep "/s?bin/\w|\.so\.?|\.o$") #only choose binary, .so and .o files | |
for file in $packagefiles; do # check the files | |
if (( $(file $file | grep -c 'ELF') != 0 )); then | |
# Is an ELF binary. | |
libs=$(readelf -d "${file}" | awk 'BEGIN {FS="["}/NEEDED/{printf $2}'|tr ']' '\n') | |
for lib in ${libs} ; do | |
# needed libs | |
if [ -z $(whereis ${lib} | awk '{print $2}') ] && [ -z $(find $(dirname ${file}) -type f -name ${lib}) ] ; then #check local libs and bundled libs | |
# Missing lib. | |
echo -e "\n\t ${BOLDRED}${file}${NC} needs ${BOLDRED}${lib}${NC}" | |
BROKEN="true" # to avoid packages being listed in the brokenpkg array several times | |
fi | |
done | |
fi | |
done | |
if [[ ${BROKEN} == "true" ]] ; then | |
brokenpkgs="${brokenpkgs} ${package}" | |
elif [[ ${BROKEN} == "false" ]] ; then | |
echo -e " ${BOLDGREEN}[OK]${NC}" | |
fi | |
done | |
echo "everything done." | |
brokenamount=$(echo ${brokenpkgs} | wc -w) | |
echo -e "\n${BOLDWHITE}${brokenamount}${NC} package(s) may need rebuild: \n${BOLDRED}${brokenpkgs}${NC}\n" | |
autoignoredamount=$(echo ${autoignored} | wc -w) | |
echo -e "${BOLDWHITE}${autoignoredamount}${NC} package(s) auto ignored: \n${BOLDGREEN}${autoignored}${NC}\n" | |
#timeend | |
TE=$(date +%s) | |
TD=$((TE-TS)) | |
echo -e "Done after ${BOLDWHITE}${TD}${NC} seconds." | |
echo "This script may not be able to distinguish between required and optional dependencies!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment