diff options
author | Esteban Carnevale <alfplayer@mailoo.org> | 2014-12-16 14:06:18 -0300 |
---|---|---|
committer | Esteban Carnevale <alfplayer@mailoo.org> | 2014-12-16 16:45:16 -0300 |
commit | ddae41d77f23793a95b5c24117940482b7508df8 (patch) | |
tree | 343f0fd0b93e194caa30bb5f3980de43f4d0d160 | |
parent | f0705d9460fb5a8de7b1617f2daf99781e34fb1a (diff) |
libredbdiff-standalone: Improve command argument parsing including possibility to specify a single Parabola repo, and change function name comparepkgs to compare_pkgs
-rwxr-xr-x | libredbdiff-standalone | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/libredbdiff-standalone b/libredbdiff-standalone index eee0a65..ba3300a 100755 --- a/libredbdiff-standalone +++ b/libredbdiff-standalone @@ -24,17 +24,33 @@ mirrorarch='http://mirrors.kernel.org/archlinux/$repo/os/$arch' repos="libre pcr libre-multilib nonprism" - error() { echo -e "Error. $@" > /dev/stderr ; exit 1; } -if [[ $# == 1 ]] ; then - [[ $1 == -n ]] && UPDATE=0 - [[ $1 =~ ^(-h|--help)$ ]] && { echo -e "${progname}. Show [libre] packages that need to be updated from Arch repositories.\n\nUsage:\nlibredbdiff\t\tInitialize (first run) or update pacman databases\nlibredbdiff -n\t\tPrint results" ; exit 0 ; } -elif [[ $# != 0 ]] ; then - error "Bad arguments. Nothing done." -else - UPDATE=1 -fi +help() { + echo -e "${progname}. Show [libre] packages that need to be updated from Arch repositories.\n\nUsage:\nlibredbdiff\t\tInitialize (first run) or update pacman databases\nlibredbdiff -n\t\tPrint results for all Parabola repos\nlibredbdiff -n (Parabola repository)\t\tPrint results for the specified Parabola repository" +} + +while true ; do + if [[ $1 =~ ^(-n|--noupdate)$ ]] ; then + UPDATE=0 + shift + elif [[ $# == 1 && $1 =~ ^(-h|--help)$ ]] ; then + help + exit + else + if [[ ! $UPDATE ]] ; then + UPDATE=1 + fi + repo_arg="$1" + if [[ $2 ]] ; then + help + error "Bad arguments. Nothing done." + else + break + fi + fi +done + enable_repo() { repo="$1" @@ -43,7 +59,7 @@ enable_repo() { sed -i "\/\[$repo\]/,+1 s/#Include/Include/" "${conffile}" } -if (( $UPDATE )) ; then +if [[ $UPDATE == 1 ]] ; then [[ $EUID != 0 ]] && { error "To initialize $progname or update $progname pacman databases, the script must be run as root. Nothing done." ; } [[ -d "$baseconfpath" && -d "$basedbpath" && -d "$dbpath" && -d "$dbpatharch" && -e "${conffile}" && -e "${conffilearch}" && -e "${mirrorlist}" && -e "${mirrorlist}" ]] || { echo "${progname} files are missing. Initializing." ; init=1 ; } @@ -153,7 +169,7 @@ if ! pkgname="$(pacman -Qoq expac)" ; then fi } -comparepkgs() { +compare_pkgs() { if [[ ${verarch["$pkgname"]} ]] ; then cmp=$(vercmp ${ver["$pkgname"]} ${verarch["$pkgname"]}) [[ $cmp -lt 0 ]] && echo "${pkgname} needs update from the Arch package of the same name. Versions: ${ver["$pkgname"]} - ${verarch["$pkgname"]}" @@ -177,12 +193,21 @@ done < <(pacman --dbpath "${dbpatharch}" --config "${conffilearch}" -Ss | grep - expac --config "${conffile}" -S '%r/%n %v %S' > /tmp/${progname}.parabola-packages -for repo in ${repos} ; do - echo "[$repo]" +print_cmp() { + repo="$1" awk -F/ -v repo="$repo" '$1 == repo {print $2}' /tmp/${progname}.parabola-packages | while read -a line ; do ver["${line[0]}"]="${line[1]}" provides[${line[0]}]="${line[@]:2}" pkgname=${line[0]} - comparepkgs + compare_pkgs done -done +} + +if [[ ${repo_arg} ]] ; then + print_cmp "${repo_arg}" +else + for repo in ${repos} ; do + echo "[$repo]" + print_cmp "$repo" + done +fi |