diff options
author | James Meyer <james.meyer@operamail.com> | 2010-01-03 21:01:10 (GMT) |
---|---|---|
committer | James Meyer <james.meyer@operamail.com> | 2010-01-03 21:01:10 (GMT) |
commit | 2c504801a18ee36027ea994ad146cb4b64b63b5c (patch) | |
tree | 2005eb9e31cffe318307bad498a64b5ff25bb109 /build_tools/bin/check_repo/parse_pkgbuilds.sh | |
parent | e87d0c681b1ecebc9a641a9eeb059c8ae85c13f3 (diff) | |
download | linhes_dev-2c504801a18ee36027ea994ad146cb4b64b63b5c.zip |
check_repo:
various scripts to cleanup the repo.
repo_check: only reports on problems
repo-cleanup.sh will removed stray or duplicate packages in the pkg repo dir.
repo-cleanup.sh does not change anything pkgbuild related
Diffstat (limited to 'build_tools/bin/check_repo/parse_pkgbuilds.sh')
-rwxr-xr-x | build_tools/bin/check_repo/parse_pkgbuilds.sh | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/build_tools/bin/check_repo/parse_pkgbuilds.sh b/build_tools/bin/check_repo/parse_pkgbuilds.sh new file mode 100755 index 0000000..5cd17e4 --- /dev/null +++ b/build_tools/bin/check_repo/parse_pkgbuilds.sh @@ -0,0 +1,149 @@ +#!/bin/bash + +# Usage : parse_pkgbuilds.sh arch <pkgbuilds_dir1,dir2,...> +# Example : parse_pkgbuilds.sh i686 /var/abs/core /var/abs/extra + +exit() { return; } + +splitpkg_overrides=('depends' 'optdepends' 'provides' 'conflicts') +variables=('pkgname' 'pkgbase' 'pkgver' 'pkgrel' 'makedepends' 'arch' ${splitpkg_overrides[@]}) +readonly -a variables splitpkg_overrides + +backup_package_variables() { + for var in ${splitpkg_overrides[@]}; do + indirect="${var}_backup" + eval "${indirect}=(\${$var[@]})" + done +} + +restore_package_variables() { + for var in ${splitpkg_overrides[@]}; do + indirect="${var}_backup" + if [ -n "${!indirect}" ]; then + eval "${var}=(\${$indirect[@]})" + else + unset ${var} + fi + done +} + +print_info() { + echo -e "%NAME%\n$pkgname\n" + echo -e "%VERSION%\n$pkgver-$pkgrel\n" + echo -e "%PATH%\n$dir\n" + + if [ -n "$pkgbase" ]; then + echo -e "%BASE%\n$pkgbase\n" + fi + + if [ -n "$arch" ]; then + echo "%ARCH%" + for i in ${arch[@]}; do echo $i; done + echo "" + fi + if [ -n "$depends" ]; then + echo "%DEPENDS%" + for i in ${depends[@]}; do + echo $i + done + echo "" + fi + if [ -n "$makedepends" ]; then + echo "%MAKEDEPENDS%" + for i in ${makedepends[@]}; do + echo $i + done + echo "" + fi + if [ -n "$conflicts" ]; then + echo "%CONFLICTS%" + for i in ${conflicts[@]}; do echo $i; done + echo "" + fi + if [ -n "$provides" ]; then + echo "%PROVIDES%" + for i in ${provides[@]}; do echo $i; done + echo "" + fi +} + +source_pkgbuild() { + ret=0 + dir=$1 + pkgbuild=$dir/PKGBUILD + for var in ${variables[@]}; do + unset ${var} + done + source $pkgbuild &>/dev/null || ret=$? + + # ensure $pkgname and $pkgver variables were found + if [ $ret -ne 0 -o -z "$pkgname" -o -z "$pkgver" ]; then + echo -e "%INVALID%\n$pkgbuild\n" + return 1 + fi + + if [ "${#pkgname[@]}" -gt "1" ]; then + pkgbase=${pkgbase:-${pkgname[0]}} + for pkg in ${pkgname[@]}; do + if [ "$(type -t package_${pkg})" != "function" ]; then + echo -e "%INVALID%\n$pkgbuild\n" + return 1 + else + backup_package_variables + pkgname=$pkg + while IFS= read -r line; do + var=${line%%=*} + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + for realvar in ${variables[@]}; do + if [ "$var" == "$realvar" ]; then + eval $line + break + fi + done + done < <(type package_${pkg}) + print_info + restore_package_variables + fi + done + else + echo + print_info + fi + + return 0 +} + +find_pkgbuilds() { + #Skip over some dirs + local d="${1##*/}" + if [ "$d" = "CVS" -o "$d" = ".svn" ]; then + return + fi + + if [ -f $1/PKGBUILD ]; then + source_pkgbuild $1 + return + fi + empty=1 + for dir in $1/*; do + if [ -d $dir ]; then + find_pkgbuilds $dir + unset empty + fi + done + if [ -n "$empty" ]; then + echo -e "%MISSING%\n$1\n" + fi +} + +if [ -z "$1" -o -z "$2" ]; then + exit 1 +fi + +CARCH=$1 +shift +for dir in "$@"; do + find_pkgbuilds $dir +done + +exit 0 |