From 6092b9d93df1c3d5170a2b6aa0275aebef18bd37 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 25 May 2017 14:39:05 -0400 Subject: start moving things to use the libremessages exit codes --- src/abslibre-tools/createworkdir | 4 ++-- src/abslibre-tools/diff-unfree | 6 +++--- src/abslibre-tools/libreaddiff | 6 +++--- src/abslibre-tools/libredbdiff | 12 ++++++------ src/abslibre-tools/librerelease | 6 +++--- src/abslibre-tools/librestage | 22 +++++++++++----------- src/chroot-tools/librechroot | 28 ++++++++++++++-------------- src/chroot-tools/libremakepkg | 16 ++++++++-------- src/dagpkg | 12 ++++++++---- src/gitget/gitget | 28 ++++++++++++++-------------- src/gitget/libregit | 4 ++-- src/is_built | 12 ++++++------ src/lib/blacklist.sh | 2 +- src/lib/conf.sh.in | 12 ++++++------ src/lib/libreblacklist | 4 ++-- src/lib/messages.sh | 2 +- src/librefetch/librefetch | 30 +++++++++++++++++------------- src/pkgbuild-check-nonfree | 2 +- src/pkgbuild-summarize-nonfree | 18 +++++++++--------- src/repo-diff | 4 ++-- src/toru/toru-path | 6 +++--- src/xbs-abs/helper-abs | 8 ++++---- src/xbs-abslibre/helper-abslibre | 6 +++--- src/xbs/xbs | 14 +++++++------- 24 files changed, 136 insertions(+), 128 deletions(-) diff --git a/src/abslibre-tools/createworkdir b/src/abslibre-tools/createworkdir index 6f58b05..aa1425d 100755 --- a/src/abslibre-tools/createworkdir +++ b/src/abslibre-tools/createworkdir @@ -4,7 +4,7 @@ # Copyright (C) 2010-2011 Nicolás Reynolds # Copyright (C) 2011 Joshua Ismael Haase Hernández (xihh) -# Copyright (C) 2013 Luke Shumaker +# Copyright (C) 2013, 2017 Luke Shumaker # # License: GNU GPLv3+ # @@ -46,7 +46,7 @@ main() { echo printf '%q ' "${cmd[@]}" echo - exit 1 + exit $EXIT_FAILURE fi msg "Finished, your packaging directory tree looks like this now:" diff --git a/src/abslibre-tools/diff-unfree b/src/abslibre-tools/diff-unfree index 860c985..29025e2 100755 --- a/src/abslibre-tools/diff-unfree +++ b/src/abslibre-tools/diff-unfree @@ -37,7 +37,7 @@ usage() { main() { if [[ "$1" == "--help" ]]; then usage - return 0 + return $EXIT_SUCCESS fi load_conf libretools.conf DIFFPROG || exit @@ -56,14 +56,14 @@ main() { if [[ ! -r PKGBUILD ]]; then error "This is not a build dir." - return 1 + exit $EXIT_FAILURE fi tmp_dir="$(mktemp --tmpdir -d "${package}.XXXXXX")" if [[ ! -d "${tmp_dir}" ]]; then error "Can't create temp dir" - return 1 + exit $EXIT_FAILURE fi unfree_dir="${tmp_dir}/${svnrepo}/${package}/${trunk}" diff --git a/src/abslibre-tools/libreaddiff b/src/abslibre-tools/libreaddiff index 9336198..c97ab7c 100755 --- a/src/abslibre-tools/libreaddiff +++ b/src/abslibre-tools/libreaddiff @@ -37,13 +37,13 @@ main() { while getopts 'h' arg; do case "$arg" in - h) usage; exit 0 ;; - *) usage >&2; exit 2 ;; + h) usage; exit $EXIT_SUCCESS ;; + *) usage >&2; exit $EXIT_INVALIDARGUMENT ;; esac done if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then usage >&2 - exit 2 + exit $EXIT_INVALIDARGUMENT fi # The repo to find missing packages in. diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff index 5d301f6..3fc505c 100755 --- a/src/abslibre-tools/libredbdiff +++ b/src/abslibre-tools/libredbdiff @@ -201,7 +201,7 @@ main() { ;; -h|--help) usage - return 0 + exit $EXIT_SUCCESS ;; --) break @@ -210,7 +210,7 @@ main() { done if $badargs; then usage >&2 - return 2 + exit $EXIT_INVALIDARGUMENT fi case $mode in @@ -218,7 +218,7 @@ main() { if [[ $# -gt 0 ]]; then print "%s: found non-flag arguments; a repo list may only be specified with the -n flag: %s" "$cmd" "$*" >&2 usage >&2 - return 2 + exit $EXIT_INVALIDARGUMENT fi main_update ;; @@ -226,7 +226,7 @@ main() { if [[ $# -gt 1 ]]; then print "%s: found too many non-flag arguments; only one repo may be specified: %s" "$cmd" "$*" >&2 usage >&2 - return 2 + exit $EXIT_INVALIDARGUMENT fi if [[ $# = 1 ]]; then if ! in_array "$1" "${repos[@]}"; then @@ -242,7 +242,7 @@ main_update() { if [[ $EUID != 0 ]]; then error "Must run as root to initialize or update %s databases." "$cmd" usage >&2 - exit 1 + exit $EXIT_NOPERMISSION fi load_conf libredbdiff.conf statedir mirror_prbl mirror_arch || exit @@ -305,7 +305,7 @@ main_compare() { then error "You must run %q with out arguments as root to initialize." "$cmd" usage >&2 - exit 1 + exit $EXIT_INVALIDARGUMENT fi local tmpdir diff --git a/src/abslibre-tools/librerelease b/src/abslibre-tools/librerelease index e673081..e6c180e 100755 --- a/src/abslibre-tools/librerelease +++ b/src/abslibre-tools/librerelease @@ -62,7 +62,7 @@ list0_files() { # This function is taken almost verbatim from makepkg create_signature() { - local ret=0 + local ret=$EXIT_SUCCESS local filename="$1" msg "Signing package..." @@ -71,7 +71,7 @@ create_signature() { SIGNWITHKEY=(-u "${GPGKEY}") fi # The signature will be generated directly in ascii-friendly format - gpg --detach-sign --use-agent "${SIGNWITHKEY[@]}" "$filename" || ret=$? + gpg --detach-sign --use-agent "${SIGNWITHKEY[@]}" "$filename" || ret=$EXIT_FAILURE if (( ! ret )); then @@ -100,7 +100,7 @@ sign_packages() { fi if ! [[ -f "${file}.sig" ]]; then - create_signature "$file" || return 2 + create_signature "$file" || return fi done } diff --git a/src/abslibre-tools/librestage b/src/abslibre-tools/librestage index 0794b13..f1f74cd 100755 --- a/src/abslibre-tools/librestage +++ b/src/abslibre-tools/librestage @@ -4,7 +4,7 @@ # Copyright (C) 2010-2012 Nicolás Reynolds # Copyright (C) 2011 Joshua Ismael Haase Hernández (xihh) -# Copyright (C) 2013-2014 Luke Shumaker +# Copyright (C) 2013-2014, 2017 Luke Shumaker # # License: GNU GPLv3+ # @@ -37,26 +37,26 @@ usage() { main() { if [[ -w / ]]; then error "This program should be run as a regular user" - return 1 + return $EXIT_NOPERMISSION fi # Parse options, set up while getopts 'h' arg; do case $arg in - h) usage; return 0;; - *) usage >&2; return 1;; + h) usage; return $EXIT_SUCCESS;; + *) usage >&2; return $EXIT_INVALIDARGUMENT;; esac done local repo= case $# in 0) repo="$(basename "$(dirname "$PWD")")";; 1) repo=$1;; - *) usage >&2; return 1;; + *) usage >&2; return $EXIT_INVALIDARGUMENT;; esac if ! [[ -e ./PKGBUILD ]]; then error "PKGBUILD not found" - return 1 + return $EXIT_FAILURE fi # Load configuration @@ -101,7 +101,7 @@ main() { staged=true else error "Can't put %s on [%s]" "$_pkgname" "$repo" - return 1 + return $EXIT_FAILURE fi done if pkgfile=$(find_cached_srcpackage "$pkgbase" "$(get_full_version)" "$CARCH"); then @@ -113,7 +113,7 @@ main() { staged=true else error "Can't put %s on [%s]" "$pkgbase" sources - return 1 + return $EXIT_FAILURE fi fi done @@ -147,7 +147,7 @@ main() { staged=true else error "Can't put %s on [%s]" "$srcname" other - return 1 + return $EXIT_FAILURE fi fi break @@ -156,10 +156,10 @@ main() { done if $staged ; then - return 0 + return $EXIT_SUCCESS else error "Nothing was staged" - return 1 + return $EXIT_FAILURE fi } diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index db4c87b..19ae9ce 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -83,7 +83,7 @@ hack_arch_nspawn_flags() { package. If you have it installed, but still see this message, you may need to restart %s.' \ binfmt-qemu-static systemd-binfmt.service - return 1 + return $EXIT_NOTINSTALLED fi # Let qemu/binfmt_misc do its thing @@ -302,7 +302,7 @@ main() { if ! [[ -f "/usr/share/pacman/defaults/pacman.conf.$OPTARG" && -f "/usr/share/pacman/defaults/makepkg.conf.$OPTARG" ]]; then error 'Unsupported architecture: %s' "$OPTARG" plain 'See the files in %q for valid architectures.' /usr/share/pacman/defaults/ - return 1; + return $EXIT_INVALIDARGUMENT; fi trap 'rm -f -- "$tmppacmanconf"' EXIT tmppacmanconf="$(mktemp --tmpdir librechroot-pacman.conf.XXXXXXXXXX)" @@ -313,20 +313,20 @@ main() { );; w) sysd_nspawn_flags+=("--bind=$OPTARG");; r) sysd_nspawn_flags+=("--bind-ro=$OPTARG");; - *) usage >&2; return 1;; + *) usage >&2; return $EXIT_INVALIDARGUMENT;; esac done shift $((OPTIND - 1)) if [[ $# -lt 1 ]]; then error "Must specify a command" usage >&2 - return 1 + return $EXIT_INVALIDARGUMENT fi mode=$1 if ! in_array "$mode" "${commands[@]}"; then error "Unrecognized command: %s" "$mode" usage >&2 - return 1 + return $EXIT_INVALIDARGUMENT fi shift case "$mode" in @@ -334,14 +334,14 @@ main() { if [[ $# -gt 0 ]]; then error 'Command `%s` does not take any arguments: %s' "$mode" "$*" usage >&2 - return 1 + return $EXIT_INVALIDARGUMENT fi :;; install-file) if [[ $# -lt 1 ]]; then error 'Command `%s` requires at least one file' "$mode" usage >&2 - return 1 + return $EXIT_INVALIDARGUMENT else local missing=() local file @@ -352,7 +352,7 @@ main() { done if [[ ${#missing[@]} -gt 0 ]]; then error "%s: file(s) not found: %s" "$mode" "${missing[*]}" - return 1 + return $EXIT_INVALIDARGUMENT fi fi :;; @@ -360,14 +360,14 @@ main() { if [[ $# -lt 1 ]]; then error 'Command `%s` requires at least one package name' "$mode" usage >&2 - return 1 + return $EXIT_INVALIDARGUMENT fi :;; run) if [[ $# -lt 1 ]]; then error 'Command `%s` requires at least one argument' "$mode" usage >&2 - return 1 + return $EXIT_INVALIDARGUMENT fi :;; esac @@ -375,7 +375,7 @@ main() { if [[ $mode == help ]]; then usage - return 0 + return $EXIT_SUCCESS fi load_conf chroot.conf CHROOTDIR CHROOT @@ -390,7 +390,7 @@ main() { if (( EUID )); then error "This program must be run as root." - return 1 + return $EXIT_NOPERMISSION fi umask 0022 @@ -402,7 +402,7 @@ main() { plain "https://bugs.freedesktop.org/show_bug.cgi?id=70290" prose "Due to a bug in systemd-nspawn, redirecting stdin is not supported." >&2 - return 1 + return $EXIT_FAILURE fi # Keep this lock for as long as we are running @@ -413,7 +413,7 @@ main() { if [[ $mode != delete ]]; then if ! check_mountpoint "$copydir.lock"; then error "Chroot copy is mounted with nosuid or noexec options: [%s]" "$COPY" - return 1 + return $EXIT_FAILURE fi if [[ ! -d $rootdir ]]; then diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index 02b31a8..841f533 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -83,9 +83,9 @@ run_hook() { if [[ ${#fails[@]} -gt 0 ]]; then error "Failure(s) in %s: %s" "$hookname" "${fails[*]}" - return 1 + return $EXIT_FAILURE else - return 0 + return $EXIT_SUCCESS fi } @@ -176,7 +176,7 @@ usage() { err_chflag() { local flag=$1 error 'The -%s flag does not make sense inside of a chroot' "$flag" - return 1 + exit $EXIT_INVALIDARGUMENT } main() { @@ -197,14 +197,14 @@ main() { librechroot_flags+=(-$flag "$OPTARG"); fi;; N) NONET=false;; R) repack=true; makepkg_args+=(-R);; - h) usage; return 0;; - *) usage >&2; return 1;; + h) usage; exit $EXIT_SUCCESS;; + *) usage >&2; exit $EXIT_INVALIDARGUMENT;; esac done shift $((OPTIND - 1)) if [[ $# != 0 ]]; then error 'Extra arguments: %s' "$*" - return 1 + exit $EXIT_INVALIDARGUMENT fi # Resolve the chroot path ############################################## @@ -236,13 +236,13 @@ main() { if (( EUID )); then error "This program must be run as root" - exit 1 + exit $EXIT_NOPERMISSION fi if [[ ! -f PKGBUILD ]]; then # This is the message used by makepkg error "PKGBUILD does not exist." - exit 1 + exit $EXIT_FAILURE fi # Make sure that the various *DEST directories exist diff --git a/src/dagpkg b/src/dagpkg index f205390..187fab3 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -54,7 +54,7 @@ source_pkgbuild() { # Source this PKGBUILD, if it doesn't exist, exit if ! load_PKGBUILD &>/dev/null; then error "No PKGBUILD in %s" "$PWD" - exit 1 + exit $EXIT_FAILURE fi # Save resources @@ -89,9 +89,13 @@ visit_pkgbuild() { # Detect cycle or already visited package case "${marks[$name]:-0}" in - 1) msg2 "cycle found with %s depending on %s" "$prev" "$name" - exit 1;; - 2) return;; + 1) + msg2 "cycle found with %s depending on %s" "$prev" "$name" + exit $EXIT_FAILURE + ;; + 2) + return + ;; esac msg "%s (%s)" "${name}" "${prev}" diff --git a/src/gitget/gitget b/src/gitget/gitget index 6a4b9d1..5e0c125 100755 --- a/src/gitget/gitget +++ b/src/gitget/gitget @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Copyright (C) 2012-2013 Pacman Development Team -# Copyright (C) 2012-2013 Luke Shumaker +# Copyright (C) 2012-2013, 2017 Luke Shumaker # # License: GNU GPLv2+ # @@ -34,7 +34,7 @@ cd_safe() { if ! cd "$1"; then error "Failed to change to directory %s" "$1" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi } @@ -51,7 +51,7 @@ download_git_checkout() { if ! git clone "$url" "$dir"; then error "Failure while downloading %s %s repo" "${name}" "git" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi cd_safe "$dir" if [[ -n $push ]]; then @@ -67,7 +67,7 @@ download_git_checkout() { else error "%s is not a clone of %s" "$dir" "$url" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi fi if [[ -n $push ]] ; then @@ -78,11 +78,11 @@ download_git_checkout() { if ! curpush="$(git config --get remote.origin.pushUrl)"; then error "%s does not have a %s configured" pushUrl "$name" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE elif [[ $curpush != "$push" ]]; then error "%s has %s configured, but it doesn't match %s" "$name" pushUrl "$push" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi fi fi @@ -106,7 +106,7 @@ download_git_bare() { if ! git clone --mirror "$url" "$dir"; then error "Failure while downloading %s %s repo" "${name}" "git" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi if [[ -n $push ]]; then cd_safe "$dir" @@ -121,7 +121,7 @@ download_git_bare() { else error "%s is not a clone of %s" "$dir" "$url" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi fi if [[ -n $push ]] ; then @@ -132,11 +132,11 @@ download_git_bare() { if ! curpush="$(git config --get remote.origin.pushUrl)"; then error "%s does not have a %s configured" pushUrl "$name" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE elif [[ $curpush != "$push" ]]; then error "%s has %s configured, but it doesn't match %s" "$name" pushUrl "$push" plain "Aborting..." - exit 1 + exit $EXIT_FAILURE fi fi fi @@ -192,12 +192,12 @@ main() { f) FORCE=true;; p) push=$OPTARG;; n) name=$OPTARG;; - h) usage; return 0;; - *) usage >&2; return 1;; + h) usage; exit $EXIT_SUCCESS;; + *) usage >&2; exit $EXIT_INVALIDARGUMENT;; esac done shift $((OPTIND - 1)) - [[ $# == 3 ]] || { usage >&2; return 1; } + [[ $# == 3 ]] || { usage >&2; exit $EXIT_INVALIDARGUMENT; } local mode=$1 local url=${2#git+} local dir=$3 @@ -218,7 +218,7 @@ main() { case "$mode" in checkout) download_git_checkout "$urlmain" "$ref" "$dir" "$name" "$push";; bare) download_git_bare "$urlmain" "$dir" "$name" "$push";; - *) usage >&2; return 1;; + *) usage >&2; exit $EXIT_INVALIDARGUMENT;; esac } diff --git a/src/gitget/libregit b/src/gitget/libregit index 6c49af5..5b7e799 100755 --- a/src/gitget/libregit +++ b/src/gitget/libregit @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (C) 2012-2013 Luke Shumaker +# Copyright (C) 2012-2013, 2017 Luke Shumaker # # License: GNU GPLv2+ # @@ -32,7 +32,7 @@ usage() { } main() { - [[ $# == 3 ]] || { usage >&2; return 1; } + [[ $# == 3 ]] || { usage >&2; exit $EXIT_INVALIDARGUMENT; } repo=$1 ref=$2 dir=$3 diff --git a/src/is_built b/src/is_built index 22c67a7..3fb09b6 100755 --- a/src/is_built +++ b/src/is_built @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Copyright (C) 2011-2012 Nicolás Reynolds # Copyright (C) 2011-2012 Joshua Ismael Haase Hernández (xihh) -# Copyright (C) 2013 Luke Shumaker +# Copyright (C) 2013, 2017 Luke Shumaker # # License: GNU GPLv3+ # @@ -41,13 +41,13 @@ usage() { main() { while getopts 'h' arg; do case $arg in - h) usage; exit 0 ;; - *) usage >&2; exit 2 ;; + h) usage; exit $EXIT_SUCCESS ;; + *) usage >&2; exit $EXIT_INVALIDARGUMENT ;; esac done if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then usage >&2 - exit 2 + exit $EXIT_INVALIDARGUMENT fi pkg=${1} @@ -63,9 +63,9 @@ main() { # 1 : pver > ver if [[ $result -ge 0 ]] && [[ $r -eq 0 ]]; then - exit 0 + exit $EXIT_TRUE else - exit 1 + exit $EXIT_FALSE fi } diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh index fc07815..249ee89 100644 --- a/src/lib/blacklist.sh +++ b/src/lib/blacklist.sh @@ -61,7 +61,7 @@ blacklist-update() ( _l warning "Using local copy of blacklist" else _l error "Download failed, exiting" - return 1 + return 1 # $EXIT_FAILURE fi fi diff --git a/src/lib/conf.sh.in b/src/lib/conf.sh.in index 7d1646b..f2d515d 100644 --- a/src/lib/conf.sh.in +++ b/src/lib/conf.sh.in @@ -109,7 +109,7 @@ list_envvars() { # Loads the configuration files for $slug in the proper order, and # optionally verify that certain variables are set. load_conf() { - [[ "$1" = *.conf ]] || libremessages panic || exit 1 + [[ "$1" = *.conf ]] || libremessages panic || exit 1 # $EXIT_FAILURE local slug=${1%.conf} shift @@ -123,7 +123,7 @@ load_conf() { # Load the files while read -r file; do if [[ -r $file ]]; then - . "$file" || return 6 + . "$file" || return 6 # $EXIT_NOTCONFIGURED fi done < <(list_files "$slug") @@ -133,7 +133,7 @@ load_conf() { done < <(list_envvars "$slug") # Verify that the variables we need were set - declare -i ret=0 + declare -i ret=0 # $EXIT_SUCCESS for var in "$@"; do if [[ -z ${!var:-} ]]; then if [[ $(list_files "$slug"|wc -l) -gt 1 ]]; then @@ -142,7 +142,7 @@ load_conf() { else libremessages _l print "Configure '%s' in '%s'" "$var" "$(list_files "$slug")" fi - ret=6 + ret=6 # $EXIT_NOTCONFIGURED fi done >&2 return $ret @@ -170,10 +170,10 @@ set_var() { if [[ -w $file ]]; then sed -i "/^\s*$key=/d" "$file" printf '%s=%q\n' "$key" "$val" >> "$file" - return 0 + return 0 # $EXIT_SUCCESS fi done < <(list_files "$slug"|tac) - return 1 + return 1 # $EXIT_FAILURE } # PKGBUILD (not configuration, per se) ######################################### diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist index 6c354fe..d6fc7f3 100755 --- a/src/lib/libreblacklist +++ b/src/lib/libreblacklist @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (C) 2013-2014, 2016 Luke Shumaker +# Copyright (C) 2013-2014, 2016-2017 Luke Shumaker # # License: GNU GPLv2+ # @@ -68,7 +68,7 @@ else main() { if [[ $# -eq 0 ]]; then usage >&2 - exit 1 + exit $EXIT_INVALIDARGUMENT fi _blacklist_cmd=$1 shift diff --git a/src/lib/messages.sh b/src/lib/messages.sh index d989469..37ee1b8 100644 --- a/src/lib/messages.sh +++ b/src/lib/messages.sh @@ -58,7 +58,7 @@ declare -rgi EXIT_NOTCONFIGURED=6 # For programming errors, bails immediately with little fanfare. panic() { _l _ 'panic: malformed call to internal function' >&2 - exit 1 + exit $EXIT_FAILURE } # Usage: print MESG [ARGS...] diff --git a/src/librefetch/librefetch b/src/librefetch/librefetch index 58a98b9..1e2c450 100755 --- a/src/librefetch/librefetch +++ b/src/librefetch/librefetch @@ -99,7 +99,7 @@ main() { mode=download-create if ! parse_options "$@"; then usage >&2 - exit 1 + exit $EXIT_INVALIDARGUMENT fi doit @@ -110,7 +110,7 @@ doit() { if [[ $mode =~ help ]]; then usage - exit 0 + exit $EXIT_SUCCESS fi ######################################################################## @@ -121,7 +121,7 @@ doit() { if [[ $mode =~ makepkg ]]; then printf '%s\n' "$makepkg" - exit 0 + exit $EXIT_SUCCESS else tmpdirs+=("${makepkg%/*}") fi @@ -134,7 +134,7 @@ doit() { fi if [[ ! -f "$BUILDFILE" ]]; then error "%s does not exist." "$BUILDFILE" - exit 1 + exit $EXIT_FAILURE fi case "$BUILDFILE" in */SRCBUILD) srcbuild="$(modified_srcbuild "$BUILDFILE")";; @@ -150,14 +150,14 @@ doit() { PKGBUILD) sed -e 's/^[a-z]/mk&/' -e 's/^\s/ &/';; SRCBUILD) cat;; esac - exit 0 + exit $EXIT_SUCCESS fi # Mode: srcbuild ####################################################### if [[ $mode =~ srcbuild ]]; then cat "$srcbuild" - exit 0 + exit $EXIT_SUCCESS fi ######################################################################## @@ -200,7 +200,11 @@ doit() { dlcmd="${dlcmd//\%o/\"\$dst\"}" dlcmd="${dlcmd//\%u/\"\$src\"}" - { eval "$dlcmd"; } >&2 && exit 0 + if { eval "$dlcmd"; } >&2; then + exit $EXIT_SUCCESS + else + exit $EXIT_FAILURE + fi fi # Mode: create ######################################################### @@ -231,7 +235,7 @@ doit() { # sets the variables BUILDFILE, makepkg_opts, extra_opts, mode parse_options() { - declare -i ret=0 + declare -i ret=$EXIT_SUCCESS local {shrt,long}{1,2} # makepkg options @@ -252,7 +256,7 @@ parse_options() { local shrt long args shrt="$({ printf '%s\0' "${shrt1[@]}"; printf '%s:\0' "${shrt2[@]}"; } | sort -zu | xargs -0 printf '%s')" long="$({ printf '%s\0' "${long1[@]}"; printf '%s:\0' "${long2[@]}"; } | sort -zu | xargs -0 printf '%s,')" - args="$(getopt -n "$cmd" -o "$shrt" -l "${long%,}" -- "$@")" || ret=$? + args="$(getopt -n "$cmd" -o "$shrt" -l "${long%,}" -- "$@")" || ret=$EXIT_INVALIDARGUMENT eval "set -- $args" unset shrt long args @@ -293,13 +297,13 @@ parse_options() { checksums|srcbuild|makepkg) # don't take any extra arguments if [[ ${#extra_opts[@]} != 0 ]]; then print "%s: found extra non-flag arguments: %s" "$cmd" "${extra_opts[*]}" >&2 - ret=1 + ret=$EXIT_INVALIDARGUMENT fi ;; *download*|*create*) # take 1 or 2 extra arguments if [[ ${#extra_opts[@]} != 1 ]] && [[ ${#extra_opts[@]} != 2 ]]; then print "%s: %d non-flag arguments found, expected 1 or 2: %s" "$cmd" ${#extra_opts[@]} >&2 - ret=1 + ret=$EXIT_INVALIDARGUMENT fi ;; esac @@ -380,7 +384,7 @@ modified_srcbuild() { # This function is taken almost verbatim from makepkg create_signature() { - local ret=0 + local ret=$EXIT_SUCCESS local filename="$1" msg "Signing package..." @@ -389,7 +393,7 @@ create_signature() { SIGNWITHKEY=(-u "${GPGKEY}") fi - gpg --detach-sign --use-agent "${SIGNWITHKEY[@]}" --no-armor "$filename" &>/dev/null || ret=$? + gpg --detach-sign --use-agent "${SIGNWITHKEY[@]}" --no-armor "$filename" &>/dev/null || ret=$EXIT_FAILURE if (( ! ret )); then diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree index 59ec7c9..2580c1c 100755 --- a/src/pkgbuild-check-nonfree +++ b/src/pkgbuild-check-nonfree @@ -91,7 +91,7 @@ main() { # Do a check to see if we are running as root if [[ -w / ]] && ! $asroot; then error "Run as normal user, or use the -f option to run as root." - return 1 + return $_E_ERROR fi # Adjust the verbosity diff --git a/src/pkgbuild-summarize-nonfree b/src/pkgbuild-summarize-nonfree index cf9277e..b036dd5 100755 --- a/src/pkgbuild-summarize-nonfree +++ b/src/pkgbuild-summarize-nonfree @@ -46,19 +46,19 @@ main() { while getopts 'qh' arg; do case "$arg" in q) quiet=true;; - h) usage; return 0;; - *) usage >&2; return 1;; + h) usage; exit $EXIT_SUCCESS;; + *) usage >&2; exit $EXIT_INVALIDARGUMENT;; esac done shift $((OPTIND - 1)) if [[ $# -ne 1 ]]; then usage >&2 - return 1 + exit $EXIT_INVALIDARGUMENT fi if ! [[ $1 =~ ^[0-9]+$ ]]; then error 'STATUS must be an integer' usage >&2 - return 1 + exit $EXIT_INVALIDARGUMENT fi if $quiet; then @@ -73,7 +73,7 @@ parse() { [[ $# == 1 ]] || panic 'malformed call to parse' declare -i s=$1; - declare -i ret=0 + declare -i ret=$EXIT_SUCCESS declare -i i for i in 1 2 4 8 16 32; do if [[ $((s & i)) -gt 0 ]]; then @@ -81,20 +81,20 @@ parse() { $_E_ERROR) # could be anything, assume the worst error "There was an error processing the PKGBUILD" - ret=1;; + ret=$EXIT_FAILURE;; $_E_LIC_UNKNOWN) warning "This PKGBUILD has an unknown license";; $_E_LIC_NOGPL) warning "This PKGBUILD has a GPL-incompatible license";; $_E_LIC_NONFREE) error "This PKGBUILD has a known nonfree license" - ret=1;; + ret=$EXIT_FAILURE;; $_E_DEP_NONFREE) error "This PKGBUILD depends on known nonfree packages" - ret=1;; + ret=$EXIT_FAILURE;; $_E_PKG_NONFREE) error "This PKGBUILD is for a known nonfree package" - ret=1;; + ret=$EXIT_FAILURE;; esac fi done diff --git a/src/repo-diff b/src/repo-diff index df5e49b..76e2d87 100755 --- a/src/repo-diff +++ b/src/repo-diff @@ -51,7 +51,7 @@ g() { main() { if test $# -eq 0; then usage - return 0 + exit $EXIT_SUCCESS fi local tmpdir; tmpdir="$(mktemp -d -t "${0##*/}.XXXXXXXXXX")" @@ -61,7 +61,7 @@ main() { for i in $1 $2; do n=$(n "$i") - test -z "$n" && exit 1 + [[ -n "$n" ]] || exit $EXIT_FAILURE wget -O "$n" -nv "$(g "$i")" b "$n" > "${n}.orig" diff --git a/src/toru/toru-path b/src/toru/toru-path index 611a857..494d0ae 100755 --- a/src/toru/toru-path +++ b/src/toru/toru-path @@ -61,10 +61,10 @@ main() { if [[ $# != 0 ]]; then if [[ $# == 1 && "$1" == '-h' ]]; then usage - return 0 + return $EXIT_SUCCESS fi usage >&2 - return 2 + return $EXIT_INVALIDARGUMENT fi declare -i ret=0 @@ -79,7 +79,7 @@ main() { if [ ! -w "$TORUPATH" ]; then error "Toru's path isn't writable. Please check your TORUPATH: %q" "$TORUPATH" - exit 1 + exit $EXIT_NOPERMISSION fi local lastsyncfile=${TORUPATH}/lastsync.paths diff --git a/src/xbs-abs/helper-abs b/src/xbs-abs/helper-abs index 6c9ee56..e50b9a6 100755 --- a/src/xbs-abs/helper-abs +++ b/src/xbs-abs/helper-abs @@ -59,10 +59,10 @@ pac2svn() { if in_array "$pacrepo" "${pacrepos[@]}"; then echo "$svnrepo" - return 0 + return 0 # $EXIT_SUCCESS fi done - return 1 + return 1 # $EXIT_FAILURE } status() { @@ -188,9 +188,9 @@ releasepath() { releasepath="${svndir}/repos/${repo}-${arch}" if [[ -f "${releasepath}/PKGBUILD" ]]; then printf '%s\n' "$releasepath" - return 0 + return 0 # $EXIT_SUCCESS fi - return 1 + return 1 # $EXIT_FAILURE } name() { diff --git a/src/xbs-abslibre/helper-abslibre b/src/xbs-abslibre/helper-abslibre index 7ebed0a..78d36b0 100755 --- a/src/xbs-abslibre/helper-abslibre +++ b/src/xbs-abslibre/helper-abslibre @@ -34,7 +34,7 @@ unlockarch() { checkgit() { if [[ ! -d "${ABSLIBREDEST}/${arch}/.git" ]]; then error 'Not a git repository: %s' "${ABSLIBREDEST}/${arch}" - exit 1 + exit $EXIT_FAILURE fi } @@ -187,10 +187,10 @@ releasepath() { if [[ -f "${pkgdir}/PKGBUILD" ]]; then printf '%s\n' "$pkgdir" - return 0 + return $EXIT_SUCCESS fi - return 1 + return $EXIT_FAILURE } name() { diff --git a/src/xbs/xbs b/src/xbs/xbs index 12c5770..7b82142 100755 --- a/src/xbs/xbs +++ b/src/xbs/xbs @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (C) 2013-2015 Luke Shumaker +# Copyright (C) 2013-2015, 2017 Luke Shumaker # # License: GNU GPLv2+ # @@ -27,7 +27,7 @@ errusage() { error "$@" fi usage >&2 - exit 1 + exit $EXIT_INVALIDARGUMENT } usage() { @@ -83,7 +83,7 @@ status() { # this case it does: Using "exit" instead of "return" # is imporant because it prevents flow returning to # release-client. - exit 1 + exit $EXIT_FAILURE fi "$HELPER" status "$@" } @@ -95,7 +95,7 @@ download() { release-client() { if ! status; then error 'You have not committed your changes yet!' - exit 1 + exit $EXIT_FAILURE fi "$HELPER" release-client "$@" } @@ -103,7 +103,7 @@ release-client() { release-server() { if [[ ! -f PKGBUILD ]]; then error 'PKGBUILD not found' - exit 1 + exit $EXIT_FAILURE fi "$HELPER" release-server "$@" } @@ -133,7 +133,7 @@ main() { while getopts 'b:h' arg; do case $arg in b) BUILDSYSTEM=$OPTARG;; - h) usage; return 0;; + h) usage; return $EXIT_SUCCESS;; *) errusage;; esac done @@ -150,7 +150,7 @@ main() { HELPER="${XBS_LIBDIR}/helper-${BUILDSYSTEM}" if [[ ! -x "$HELPER" ]]; then error 'No helper for build system found: %s' "$BUILDSYSTEM" - return 1; + return $EXIT_NOTCONFIGURED; fi if [[ $# -lt 1 ]]; then -- cgit v1.2.2