From eb2e898b093effbbb61c5a2ffa7eb731ffc6d6c5 Mon Sep 17 00:00:00 2001 From: Esteban Carnevale Date: Tue, 16 Dec 2014 15:41:57 -0300 Subject: libredbdiff-standalone: Multiple fixes and improvements --- libredbdiff-standalone | 93 +++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/libredbdiff-standalone b/libredbdiff-standalone index ba3300a..71da50e 100755 --- a/libredbdiff-standalone +++ b/libredbdiff-standalone @@ -27,41 +27,47 @@ repos="libre pcr libre-multilib nonprism" error() { echo -e "Error. $@" > /dev/stderr ; exit 1; } 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" + 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 [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 + if [[ $1 =~ ^(-n|--noupdate)$ ]] ; then + update=0 + shift + elif [[ $1 =~ ^(-h|--help)$ ]] ; then + echo "-h or --help was specified as command argument" + help + exit + elif [[ $update == 0 ]] ; then + if [[ $2 ]] ; then + help + error "Bad arguments. Nothing done." + elif [[ $1 ]] ; then + repo_arg="$1" + for repo in ${repos} ; do + if [[ "$repo" == "$repo_arg" ]] ; then + found=1 + break + fi + done + if [[ $found != 1 ]] ; then + error "The specified Parabola repo \"${repo_arg}\" cannot be compared. It's not in the list of repos in the configuration variable \"repos\"." + fi + break + elif [[ ! $1 ]] ; then + break + fi + else + break + fi done -enable_repo() { - repo="$1" - echo "Enabling repo \"$repo\" in ${conffile}" - sed -i "s/\#\[$repo\]/[$repo]/" "${conffile}" - sed -i "\/\[$repo\]/,+1 s/#Include/Include/" "${conffile}" -} +if [[ $update != 0 ]] ; then + if [[ $EUID != 0 ]] ; then + error "The current user is not the user \"root\". To initialize $progname or update $progname pacman databases, the script must be run as root. Nothing done." + fi -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 ; } createdir() { @@ -77,6 +83,14 @@ if [[ $UPDATE == 1 ]] ; then createdir "$dbpath" createdir "$dbpatharch" + enable_repo() { + repo="$1" + conffile_arg="$2" + echo "Enabling repo \"$repo\" in ${conffile_arg}" + sed -i "s/\#\[$repo\]/[$repo]/" "${conffile_arg}" + sed -i "\/\[$repo\]/,+1 s/#Include/Include/" "${conffile_arg}" + } + downloadfile() { if [[ ! -e $1 ]] ; then echo "$2" @@ -139,7 +153,7 @@ if [[ $UPDATE == 1 ]] ; then exit 0 else filenotfound() { - [[ ! -r $1 ]] && { error "Could not read $1. Nothing done.\nIt may be necessary to run libredbdiff without arguments as root to initialize ${progname}." ; } + [[ ! -r $1 ]] && { error "Could not read $1. Nothing done.\nIt could be necessary to run libredbdiff without arguments as root to initialize ${progname}." ; } } filenotfound "${dbpath}" filenotfound "${dbpatharch}" @@ -147,7 +161,9 @@ else filenotfound "${conffilearch}" filenotfound "${mirrorlist}" filenotfound "${mirrorlistarch}" -fi +fi # close "if [[ $update != 0 ]] ; then" + +if [[ $update == 0 ]] ; then unset provides ver verarch declare -Ax provides ver verarch @@ -203,11 +219,12 @@ print_cmp() { done } -if [[ ${repo_arg} ]] ; then - print_cmp "${repo_arg}" -else - for repo in ${repos} ; do - echo "[$repo]" - print_cmp "$repo" - done -fi + if [[ ${repo_arg} ]] ; then + print_cmp "${repo_arg}" + else + for repo in ${repos} ; do + echo "[$repo]" + print_cmp "$repo" + done + fi +fi # close "if [[ $update == 0 ]] ; then" -- cgit v1.2.3