summaryrefslogtreecommitdiff
path: root/src/librefetch/librefetch
diff options
context:
space:
mode:
Diffstat (limited to 'src/librefetch/librefetch')
-rwxr-xr-xsrc/librefetch/librefetch93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/librefetch/librefetch b/src/librefetch/librefetch
index 0a1bb70..a69ddea 100755
--- a/src/librefetch/librefetch
+++ b/src/librefetch/librefetch
@@ -72,25 +72,25 @@ usage() {
prose "The default build script is 'PKGBUILD', or 'SRCBUILD' if it
exists."
echo
- prose "Other options, if they are valid \`makepkg\` options, are passed
- straight to makepkg."
+ prose 'Other options, if they are valid `makepkg` options, are passed
+ straight to makepkg.'
echo
print "Example usage:"
print ' $ %s https://repo.parabola.nu/other/mypackage/mypackage-1.0.tar.gz' "$cmd"
echo
print "Options:"
flag 'Settings:' \
- "-C" "Force create mode (don't download)" \
- "-D" "Force download mode (don't create)" \
- "-p <$(_ FILE)>" "Use an alternate build script (instead of
+ "-C" "Force create mode (don't download)" \
+ "-D" "Force download mode (don't create)" \
+ "-p <$(_ FILE)>" "Use an alternate build script (instead of
'PKGBUILD'). If an SRCBUILD exists in the same
directory, it is used instead" \
- 'Alternate modes:' \
- "-g, --geninteg" "Generate integrity checks for source files" \
- "-S, --srcbuild" "Print the effective build script (SRCBUILD)" \
- "-M, --makepkg" "Generate and print the location of the
+ 'Alternate modes:' \
+ "-g, --geninteg" "Generate integrity checks for source files" \
+ "-S, --srcbuild" "Print the effective build script (SRCBUILD)" \
+ "-M, --makepkg" "Generate and print the location of the
effective makepkg script" \
- "-h, --help" "Show this message"
+ "-h, --help" "Show this message"
}
main() {
@@ -133,13 +133,13 @@ doit() {
if [[ -f "${BUILDFILEDIR}/SRCBUILD" ]]; then
BUILDFILE="${BUILDFILEDIR}/SRCBUILD"
fi
- if [[ ! -f "$BUILDFILE" ]]; then
+ if [[ ! -f $BUILDFILE ]]; then
error "%s does not exist." "$BUILDFILE"
exit $EXIT_FAILURE
fi
case "$BUILDFILE" in
- */SRCBUILD) srcbuild="$(modified_srcbuild "$BUILDFILE")";;
- *) srcbuild="$(modified_pkgbuild "$BUILDFILE")";;
+ */SRCBUILD) srcbuild="$(modified_srcbuild "$BUILDFILE")" ;;
+ *) srcbuild="$(modified_pkgbuild "$BUILDFILE")" ;;
esac
tmpfiles+=("$srcbuild")
@@ -147,10 +147,10 @@ doit() {
if [[ $mode =~ checksums ]]; then
"$makepkg" "${makepkg_opts[@]}" -g -p "$srcbuild" |
- case ${BUILDFILE##*/} in
- PKGBUILD) sed -e 's/^[a-z]/mk&/' -e 's/^\s/ &/';;
- SRCBUILD) cat;;
- esac
+ case ${BUILDFILE##*/} in
+ PKGBUILD) sed -e 's/^[a-z]/mk&/' -e 's/^\s/ &/' ;;
+ SRCBUILD) cat ;;
+ esac
exit $EXIT_SUCCESS
fi
@@ -178,15 +178,15 @@ doit() {
load_conf librefetch.conf MIRRORS DOWNLOADER || exit
# Canonicalize $src
- if [[ "$src" == libre://* ]]; then
+ if [[ $src == libre://* ]]; then
src="${MIRRORS[0]}/${src#libre://}"
fi
# check to see if $src is a candidate for create mode
- local inmirror=false;
+ local inmirror=false
local mirror
for mirror in "${MIRRORS[@]}"; do
- if [[ "$src" == "$mirror"* ]]; then
+ if [[ $src == "$mirror"* ]]; then
inmirror=true
break
fi
@@ -197,7 +197,7 @@ doit() {
fi
local dlcmd="${DOWNLOADER}"
- [[ $dlcmd = *%u* ]] || dlcmd="$dlcmd %u"
+ [[ $dlcmd == *%u* ]] || dlcmd="$dlcmd %u"
dlcmd="${dlcmd//\%o/\"\$dst\"}"
dlcmd="${dlcmd//\%u/\"\$src\"}"
@@ -253,8 +253,14 @@ parse_options() {
# Feed the options through getopt (sanitize them)
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,')"
+ 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=$EXIT_INVALIDARGUMENT
eval "set -- $args"
unset shrt long args
@@ -262,25 +268,26 @@ parse_options() {
# Parse the options.
local opt optarg have_optarg
while [[ $# -gt 0 ]]; do
- opt=$1; shift
+ opt=$1
+ shift
have_optarg=false
- if { [[ $opt == --?* ]] && in_array "${opt#--}" "${long2[@]}"; } \
- || { [[ $opt == -? ]] && in_array "${opt#-}" "${shrt2[@]}"; }
- then
- optarg=$1; shift
+ if { [[ $opt == --?* ]] && in_array "${opt#--}" "${long2[@]}"; } ||
+ { [[ $opt == -? ]] && in_array "${opt#-}" "${shrt2[@]}"; }; then
+ optarg=$1
+ shift
have_optarg=true
fi
case "$opt" in
- -C) mode=create;;
- -D) mode=download;;
- -g|--geninteg) mode=checksums;;
- -S|--srcbuild) mode=srcbuild;;
- -M|--makepkg) mode=makepkg;;
- -p) BUILDFILE="$(realpath -Lm -- "$optarg")";;
- -h|--help) mode=help;;
- --) break;;
+ -C) mode=create ;;
+ -D) mode=download ;;
+ -g | --geninteg) mode=checksums ;;
+ -S | --srcbuild) mode=srcbuild ;;
+ -M | --makepkg) mode=makepkg ;;
+ -p) BUILDFILE="$(realpath -Lm -- "$optarg")" ;;
+ -h | --help) mode=help ;;
+ --) break ;;
*)
makepkg_opts+=("$opt")
if $have_optarg; then makepkg_opts+=("$optarg"); fi
@@ -292,14 +299,14 @@ parse_options() {
# check the number of extra_opts
case "$mode" in
help) # don't worry about it
- :;;
- checksums|srcbuild|makepkg) # don't take any extra arguments
+ : ;;
+ 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=$EXIT_INVALIDARGUMENT
fi
;;
- *download*|*create*) # take 1 or 2 extra arguments
+ *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=$EXIT_INVALIDARGUMENT
@@ -368,18 +375,17 @@ modified_pkgbuild() {
local pkgbuild=$1
local srcbuild
srcbuild="$(mktemp "${pkgbuild%/*}/${cmd}.XXXXXXXXXXX.PKGBUILD.to.SRCBUILD")"
- printf '%s' "$pkgbuild_append" | cat "$pkgbuild" - > "$srcbuild"
+ printf '%s' "$pkgbuild_append" | cat "$pkgbuild" - >"$srcbuild"
printf '%s\n' "$srcbuild"
}
-
# Modify SRCBUILD ##############################################################
modified_srcbuild() {
local orig=$1
local new
new="$(mktemp "${orig%/*}/${cmd}.XXXXXXXXXXX.SRCBUILD.to.SRCBUILD")"
- sed -e '/PKGDEST=/d' -e '/PKGEXT=/d' < "$orig" > "$new"
+ sed -e '/PKGDEST=/d' -e '/PKGEXT=/d' <"$orig" >"$new"
printf '%s\n' "$new"
}
@@ -398,8 +404,7 @@ create_signature() {
gpg --detach-sign --use-agent "${SIGNWITHKEY[@]}" --no-armor "$filename" &>/dev/null || ret=$EXIT_FAILURE
-
- if (( ! ret )); then
+ if ((!ret)); then
msg2 "Created signature file %s." "$filename.sig"
else
error "Failed to sign package file."