Changeset - bf2d7f69b724
[Not reviewed]
default
0 1 0
Dennis Fink - 7 years ago 2013-03-05 08:20:48
the_metalgamer@hackerspace.lu
created two new functions to simplify verbose messages
1 file changed with 45 insertions and 33 deletions:
yaah
45
33
0 comments (0 inline, 0 general)
yaah
Show inline comments
...
 
@@ -16,9 +16,9 @@
 
#:                                                     precedence over -v and
 
#:                                                     --verbose
 
#: Requirements: jshon <http://kmkeen.com/jshon/>
 
#:      Version: 0.1
 
#:      Version: 0.1.1
 
#:      Created: 2013-02-26
 
#:     Revision: 2013-03-04
 
#:     Revision: 2013-03-05
 
#:       Author: Dennis Fink <the_metalgamer@hackerspace.lu>
 

	
 
## Security
...
 
@@ -39,7 +39,7 @@ umask $UMASK
 
SCRIPTNAME=${0##*/}
 
DESCRIPTION="Yet another AUR helper"
 
DATE_OF_CREATION=2013-02-26
 
VERSION=0.1
 
VERSION=0.1.1
 
AUTHOR="Dennis Fink <the_metalgamer@hackerspace.lu>"
 

	
 
readonly SCRIPTNAME DESCRIPTION DATE_OF_CREATION VERSION AUTHOR
...
 
@@ -86,6 +86,34 @@ msg () {
 
}
 

	
 
#=== FUNCTION =================================================================
 
#        Name: msg_verbose1
 
# Description: Prints message if $verbose is 1 or greater
 
# Parameter 1: Message to print
 
#==============================================================================
 

	
 
msg_verbose1 () {
 

	
 
    if [[ $verbose -ge 1 ]]; then
 
        msg $1
 
    fi
 

	
 
}
 

	
 
#=== FUNCTION =================================================================
 
#        Name: msg_verbose2
 
# Description: Prints message if $verbose is 2 or greater
 
# Parameter 1: Message to print
 
#==============================================================================
 

	
 
msg_verbose2 () {
 

	
 
    if [[ $verbose -ge 2 ]]; then
 
        msg $1
 
    fi
 

	
 
}
 

	
 
#=== FUNCTION =================================================================
 
#        Name: msg2
 
# Description: Print message with a blue pretag
 
# Parameter 1: Message to print
...
 
@@ -155,20 +183,16 @@ query_online_version () {
 

	
 
        declare -a packages=("${!1}")
 
        local arguments=""
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Creating argument list."
 
        fi
 

	
 
        msg_verbose2 "Creating argument list."
 

	
 
        for package in "${packages[@]}"; do
 
            arguments+="&arg\[\]=${package%\ *}"
 
        done
 

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

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

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

	
...
 
@@ -177,32 +201,23 @@ query_online_version () {
 
            return 1
 
        fi
 

	
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Getting numbers of objects in json array!"
 
        fi
 
        msg_verbose2 "Getting numbers of objects in json array!"
 

	
 
        local number=$(jshon -Q -e results -l <<< "$aur_response")
 

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

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

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

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

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

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

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

	
 
            local new_package_version=$(jshon -Q -e results -e $i -e Version \
 
                <<< $aur_response | tr -d "\"")
...
 
@@ -236,9 +251,8 @@ query_local_version () {
 
    if [[ $? -eq 0 ]]; then
 
        msg "There are ${#packages[@]} foreign packages to check."
 

	
 
        if [[ $verbose -ge 2 ]]; then
 
            msg "Sorting package array!"
 
        fi
 
        msg_verbose2 "Sorting package array!"
 

	
 
        sorted_packages=($(sort <<<"${packages[*]}"))
 
        query_online_version sorted_packages[@]
 
    else
...
 
@@ -263,9 +277,7 @@ extract_and_remove () {
 

	
 
            tar xzf $1 -C $downloaddir
 

	
 
            if [[ $verbose -ge 1 ]]; then
 
                msg "Removing '$1'"
 
            fi
 
            msg_verbose1 "Removing '$1'"
 
            rm $1
 
        else
 
            error "'$1' is not a file"
0 comments (0 inline, 0 general)