summaryrefslogtreecommitdiff
path: root/src/librefetch
diff options
context:
space:
mode:
Diffstat (limited to 'src/librefetch')
-rwxr-xr-xsrc/librefetch/librefetch212
-rw-r--r--src/librefetch/librefetch.8.ronn55
-rw-r--r--src/librefetch/librefetch.conf5
-rw-r--r--src/librefetch/librefetch.conf.5.ronn16
4 files changed, 179 insertions, 109 deletions
diff --git a/src/librefetch/librefetch b/src/librefetch/librefetch
index 086a5e9..82c8703 100755
--- a/src/librefetch/librefetch
+++ b/src/librefetch/librefetch
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# librefetch
-#
-# Copyright 2013 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# Copyright (C) 2013-2014 Luke Shumaker <lukeshu@sbcglobal.net>
#
# This file is part of Parabola.
#
@@ -18,60 +18,58 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-. $(librelib conf.sh)
-. libremessages
+. $(librelib conf)
+. $(librelib messages)
+setup_traps
declare -r tempdir="$(mktemp -d --tmpdir ${0##*/}.XXXXXXXXXXX)"
-cleanup() { rm -rf -- "$tempdir"; }
-trap cleanup EXIT
+trap "rm -rf -- $(printf '%q' "$tempdir")" EXIT
cmd=${0##*/}
usage() {
- print "Usage: %s [options] <source-url> [<output-file>]" "$cmd"
- print "Usage: %s -[g|P|V|h]" "$cmd"
+ print "Usage: %s [OPTIONS] SOURCE_URL [OUTPUT_FILE]" "$cmd"
+ print "Usage: %s -[g|P|h]" "$cmd"
print "Downloads or creates a liberated source tarball."
echo
- print "The default mode is to create <output-file>, first by trying download"
- print "mode, then create mode."
+ prose "The default mode is to create OUTPUT_FILE, first by trying
+ download mode, then create mode."
+ echo
+ prose "If OUTPUT_FILE isn't specified, it defaults to the non-directory
+ part of SOURCE_URL, in the current directory."
echo
- print "If <output-file> isn't specified, it defaults to the non-directory"
- print "part of <source-url>, in the current directory."
+ prose "Unless '-C' is specified, if SOURCE_URL does not begin with a
+ configured mirror, create mode is inhibited."
echo
- print "In download mode, the glob '*://' is stripped from the beginning of"
- print "<source-url>, and the resulting path is attempted to be downloaded"
- print "from the configured mirror."
+ prose "In download mode, it simply tries to download SOURCE_URL. At the
+ beginning of a URL, 'libre://' expands to the first configured
+ mirror."
echo
- print "In create mode, it looks at a build script, and uses that to create"
- print "the source tarball. <source-url> is ignored, except that it is used"
- print "to set the default value of <output-file>."
+ prose "In create mode, it looks at a build script, and uses that to
+ create the source tarball. SOURCE_URL is ignored, except that it
+ is used to set the default value of OUTPUT_FILE."
echo
- print "The default build script is 'PKGBUILD', or 'SRCBUILD' if it exists."
+ prose "The default build script is 'PKGBUILD', or 'SRCBUILD' if it
+ exists."
echo
- print "Unrecognized options are passed straight to makepkg."
+ prose "Unrecognized options are passed straight to makepkg."
+ echo
+ prose "%s does NOT support getopt-style flag combining. You must use
+ '-a -b', not '-ab'." "$cmd"
echo
print "Example usage:"
- print ' $ %s libre://mypackage-1.0.tar.gz' "$cmd"
+ print ' $ %s https://repo.parabolagnulinux.org/other/mypackage/mypackage-1.0.tar.gz' "$cmd"
echo
print "Options:"
print " Settings:"
- print " -C Force create mode (don't download)"
- print " -D Force download mode (don't create)"
- print " -p <file> Use an alternate build script (instead of 'PKGBUILD')"
- print " If an SRCBUILD exists in the same directory, it is used"
- print " instead"
+ flag "-C" "Force create mode (don't download)"
+ flag "-D" "Force download mode (don't create)"
+ flag "-p <$(_ FILE)>" "Use an alternate build script (instead of
+ 'PKGBUILD') If an SRCBUILD exists in the same
+ directory, it is used instead"
print " Alternate modes:"
- print " -g, --geninteg Generage integrity checks for source files"
- print " -P, --print Print the effective build script (SRCBUILD)"
- print " -V, --version Show version information"
- print " -h, --help Show this message"
-}
-
-version() {
- print "librefetch (libretools) beta 4"
- echo
- print "Copyright (C) 2013 Luke Shumaksr <lukeshu@sbcglobal.net>"
- print "This is free software; see the source for copying conditions."
- print "There is NO WARRANTY, to the extent permitted by law."
+ flag "-g, --geninteg" "Generage integrity checks for source files"
+ flag "-P, --print" "Print the effective build script (SRCBUILD)"
+ flag "-h, --help" "Show this message"
}
main() {
@@ -81,12 +79,8 @@ main() {
mode=download-create
parse_options "$@"
- # Mode: version, help ##################################################
+ # Mode: help ###########################################################
- if [[ $mode =~ version ]]; then
- version
- return 0
- fi
if [[ $mode =~ help ]]; then
usage
return 0
@@ -97,20 +91,20 @@ main() {
local BUILDFILEDIR="${BUILDFILE%/*}"
if [[ -f "${BUILDFILEDIR}/SRCBUILD" ]]; then
BUILDFILE="${BUILDFILEDIR}/SRCBUILD"
- srcbuild="$(modified_srcbuild "$BUILDFILE")"
- else
- srcbuild="$(modified_pkgbuild "$BUILDFILE")"
fi
+ if [[ ! -f "$BUILDFILE" ]]; then
+ error "%s does not exist." "$BUILDFILE"
+ exit 1
+ fi
+ case "$BUILDFILE" in
+ */SRCBUILD) srcbuild="$(modified_srcbuild "$BUILDFILE")";;
+ *) srcbuild="$(modified_pkgbuild "$BUILDFILE")";;
+ esac
makepkg="$(modified_makepkg "$(which makepkg)")"
# Mode: checksums ######################################################
if [[ $mode =~ checksums ]]; then
- if [[ ${#extra_opts[@]} != 0 ]]; then
- print "%s: found extra non-flag arguments: %s" "$cmd" "${extra_opts[*]}" >> /dev/stderr
- usage >> /dev/stderr
- return 1
- fi
"$makepkg" "${makepkg_opts[@]}" -g -p "$srcbuild" |
case ${BUILDFILE##*/} in
PKGBUILD) sed -e 's/^[a-z]/mk&/' -e 's/^\s/ &/';;
@@ -122,45 +116,52 @@ main() {
# Mode: print ##########################################################
if [[ $mode =~ print ]]; then
- if [[ ${#extra_opts[@]} != 0 ]]; then
- print "%s: found extra non-flag arguments: %s" "$cmd" "${extra_opts[*]}" >> /dev/stderr
- usage >> /dev/stderr
- return 1
- fi
cat "$srcbuild"
return 0
fi
########################################################################
- local src dst
- case ${#extra_opts[@]} in
- 1)
- src="${extra_opts[0]#*://}"
- dst="$(readlink -m -- "${src##*/}")"
- ;;
- 2)
- src="${extra_opts[0]#*://}"
- dst="$(readlink -m -- "${extra_opts[1]}")"
- ;;
- *)
- print "%s: %d non-flag arguments found, expected 1 or 2: %s" "$cmd" ${#extra_opts[@]} >> /dev/stderr
- usage >> /dev/stderr
- return 1
- esac
+ local src="${extra_opts[0]}"
+ local dst="${extra_opts[1]:-${src##*/}}"
+
+ # Don't canonicalize $src unless mode =~ download, and we've validated
+ # that $MIRRORS is configured.
+
+ # Canonicalize $dst
+ dst="$(readlink -m -- "$dst")"
# Mode: download #######################################################
if [[ $mode =~ download ]]; then
load_files librefetch
- check_vars librefetch MIRROR DOWNLOADER || return 1
+ check_vars librefetch MIRRORS DOWNLOADER || return 1
+
+ # Canonicalize $src
+ if [[ "$src" == libre://* ]]; then
+ src="${MIRRORS[0]}/${src#libre://}"
+ fi
- local url="${MIRROR}/${src}"
+ # check to see if $src is a candidate for create mode
+ local inmirror=false;
+ local mirror
+ for mirror in "${MIRRORS[@]}"; do
+ if [[ "$src" == "$mirror"* ]]; then
+ inmirror=true
+ break
+ fi
+ done
+ if ! $inmirror; then
+ # inhibit create
+ mode=download
+ fi
local dlcmd="${DOWNLOADER}"
- dlcmd="${dlcmd//\%o/\"$dst\"}"
- dlcmd="${dlcmd//\%u/\"$url\"}"
- { eval "$dlcmd"; } >> /dev/stderr && return 0
+ [[ $dlcmd = *%u* ]] || dlcmd="$dlcmd %u"
+ dlcmd="${dlcmd//\%o/"\$dst"}"
+ dlcmd="${dlcmd//\%u/"\$src"}"
+
+ { eval "$dlcmd"; } >&2 && return 0
fi
# Mode: create #########################################################
@@ -172,16 +173,23 @@ main() {
export pkg_file=$dst
cd "$BUILDFILEDIR"
- "$makepkg" "${makepkg_opts[@]}" -p "$srcbuild" >> /dev/stderr || return $?
+ "$makepkg" "${makepkg_opts[@]}" -p "$srcbuild" >&2 || return $?
fi
}
# sets the variables BUILDFILE, makepkg_opts, extra_opts, mode
parse_options() {
- # Detect makepkg options that take a second argument
- local makepkg_orig="$(which "${MAKEPKG:-makepkg}")"
- local makepkg_opt2long=($("${makepkg_orig}" -h | sed -rn 's/\s*(--\S*) <.*/\1/p'))
- local makepkg_opt2short=($("${makepkg_orig}" -h | sed -rn 's/\s*(-.) <.*/\1/p'))
+ # Detect makepkg options
+ local makepkg_orig="$(which makepkg)"
+ # --long flags that take a second argument
+ local makepkg_opt2long=( $(LC_ALL=C "${makepkg_orig}" -h | sed -rn 's/\s*(--\S*) <.*/\1/p'))
+ # -s hort flags that take a second argument
+ local makepkg_opt2short=($(LC_ALL=C "${makepkg_orig}" -h | sed -rn 's/\s*(-.) <.*/\1/p'))
+ # all flags
+ local makepkg_argall=( $(LC_ALL=C "${makepkg_orig}" -h | sed -rn \
+ -e 's/^ +(-.) .*/\1/p' \
+ -e 's/^ +(-.), (--\S*) .*/\1\n\2/p' \
+ -e 's/^ +(--\S*) .*/\1/p'))
local opt
local have_opt
@@ -204,18 +212,42 @@ parse_options() {
-g|--geninteg) mode=checksums;;
-P|--print) mode=print;;
-p) BUILDFILE="$(readlink -m -- "$opt")";;
- -V|--version) mode=version;;
-h|--help) mode=help;;
+ --) shift; break;;
-*)
- makepkg_opts+=("$arg")
- $have_opt && makepkg_opts+=("$opt")
+ if in_array "${arg}" "${makepkg_argall[@]}"; then
+ makepkg_opts+=("$arg")
+ $have_opt && makepkg_opts+=("$opt")
+ else
+ printf '%s: invalid flag: %s' "$cmd" "$arg"
+ return 1
+ fi
;;
- --) shift; break;;
*) extra_opts+=("$arg");;
esac
shift
done
extra_opts+=("$@")
+
+ # check the number of extra_opts
+ case "$mode" in
+ help) # don't worry about it
+ :;;
+ checksums|print) # don't take any extra arguments
+ if [[ ${#extra_opts[@]} != 0 ]]; then
+ print "%s: found extra non-flag arguments: %s" "$cmd" "${extra_opts[*]}" >&2
+ usage >&2
+ return 1
+ 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
+ usage >&2
+ return 1
+ fi
+ ;;
+ esac
}
# Modify makepkg ###############################################################
@@ -232,7 +264,11 @@ makepkg_modify='
/tidy_install\(\) \{/,/^\}$/ {
/for .*PURGE_TARGETS/itidy_install_purge
/for .*PURGE_TARGETS/,/done/d
- /^\}$/ifind . -exec touch --date="1990-01-01 0:0:0 +0" {} +
+ /^\}$/ifind . -exec touch --no-dereference --date="1990-01-01 0:0:0 +0" -- {} +
+}
+
+/download_sources\(\) \{/ {
+ arm -rf "$srcdir"\nmkdir "$srcdir"
}
s|srcdir=.*|&-libre|
@@ -298,8 +334,8 @@ checkdepends=()
makedepends=("${mkdepends[@]}")
####
-options+=(!strip docs libtool emptydirs !zipman purge !upx)
-PURGE_TARGETS+=(.bzr/ .cvs/ .git/ .hg/ .svn/ .makepkg/)
+options=(!strip docs libtool staticlibs emptydirs !zipman purge !upx)
+PURGE_TARGETS=(.bzr/ .cvs/ .git/ .hg/ .svn/ .makepkg/)
####
if ! declare -f mksource >/dev/null; then
diff --git a/src/librefetch/librefetch.8.ronn b/src/librefetch/librefetch.8.ronn
index 7fa15d4..7d2dfb3 100644
--- a/src/librefetch/librefetch.8.ronn
+++ b/src/librefetch/librefetch.8.ronn
@@ -3,32 +3,40 @@ librefetch(8) -- downloads or creates a liberated source tarball
## SYNOPSIS
-`librefetch` [options] <source-url> [<output-file>]<br>
-`librefetch` -[g|V|h]
+`librefetch` [<OPTIONS>] <SOURCE-URL> [<OUTPUT-FILE>]<br>
+`librefetch` `-`[`g`|`P`|`h`]
## DESCRIPTION
`librefetch` is a program to streamline creation of custom source
tarballs for `PKGBUILD(5)` files.
-To automatically use `librefetch` to download or create a source
-tarball, you can add `libre://FILENAME.tar.gz` to the source array in
-your `PKGBUILD`. This works because a post-install script for the
-package adds `librefetch` as a download agent for `libre://` to
-`makepkg.conf`. Because of this, it is almost never necessary to call
-`librefetch` manually.
+If a URL mentioned in the `source` array in a `PKGUILD` is in a
+location that Parabola uploads "custom" source tarballs (or configured
+locations), and no file is at that URL, librefetch will automatically
+create it for you.
-There are 7 modes:
+This works because a post-install script for the package configures
+`librefetch` as the download agent for `https://` URLs in
+`makepkg.conf`; allowing it to jump in and create a file if need be.
+Because of this, it is almost never necessary to call `librefetch`
+manually.
+
+The post-install script also configures `librefetch` as the download
+agent for `libre://` URLs, for compatability with PKGBUILDs that used
+a previous version of librefetch.
+
+There are 5 modes:
- * `download-create`: The default mode. First try `download` mode,
- then `create` mode.
* `download`: Download the tarball from the configured mirror.
* `create`: Create the tarball from a `PKGBUILD`/`SRCBUILD`.
* `checksums`: Generate integrity checks for source files.
* `print`: Print the effective build script.
- * `version`: Print `librefetch` version information.
* `help`: Print `librefetch` usage information.
+The normal mode of operation is `download` mode. If `download` mode
+fails, it may choose to try `create` mode.
+
## OPTIONS
* `-C`: Force `create` mode (don't download)
@@ -39,9 +47,26 @@ There are 7 modes:
* `-g` | `--geninteg`: Use `checksums` mode: Generate integrity
checks for source files.
* `-P` | `--print`: Use `print` mode: print the effective build script.
- * `-V` | `--version`: Use `version` mode: Show version information.
* `-h` | `--help`: Use `help` mode: Show useage information.
+## DOWNLOAD MODE
+
+If <SOURCE-URL> begins with the string `libre://`, it is replaced with
+the first value in `MIRRORS`, as configured in `librefetch.conf(5)`;
+this is for compatability with PKGBUILDs that used a previous version
+of librefetch.
+
+It uses `DOWNLOADER`, as configured in `librefetch.conf` to attempt to
+download the source tarball from that URL. If that fails, and
+following conditions are met, it proceeds to `create` mode:
+
+ * The `-D` flag has not been specified to inhibit `create` mode.
+ * The `<source-url>` begins with one of the values in `MIRRORS`.
+
+The latter requirement allows librefetch to be used as a generic
+HTTP(S) download agent, that can automatically create files from
+whitelisted locations.
+
## CREATE MODE
The principle of `create` mode is that a special `PKGBUILD(5)`, called
@@ -128,11 +153,11 @@ Other changes:
* `options=()` is set have `makepkg` avoid making changes to
`$pkgdir`. The exact change is:
- options+=(!strip docs libtool emptydirs !zipman purge !upx)
+ options=(!strip docs libtool staticlibs emptydirs !zipman purge !upx)
* `PURGE_TARGETS=()` has vcs directories added to it:
- PURGE_TARGETS+=(.bzr/ .cvs/ .git/ .hg/ .svn/ .makepkg/)
+ PURGE_TARGETS=(.bzr/ .cvs/ .git/ .hg/ .svn/ .makepkg/)
### MAKEPKG MODIFICATIONS
diff --git a/src/librefetch/librefetch.conf b/src/librefetch/librefetch.conf
index 40d2078..6948e8d 100644
--- a/src/librefetch/librefetch.conf
+++ b/src/librefetch/librefetch.conf
@@ -1,2 +1,5 @@
-MIRROR='https://repo.parabolagnulinux.org/sources/'
+MIRRORS=(
+ 'https://repo.parabolagnulinux.org/sources/'
+ 'https://repo.parabolagnulinux.org/other/'
+)
DOWNLOADER='/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
diff --git a/src/librefetch/librefetch.conf.5.ronn b/src/librefetch/librefetch.conf.5.ronn
index 3d80ab5..6158104 100644
--- a/src/librefetch/librefetch.conf.5.ronn
+++ b/src/librefetch/librefetch.conf.5.ronn
@@ -24,13 +24,19 @@ If `$XDG_CONFIG_HOME` is not set, a default value is set:
## OPTIONS
- * `MIRROR='https://repo.parabolagnulinux.org/sources/'`:
- The location to download pre-built source tarball in download
- mode.
+ * `MIRRORS=( ... )`:
+ A list of locations that generated source tarballs may be located
+ at. If a URL begins with `libre://`, then `libre://` is replaced
+ with the first location listed here.
* `DOWNLOADER='/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'`:
The HTTP client to use when downloading pre-built source tarballs
- in download mode.
+ in download mode. The format and semantics are similar to
+ `DLAGENTS` in `makepkg.conf`(5). If present, `%u` will be replaced
+ with the download URL (correctly quoted), otherwise the download
+ URL will be appended to the end of the command. If present, `%o`
+ will be replaced with the local filename that it should be
+ downloaded to.
## SEE ALSO
-librefetch(8)
+librefetch(8), makepkg.conf(5)