Files
scratchpkg/pkgdeplist
2018-07-20 18:30:42 +08:00

142 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
RED='\e[0;31m' #Red
GREEN='\e[0;32m' #Green
YELLOW='\e[0;33m' #Yellow
CYAN='\e[0;36m' #Cyan
CRESET='\e[0m' #Reset color
msgerr() {
echo -e "${RED}==> ERROR:${CRESET} $1"
}
msginst() {
echo -e "[${GREEN}i${CRESET}] $1"
}
msgmiss() {
echo -e "[${YELLOW}m${CRESET}] $1"
}
msgnoinst() {
echo -e "[ ] $1"
}
if [ ! "$1" ]; then
msgerr "Please specify package name to list its dependencies order."
exit 1
fi
while read repodir repourl junk; do
case $repodir in
""|"#"*) continue ;;
esac
PORT_REPO+=($repodir)
done < /etc/scratchpkg.repo
checkdep() {
local depends
depends=$(grep "^# depends[[:blank:]]*:" $(getportpath "$1")/spkgbuild | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//')
source $(getportpath "$1")/spkgbuild
for dep in ${depends[@]}; do
echo $dep
done
}
getportpath() {
for repo in ${PORT_REPO[@]}; do
if [[ -f $repo/$1/spkgbuild ]]; then
echo "$(dirname $repo/$1/spkgbuild)"
return 0
fi
done
return 1
}
deplist() {
# check currently process package for loop
if [ ${#CHECK[@]} -gt 0 ]; then
if [[ "$(echo ${CHECK[@]} | tr " " "\n" | grep -x $1)" == "$1" ]]; then
if [ "$IGNORE_LOOP" = 1 ]; then
return 0
else
msgerr "loop dependency found: $1"
exit 1
fi
fi
fi
# add package to currently process
CHECK+=($1)
# check dependencies
for i in $(checkdep $1); do
if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "" ]]; then
deplist $i
fi
done
# add dependency to list checked dep
if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $1) = "" ]]; then
DEP+=($1)
fi
# delete process package array
for i in "${!CHECK[@]}"; do
if [[ ${CHECK[i]} = "$1" ]]; then
unset 'CHECK[i]'
fi
done
}
INDEX_DIR="/var/lib/scratchpkg/index"
while [ "$1" ]; do
case $1 in
-i|--installed) INSTALLED=1 ;;
-n|--not-installed) NOT_INSTALLED=1 ;;
-m|--missing) MISSING=1 ;;
-l|--loop) IGNORE_LOOP=1 ;;
*) PKG+=($1) ;;
esac
shift
done
for pkg in ${PKG[@]}; do
if [ ! $(getportpath $pkg) ]; then
msgerr "Package '$pkg' not found."
exit 1
fi
done
for pkg in ${PKG[@]}; do
deplist $pkg
done
for deps in ${DEP[@]}; do
if [ "$NOT_INSTALLED" = 1 ]; then
if [ ! -e $INDEX_DIR/$deps/.pkginfo ]; then
echo "$deps"
fi
elif [ "$MISSING" = 1 ]; then
if [ ! $(getportpath "$deps") ]; then
echo "$deps"
fi
elif [ "$INSTALLED" ]; then
if [ -e $INDEX_DIR/$deps/.pkginfo ]; then
echo "$deps"
fi
else
if [ -e $INDEX_DIR/$deps/.pkginfo ]; then
msginst "$deps"
elif ! getportpath "$deps" >/dev/null; then
msgmiss "$deps"
else
msgnoinst "$deps"
fi
fi
done
exit 0