summaryrefslogtreecommitdiff
path: root/src/librefetch
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-05-25 14:39:05 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-05-25 17:28:30 -0400
commit6092b9d93df1c3d5170a2b6aa0275aebef18bd37 (patch)
tree55627e026fa7f538f8085f0fb8ed1fffcce4fcbc /src/librefetch
parentaedbebb0ea3c7b40dda987b43ff21475ef67f423 (diff)
start moving things to use the libremessages exit codes
Diffstat (limited to 'src/librefetch')
-rwxr-xr-xsrc/librefetch/librefetch30
1 files changed, 17 insertions, 13 deletions
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