Changeset - a7f2a8344d3c
[Not reviewed]
default
0 2 0
Dennis Fink - 7 years ago 2013-03-04 20:54:10
the_metalgamer@hackerspace.lu
implemented -q and -v and updated yaah.rst
2 files changed with 85 insertions and 26 deletions:
yaah
74
24
yaah.rst
11
2
0 comments (0 inline, 0 general)
yaah
Show inline comments
...
 
@@ -60,16 +60,17 @@ readonly ALL_OFF BOLD BLUE GREEN RED YEL
 

	
 
#=== FUNCTION =================================================================
 
#        Name: msg
 
# Description: Print message with a green pretag
 
# Description: Print message with a green pretag if $quiet is not set
 
# Parameter 1: Message to print
 
#==============================================================================
 

	
 
# copied from makepkg
 
# copied from makepkg and modified
 
msg () {
 

	
 
    local mesg=$1; shift
 
    printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 

	
 
    if [[ $quiet -eq 0 ]]; then
 
        local mesg=$1; shift
 
        printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
 
    fi
 
}
 

	
 
#=== FUNCTION =================================================================
...
 
@@ -82,7 +83,7 @@ msg () {
 
msg2 () {
 

	
 
    local mesg=$1; shift
 
    printf "    ${BLUE}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 
    printf "    ${BLUE}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
 

	
 
}
 

	
...
 
@@ -117,6 +118,7 @@ check_version () {
 
        local newversion=$3
 

	
 
        msg "Checking version for '$name'"
 

	
 
        if [[ $(vercmp $oldversion $newversion) -eq -1 ]]; then
 
            msg2 "New version for '$name': $oldversion -> $newversion"
 
        fi
...
 
@@ -136,14 +138,26 @@ check_version () {
 
query_online_version () {
 

	
 
    if [[ "$#" -eq 1 ]]; then
 

	
 
        msg "Getting version of online packages."
 

	
 
        declare -a packages=("${!1}")
 
        local arguments=""
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Creating argument list."
 
        fi
 
        for package in "${packages[@]}"; do
 
            arguments+="&arg\[\]=${package%\ *}"
 
        done
 

	
 
        if [[ $verbose -ge 1 ]]; then
 
            msg "Sending query to AUR."
 
        fi
 

	
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "URL is: ${AURURL}rpc.php?type=multiinfo$arguments"
 
        fi
 

	
 
        local aur_response=$(curl -s -fL "${AURURL}rpc.php?type=multiinfo$arguments")
 

	
 
        if [[ $? -ne 0 ]]; then
...
 
@@ -151,12 +165,33 @@ query_online_version () {
 
            return 1
 
        fi
 

	
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Getting numbers of objects in json array!"
 
        fi
 
        local number=$(jshon -Q -e results -l <<< "$aur_response")
 

	
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Looping over json array!"
 
        fi
 

	
 
        for i in $(seq 0 $(( $number -1 )) ); do
 

	
 
            if [[ $verbose -ge 2 ]]; then
 
                msg "Extracting package name."
 
            fi
 

	
 
            local package_name=${packages[$i]%\ *}
 

	
 
            if [[ $verbose -ge 2 ]]; then
 
                msg "Extracting old package version."
 
            fi
 

	
 
            local old_package_version=${packages[$i]#*\ }
 

	
 
            if [[ $verbose -ge 2 ]]; then
 
                msg "Extracting new package version."
 
            fi
 

	
 
            local new_package_version=$(jshon -Q -e results -e $i -e Version \
 
                <<< $aur_response | tr -d "\"")
 

	
...
 
@@ -188,6 +223,10 @@ query_local_version () {
 
    done < <(pacman -Qm $@)
 
    if [[ $? -eq 0 ]]; then
 
        msg "There are ${#packages[@]} foreign packages to check."
 
        
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Sorting package array!"
 
        fi
 
        sorted_packages=($(sort <<<"${packages[*]}"))
 
        query_online_version sorted_packages[@]
 
    else
...
 
@@ -207,8 +246,14 @@ extract_and_remove () {
 

	
 
    if [[ $# -eq 1 ]]; then
 
        if [[ -f $1 ]]; then
 

	
 
            msg "Extracting '$1'"
 

	
 
            tar xzf $1 -C $downloaddir
 
            
 
            if [[ $verbose -ge 1 ]]; then
 
                msg "Removing '$1'"
 
            fi
 
            rm $1
 
        else
 
            error "'$1' is not a file"
...
 
@@ -235,6 +280,7 @@ download () {
 
            local filename="${1}.tar.gz"
 

	
 
            msg "Downloading '$filename' to '$downloaddir'"
 

	
 
            curl -s -fL -o "$downloaddir/$filename" \
 
                "${AURURL}packages/$start/$1/$filename"
 

	
...
 
@@ -268,6 +314,7 @@ usage() {
 

	
 
check_flag=
 
verbose=0
 
quiet=0
 
downloaddir="$PWD"
 

	
 

	
...
 
@@ -281,26 +328,24 @@ while true; do
 
            check_flag=1
 
            shift
 
            ;;
 
        -d|--downloaddir)
 
            if [[ -d $2 ]]; then
 
                downloaddir=$2
 
                shift 2
 
            else
 
                error "$2 is not a directory"
 
                exit 1
 
            fi
 
        -d)
 
            downloaddir=$2
 
            shift 2
 
            ;;
 
        --downloaddir=*)
 
            if [[ -d ${1#*=} ]]; then
 
                downloaddir=${1#*=}
 
                shift
 
            else
 
                error "${1#*=} is not a directory"
 
                exit 1
 
            fi
 
            downloaddir=${1#*=}
 
            shift
 
            ;;
 
        -v|--verbose)
 
            verbose=$((verbose+1))
 
            verbose=1
 
            shift
 
            ;;
 
        -vv)
 
            verbose=2
 
            shift
 
            ;;
 
        -q|--quiet)
 
            quiet=1
 
            shift
 
            ;;
 
        --)
...
 
@@ -317,8 +362,13 @@ while true; do
 
    esac
 
done
 

	
 
# remove trailing slash
 
downloaddir=${downloaddir%/}
 
# check if downloaddir is a directory and remove trailing slash
 
if [[ -d $downloaddir ]]; then
 
    downloaddir=${downloaddir%/}
 
else
 
    error "$downloaddir is not a directory"
 
    exit 1
 
fi
 

	
 
if [[ "$check_flag" ]]; then
 
    query_local_version $@
yaah.rst
Show inline comments
...
 
@@ -34,8 +34,8 @@ OPTIONS
 
-h, --help                              Display help
 
-c, --check                             Check installed packages if there are updates available
 
-d directory, --downloaddir=directory   Download packages to the specified directory
 
-v                                      Be more verbose, can be supplied multiple times
 
-q                                      Be less verbose
 
-v, --verbose                           Be more verbose, can be supplied at maximum 2 times
 
-q, --quiet                             Be less verbose. Takes precedence over -v and --verbose
 

	
 
EXAMPLES
 
========
...
 
@@ -52,6 +52,15 @@ yaah -c
 
yaah -c task-git
 
    Check if there is a update available for task-git.
 

	
 
yaah -c -v
 
    Be more verbose at checking.
 

	
 
yaah -c -vv
 
    Be even more verbose at checking as above.
 

	
 
yaah -v task-git
 
    Be more verbose at downloading the packagie task-git.
 

	
 
SEE ALSO
 
========
 

	
0 comments (0 inline, 0 general)