diff options
31 files changed, 451 insertions, 89 deletions
diff --git a/HACKING.md b/HACKING.md new file mode 100644 index 0000000..2e5937b --- /dev/null +++ b/HACKING.md @@ -0,0 +1,223 @@ +This document is a little all over the place--I've been working on it +for a while, but I keep refactoring it as I move pieces of it into man +pages and whatnot. It's mostly a brain dump, sorry. + +There are three parts to this; procedures, "content" guidelines and +"style" guidelines. The style guidelines are less strict; as long as +things are consistent at the file-level, I'm pretty happy. + +Contributing +============ + +I'd love to have your patches! Code should be hackable; if you want +to modify something, but can't figure out how: 1) ping me for help, 2) +it probably means the code was too complicated in the first place. + +Patches should be sent to <dev@lists.parabolagnulinux.org>; please put +"[PATCH]" and "libretools" in the subject line. If you have commit +access, but want me to look over it first, feel free to create a new +branch in git, and I will notice it. Try to avoid pushing to the +"master" branch unless it's a trivial change; it makes it easier to +review things; though I *will* look over every commit before I do a +release, so don't think you can sneak something in :) + +I'd love to discuss possible changes on IRC (I'm lukeshu), either on +irc.freenode.net#parabola or in personal messages. My account may be +online even if I'm not; I will eventually see your it, I do a search +for mentions of "luke" on #parabola every time I get on. + +Code content +============ + +Be aware of the `librelib(7)` library suite, which lives `src/lib`. +It is a suite of Bash libraries that will help you out. Most of the +people looking at the libretools code are familiar with the `messages` +part of it, which actually contains a much of utility routines, not +just message printing. There is also a library for dealing with +`blacklist.txt`, and one for loading configuration files and +PKGBUILDs. These are common tasks, but are tricky to handle +consistently--the libraries are there to make things easier. Take a +look at the man pages. + +Message printing: All of the message printing routines, except for +`term_title` and `flag`, take printf-type arguments. Take advantage +of that; don't use string interpolation (don't do `"foo ${var} +bar"`). The reason for this is that if you don't do string +interpolation, messages can be automatically internationalized. +(Internationalization is incomplete at the momement) + +Message printing: The in `--help`/`-h` text, use `print` to print +lines that should not wrap, `echo` to print blank lines, `prose` to +print paragraphs, `bullet` to print bullet points, and `flag` to print +option flags. The text should follow this general format: + + print |Usage: ${program} [OPTIONS] VARS_ARE_UNDERSCORE_AND_CAPITAL + print |One line description of program, no period + echo + prose |More details. This is a paragraph. + echo + print |Options: + flag | -h Show this message + +In the "Usage:" line, use printf `%s` and the value `"${0##*/}"` to +determine the program name at runtime. + +There used to be guidelines for how to align the option flags and +descriptions, but now the `flag` command exists takes care of it for +you. Yay for things being easier! + +When using `set -u`, `set -e`, or `trap`, you should also use `set -E` +to have the error handling be passed down to subshells. + +Feel free to use `set -e` (fail on error), but be careful of the +caveats (there are a bunch of them); don't assume all errors are +checked because of it. + +Use `set -u` if you can; it makes using an unset variable an error. + - If a variable not being set is valid (perhaps a configuration + option), use `${var:-}` when accessing it to suppress the error. + - An empty array counts as unset, so if you have an array that may be + empty, use `set +u` before accessing it. + - The reason for this is that a normal string variable is basically + an array with length=1; an unset variable looks like an array + with length=0. Weird stuff. + +In the shebang, use `#!/usr/bin/env bash`. This allows us to not +hardcode the location of bash (I'm not sure why this is useful for +something distro-dependent like libretools, but fauno seems to have a +use-case for it). + +In the shebang, don't pass flags to bash, besides breaking `env` +(above), it means people will make mistakes when debugging, and +running things with `bash FILENAME`. Instead, use `set` to adjust the +flags inside of the program. + +Obey `$TMPDIR`. It's usually as easy as passing `--tmpdir` to +`mktemp`. + +Use `trap` to clean up your temporary files. This way, even if your +program terminates early, things will be cleaned up. + +Bash best practices +=================== + +Basically, know what you are doing, and be safe with it. The problem +is that most people don't know about safe bash scripting. + +A lot of people look at the "Advanced Bash Scripting" ebook--DO NOT do +that, it is trash... though it contains a "reference card" page that +may be useful and isn't trash. + +Take a look at Gentoo's Bash guidelines +<http://devmanual.gentoo.org/tools-reference/bash/index.html>. +They're pretty good, and cover most of the "gotcha's" about Bash +syntax. It mentions but discourages the use of Bash 3 +features... why? Who still uses Bash 2? Feel free to use Bash 4 +features! + +I wrote an article on Bash arrays +<https://lukeshu.com/blog/bash-arrays.html>. A lot of people think +they're tricky, but they're simple once you know how they work. It's +short enough that you should read the whole thing. Know the +difference between `"${array[@]}"` and `"${array[*]}"`. And I'll say +it again here, ALWAYS wrap those in double quotes; there is no reason +I can think of that the unquoted behavior would ever be the correct +thing. + +My brief rules of thumb: + + - Quote every variable. + - That includes arrays: `"${array[@]}"` and `"${array[*]}"`. + - In most (but not all!) cases inside of `[[ ... ]]` conditions, + variables don't need to be quoted. When in doubt, quote them. + - When assigning one variable to another, you don't need quotes; + you don't need quotes for `foo=$bar` + - Try to avoid global variables; declare all variables in functions + with `local`. + - Or `declare`; inside of a function, unless you pass the `-g` + flag, `declare` makes the variable local. + - Use `local VAR` before a `for VAR in LIST` loop--the variable is created in the + current scope, not the scope of the loop. + - Feeding input to `while` loops is weird because of how subshells + work: + + # Input from a file + # BAD + cat file | while read line; do + ... + done + # GOOD + while read line; do + ... + done <file + + # Input from a program + # BAD + prog | while read line; do + ... + done + # GOOD + while read line; do + ... + done < <(prog) + + +Style guidelines +================ + +Unless you have a good reason, use `[[ ... ]]` instead of `[ ... ]`; +they work similarly, but `[[ ... ]]` is sometimes more readable (fine, +rarely, but never less), and is harder to make mistakes with quoting, +because it is syntactic magic, as opposed to `[ ... ]` which is an +executable which just happens to be implemented as a builtin. + +Use a litteral tab for indent. When indenting line-wrapped text, such +as that for `prose`, do it like this: (» indicates tab, · indicates +space) + + func() { + » prose "This is the first line. This paragraph is going to be + » ·······wrapped." + } + +The `; then` and `; do` should go on the same line as +`if`/`elif`/`for`/`while`. Also, there is no space before the `;`. + +Prefer the `for VAR in LIST` syntax over the `for ((init; cond; inc))` +syntax, when possible. For example (heh, `for` example): + + local i + for (( i = 1 ; i <= 10 ; i++ )); do + +should be + + local i + for i in {1..10}; do + +Of course, if the upper bound is a variable, the C-like syntax is +the better option, as otherwise you would have to use `seq` (calling +an external), or `eval` (gross, easy to mess up royally). + +Indent comments like you would code; don't leave them at the beginning +of the line. Example: + + for item in "${list[@]}"; do + if [[ $item == foo ]]; then + # BAD + foobar + fi + if [[ $item == bar ]]; then + # GOOD + barbaz + fi + done + +Fauno, I'm sorry. But I don't know how you can read your own code :P. + +Some people argue in favor of the useless use of cat, because data +should flow from left to right. However, the input redirection +doesn't have to go on the right side of a command: + + cat file | program # useless use of cat + program < file # data flows right to left + < file program # just right @@ -0,0 +1,119 @@ +Installation of libretools is pretty straight-forward. The only +tricky thing is the weird dependence on the devtools-par source code. + +The build system will by default look at `$(topdir)/../devtools-par` +for the devtools-par source code. This can be changed by adjusting +the `devtoolsdir` configuration variable, see "Configuration" below. + +Once you have the devtools source taken care of, you can have the +default everything-included install by running: + + $ make + # make install + +Dependencies +------------ + +Unlike a lot of software, run-time dependencies are not required at +build-time. + +Libretools is mostly shell scripts. It very specifically targets +Parabola GNU/Linux-libre; there are a lot of dependencies, most of +which are undocumented. Switching away from a GNU user-land is bound +to cause issues. + +## Build dependencies + +The "unusual" build-time dependencies are: + + - GNU Make -- other `make`s will not work. + - GNU sed -- must support `-r` for ERE; BSD sed uses `-E` for this purpose. + - Emacs -- `emacs --batch` is used use Emacs Lisp to process some text. + - ronn -- A markdown-to-manpage converter + +At this time, the build system dos not support not building the +documentation; ronn is required. + +Additionally, other usual "core utilities" are required: + + cat, chmod, cp, echo, false, find, install, ln, msguniq, rm, tr, + xgettext + +Also, `/bin/sh` must support `{brace,expansion}`. If it doesn't, find +a shell that does, and configure `make` to use it. Though, because +libretools is mostly shell scripts, if you deviate too much from a GNU +command-line environment, I suspect that you will run into more +issues. If I were targeting anything other than Parabola, this would +be a bigger issue. + +## Test suite dependencies + +If you wish to run the test suite, you will need the "roundup" shell +unit testing program. On Parabola GNU/Linux-libre it is called +"sh-roundup". If your operating system doesn't have it, it is +available at <http://bmizerany.github.io/roundup/>. + +## Run-time dependencies + +Being mostly shell scripts, many external program are used. Anything +that is included when installing the `base` package group on Parabola +GNU/Linux, I consider an implicit dependency. If something isn't used +now, that doesn't mean it won't be in the future. + +On top of that, the following dependencies are also needed: + +librelib subpackage: + - wget +gitget subpackage: + - librelib (provided) + - git +main libretools subpackage: + - librelib (provided) + - gitget (provided, only needed for `createworkdir`) + - arch-install-scripts + - ssh client (OpenSSH, only needed for `librerelease` + - rsync + - subversion + - tokyocabinet +libretools-mips64el subpackage: + - libretools (provided) + - git + +Configuration +------------- + +This is not a GNU package, there is no `./configure` script. + +There are two ways to set configuration variables: + 1. Edit config.mk + 2. Pass `VARIABLE=VALUE` to `make` + +The configuration variables mostly match GNU packages, but default +values differ; libretools installs to `prefix=/usr` by default instead +of GNU's `prefix=/usr/local`. + +Building and installing subpackages +----------------------------------- + +There are several subpackages you can build and install. This is done +by running: + + $ make build-${package} + # make install-${package} + +respectively. In addition to `build` and `install`, the activities +you can do are: + + - `copy` -- copy necessary files from the devtools-par source code + - `build` -- build all programs and files + - `install` -- install everything + - `clean` -- remove generated files + - `pot` -- generate gettext portable object template files. + +The subpackages you can run these on are: + + - doc -- The non-manpage documentation + - libretools -- The main libretools package + - libretools-mips64el -- Programs useful for porting to mips64el + - librelib -- generic libraries included + - gitget -- A git downloader diff --git a/src/abslibre-tools/createworkdir b/src/abslibre-tools/createworkdir index 8e88375..4421ae2 100755 --- a/src/abslibre-tools/createworkdir +++ b/src/abslibre-tools/createworkdir @@ -42,10 +42,11 @@ if ! "${cmd[@]}"; then plain "Try running this command:" echo printf '%q ' "${cmd[@]}" + echo exit 1 fi msg "Finished, your packaging directory tree looks like this now:" -ls --color=always "${WORKDIR}"/*/* +ls --color=always "${WORKDIR}"/* trap -- EXIT diff --git a/src/abslibre-tools/diff-unfree b/src/abslibre-tools/diff-unfree index b3e2327..1ef0649 100755 --- a/src/abslibre-tools/diff-unfree +++ b/src/abslibre-tools/diff-unfree @@ -23,7 +23,7 @@ . libremessages . $(librelib conf.sh) load_files libretools -check_vars libretools DIFFTOOL || exit 1 +check_vars libretools DIFFPROG || exit 1 usage() { print "Usage: %s [community|packages] [unfree-package] [repo]" "${0##*/}" @@ -80,7 +80,7 @@ main() { for _file in ${unfree_dir}/*; do msg2 "%s" "$(basename "${_file}")" - ${DIFFTOOL} "$PWD/$(basename "${_file}")" "${_file}" + ${DIFFPROG} "$PWD/$(basename "${_file}")" "${_file}" done } diff --git a/src/abslibre-tools/libreaddiff b/src/abslibre-tools/libreaddiff index 9f5ae27..ebd749d 100755 --- a/src/abslibre-tools/libreaddiff +++ b/src/abslibre-tools/libreaddiff @@ -74,14 +74,14 @@ except StopIteration: load_PKGBUILD "$f/PKGBUILD" || continue is_here=false for arc in ${arch[@]} ; do - if [ "$arc" = "any" -o "$arc" = "$CARCH" ] ; then + if [[ "$arc" == "any" ]] || [[ "$arc" == "$CARCH" ]] ; then is_here=true break fi done - if [ "$is_here" = "true" ] ; then - for name in ${pkgname[@]} ; do - if [ -z "$epoch" ] ; then + if [[ "$is_here" == "true" ]] ; then + for name in "${pkgname[@]}" ; do + if [[ -z "$epoch" ]] ; then echo $name-$pkgver-$pkgrel else echo $name-$epoch:$pkgver-$pkgrel diff --git a/src/abslibre-tools/librerelease b/src/abslibre-tools/librerelease index adfb935..b77b6ec 100755 --- a/src/abslibre-tools/librerelease +++ b/src/abslibre-tools/librerelease @@ -68,7 +68,7 @@ create_signature() { SIGNWITHKEY="-u ${GPGKEY}" fi # The signature will be generated directly in ascii-friendly format - gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$? + gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" || ret=$? if (( ! ret )); then @@ -80,12 +80,12 @@ create_signature() { } sign_packages() { - if [ -z "${GPG_AGENT_INFO}" ]; then - warning "It's better to use gpg-agent to sign packages in batches" + if [[ -z "${GPG_AGENT_INFO}" ]]; then + warning "It's better to have \`%s\` running to sign packages in batches" 'gpg-agent --daemon' fi for package in $(find "${WORKDIR}/staging/" -type f -iname '*.pkg.tar.?z'); do - if [ -f "${package}.sig" ]; then + if [[ -f "${package}.sig" ]]; then msg2 "Package signature found, verifying..." # Verify that the signature is correct, else remove for re-signing @@ -95,7 +95,7 @@ sign_packages() { fi fi - if ! [ -f "${package}.sig" ]; then + if ! [[ -f "${package}.sig" ]]; then create_signature "$package" || return 2 fi done @@ -20,15 +20,15 @@ . libremessages -cmd=${0##*/} usage() { - echo "Usage: $cmd [-h] pkgname-from-aur1 [pkgname-from-aur2 ...]" + print "Usage: %s [-h] PKGNAME [PKGNAME2 PKGNAME3...]" "${0##*/}" + print "Downloads packages from the AUR, and does basic freedom checks." echo - echo "This script will download packages from AUR to the current" - echo "directory and check their license for nonfree issues. This does" - echo "not mean that they are free; they may be incorrectly labeled, or" - echo "have other freedom issues. It's a tool to help Parabola" - echo "packagers, not to help users install things directly from AUR." + prose "This script will download packages from AUR to the current + directory and check their license for nonfree issues. This does + not mean that they are free; they may be incorrectly labeled, or + have other freedom issues. It's a tool to help Parabola + packagers, not to help users install things directly from AUR." } main() { @@ -45,7 +45,7 @@ main() { . $(librelib conf.sh) load_files libretools - check_vars libretools DIFFTOOL || exit 1 + check_vars libretools DIFFPROG || exit 1 local startdir="$(pwd)" local missing_deps=() @@ -88,7 +88,7 @@ main() { if ! cmp -s "${copy_old}/${file}" "${copy_new}/${file}" ; then warning "%s != %s" "${copy_old}/${file}" "${copy_new}/${file}" diffed=true - "${DIFFTOOL}" "${copy_old}/${file}" "${copy_new}/${file}" + "${DIFFPROG}" "${copy_old}/${file}" "${copy_new}/${file}" fi done if $diffed; then diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup index 0c78989..2ff45f9 100755 --- a/src/chroot-tools/chcleanup +++ b/src/chroot-tools/chcleanup @@ -53,7 +53,7 @@ fi source /etc/libretools.d/chroot.conf # If we're running makepkg -if [ -f PKGBUILD ]; then +if [[ -f PKGBUILD ]]; then export CARCH="$(. /etc/makepkg.conf; printf '%s' "$CARCH")" source ./PKGBUILD CHROOTEXTRAPKG+=("${depends[@]}" diff --git a/src/chroot-tools/hooks-distcc.sh b/src/chroot-tools/hooks-distcc.sh index 9e42242..d8d708a 100644 --- a/src/chroot-tools/hooks-distcc.sh +++ b/src/chroot-tools/hooks-distcc.sh @@ -75,7 +75,7 @@ distcc_stop() { if [[ -f "$copydir/run/distcc-tool.pid" ]]; then - odaemon=$(cat "$copydir/distcc-tool.pid") + odaemon=$(< "$copydir/distcc-tool.pid") kill -- "$odaemon" rm -f -- \ diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index b55cae1..5e16587 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -178,7 +178,7 @@ calculate_directories() { check_mountpoint() { local file=$1 local mountpoint="$(df -P "$file"|sed '1d;s/.*\s//')" - local mountopts=($(LANG=C mount|awk "{ if (\$3==\"$mountpoint\") { gsub(/[(,)]/, \" \", \$6); print \$6 } }")) + local mountopts=($(LC_ALL=C mount|awk "{ if (\$3==\"$mountpoint\") { gsub(/[(,)]/, \" \", \$6); print \$6 } }")) ! in_array nosuid "${mountopts[@]}" && ! in_array noexec "${mountopts[@]}" } @@ -190,8 +190,8 @@ arch-nspawn() { if [[ -t 1 ]]; then cmd=("$@") else - # This perl script is equivalent to `sed -s 's|\n|\r\n|g', but - # it doesn't line-buffer. + # This perl script is similar to `sed 's|\n|\r\n|g'`, (or, more + # correctly, `sed 's|$|\r|'`) but it does't line-buffer. local perlcmd=' my $size; my $buffer; diff --git a/src/chroot-tools/makechrootpkg.sh.patch b/src/chroot-tools/makechrootpkg.sh.patch index 4082bdd..4dd1146 100644 --- a/src/chroot-tools/makechrootpkg.sh.patch +++ b/src/chroot-tools/makechrootpkg.sh.patch @@ -1,5 +1,5 @@ ---- makechrootpkg.sh.in 2013-10-15 21:33:17.000000000 -0400 -+++ makechrootpkg.sh.ugly 2013-10-25 19:05:08.000000000 -0400 +--- makechrootpkg.sh.in 2013-10-26 14:53:57.000000000 -0400 ++++ makechrootpkg.sh.ugly 2013-11-16 15:14:04.000000000 -0500 @@ -12,6 +12,7 @@ shopt -s nullglob @@ -92,7 +92,7 @@ # Get a read lock on the root chroot to make # sure we don't clone a half-updated chroot slock 8 "$chrootdir/root.lock" "Locking clean chroot" -@@ -154,10 +171,15 @@ +@@ -154,11 +171,16 @@ # Drop the read lock again lock_close 8 @@ -100,6 +100,7 @@ } -clean_temporary() { +- stat_busy "Removing temporary copy [%s]" "$copy" +# Usage: delete_chroot $copydir [$copy] +delete_chroot() { + local copydir=$1 @@ -107,9 +108,10 @@ + # Detect chrootdir filesystem type + local chroottype=$(stat -f -c %T "$copydir") + - stat_busy "Removing temporary copy [%s]" "$copy" ++ stat_busy "Removing chroot copy [%s]" "$copy" if [[ "$chroottype" == btrfs ]]; then btrfs subvolume delete "$copydir" >/dev/null || + die "Unable to delete subvolume %s" "$copydir" @@ -173,9 +195,14 @@ stat_done } diff --git a/src/fullpkg/fullpkg b/src/fullpkg/fullpkg index 00a9502..978cf7b 100755 --- a/src/fullpkg/fullpkg +++ b/src/fullpkg/fullpkg @@ -29,7 +29,7 @@ done shift $(( OPTIND - 1 )) -build_dir="${1:-$(mktemp -d /tmp/fullpkg.XXXXXX)}" +build_dir="${1:-$(mktemp --tmpdir -d fullpkg.XXXXXXXXXX)}" fullpkg-find "$build_dir" && fullpkg-build -N "$build_dir" exit 0 diff --git a/src/fullpkg/fullpkg-build b/src/fullpkg/fullpkg-build index 8149453..e824c2e 100755 --- a/src/fullpkg/fullpkg-build +++ b/src/fullpkg/fullpkg-build @@ -45,13 +45,13 @@ remove_buildorder() { succesfull_build() { - if [ "$RUN" != "$FULLBUILDCMD" ]; then + if [[ "$RUN" != "$FULLBUILDCMD" ]]; then return 0 # Custom command or download sources fi - if source .INFO && [ -n "$repo" ]; then + if source .INFO && [[ -n "$repo" ]]; then - if [ ! -z "$HOOKLOCALRELEASE" ]; then + if [[ ! -z "$HOOKLOCALRELEASE" ]]; then "$HOOKLOCALRELEASE" "$repo" fi @@ -75,11 +75,11 @@ __build() { build_packages=($(sort -gr $buildorder | cut -d: -f2)) # greater levels must be built first - while [ ${#build_packages[@]} -ge 1 ]; do + while [[ ${#build_packages[@]} -ge 1 ]]; do pushd "$build_dir/${build_packages[0]}" >/dev/null - if [ -n "${HOOKPKGBUILDMOD}" ]; then + if [[ -n "${HOOKPKGBUILDMOD}" ]]; then ${HOOKPKGBUILDMOD} || true fi @@ -156,7 +156,7 @@ shift $(( OPTIND - 1 )) build_dir="${1:-`pwd`}" buildorder="${build_dir}/BUILDORDER" -if [ ! -e "$buildorder" ]; then +if [[ ! -e "$buildorder" ]]; then error "This is not a build_dir. Make one using fullpkg." usage exit 1 @@ -172,7 +172,7 @@ fi msg "$MESSAGE" __build -if [ "$RUN" != "$FULLBUILDCMD" ]; then +if [[ "$RUN" != "$FULLBUILDCMD" ]]; then # Used for downloading or custom command mv "$build_dir/.BUILDORDER" "$buildorder" exit 0 diff --git a/src/fullpkg/fullpkg-find b/src/fullpkg/fullpkg-find index 566605a..a96bc8a 100755 --- a/src/fullpkg/fullpkg-find +++ b/src/fullpkg/fullpkg-find @@ -104,7 +104,7 @@ find_deps() { # greater levels are built first echo "${LEVEL}:${pkgbase}" >>"$build_dir/BUILDORDER" # PKGBUILD is already there - if [ -d "${build_dir}/${pkgbase}" ]; then + if [[ -d "${build_dir}/${pkgbase}" ]]; then exit 0 # Copy dir to build_dir else @@ -126,14 +126,15 @@ find_deps() { tr ' ' "\n" | \ sort -u)) - for _dep in ${deps[@]}; do + local _dep + for _dep in "${deps[@]}"; do local found=false # May fail, e.g. since abslibre-mips64el doesn't include # arch=any packages. local pkgdir=$(toru -p ${_dep}) || true - if [ -n "$pkgdir" -a -d "${pkgdir}" ]; then + if [[ -n "$pkgdir" ]] && [[ -d "${pkgdir}" ]; then found=true pushd "${pkgdir}" > /dev/null @@ -193,7 +194,7 @@ while getopts 'hA:l:cmn' arg; do esac done -if [ ! -r PKGBUILD ]; then +if [[ ! -r PKGBUILD ]]; then error "This directory doesnt contain a PKGBUILD" usage exit 1 @@ -202,11 +203,11 @@ fi shift $(( OPTIND - 1 )) build_dir="${1}" -if [ "$LEVEL" -eq 0 ]; then +if [[ "$LEVEL" -eq 0 ]]; then build_dir="${1:-$(mktemp -d /tmp/fullpkg.XXXXXX)}" - if [ ! -d "$build_dir" ]; then + if [[ ! -d "$build_dir" ]]; then mkdir -p "$build_dir" elif "$CLEANFIRST"; then # Erase files already in dir diff --git a/src/gitget/gitget b/src/gitget/gitget index 256b4e4..194ec05 100755 --- a/src/gitget/gitget +++ b/src/gitget/gitget @@ -191,6 +191,7 @@ main() { *) usage >&2; return 1;; esac done + shift $(($OPTIND - 1)) [[ $# == 3 ]] || { usage >&2; return 1; } local mode=$1 local url=${2#git+} @@ -198,6 +199,9 @@ main() { local urlmain=${url%%#*} local urlfrag=${url#*#} + if [[ "$urlfrag" == "$urlmain" ]]; then + urlfrag='' + fi local ref=${urlfrag#*=} if [[ -z $ref ]]; then diff --git a/src/is_built b/src/is_built index 80d0719..ba5f061 100755 --- a/src/is_built +++ b/src/is_built @@ -1,18 +1,21 @@ #!/usr/bin/env bash -cmd=${0##*/} +. libremessages + usage() { - echo "Usage: $cmd [-h] pkgname [pkgver]" + print "Usage: %s [-h] PKGNAME [PKGVER]" "${0##*/}" "${0##*/}" + print 'Detect iv a given package (version) is already in the repos' echo - echo "Detect if a given package version is already in repos" - echo "Assuming you want greater or equal." + prose "If a version is specified, it assumedx that you want a greater or + equal version." echo - echo "Example usage: $cmd 'pcre' '20'" + prose "Example usage:" + print " $ %s 'pcre' '20'" "${0##*/}" echo - echo "Exit status:" - echo " 0: The package is built" - echo " 1: The package has not built" - echo " >1: There was an error" + print "Exit status:" + print " 0: The package is built" + print " 1: The package has not built" + print " >1: There was an error" } while getopts 'h' arg; do diff --git a/src/lib/conf.sh b/src/lib/conf.sh index 07b6fd5..561ae9e 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -81,6 +81,9 @@ list_envvars() { PKGEXT SRCEXT \ GPGKEY PACKAGER ;; + libretools) + printf '%s\n' DIFFPROG + ;; xbs) printf '%s\n' BUILDSYSTEM ;; diff --git a/src/lib/libremessages.1.ronn b/src/lib/libremessages.1.ronn index 970b950..b91a958 100644 --- a/src/lib/libremessages.1.ronn +++ b/src/lib/libremessages.1.ronn @@ -51,6 +51,8 @@ the command `help printf` from a Bash shell for more information. ### GENERAL ROUTINES +Unless otherwise noted, these do not implicitly call `gettext`. + * `_` <MESSAGE>: If `gettext` is available, calls `gettext`, otherwise just prints the arguments given. @@ -61,7 +63,7 @@ the command `help printf` from a Bash shell for more information. * `panic`: For the times when you can't reasonably continue, similar to - "assert" in some languages. + "assert" in some programming languages. * `term_title` <MESSAGE>...: Joins all arguments with whitespace, and sets the terminal title @@ -72,6 +74,8 @@ the command `help printf` from a Bash shell for more information. These routines print to standard output, ande are useful for printing word-wrapped prose. +For each of these, <MESSAGE> is fed through `gettext` automatically. + * `print` <MESSAGE> [<ARGS>...]: Like `printf`(1), but `gettext`-aware, and automatically prints a trailing newline. @@ -102,6 +106,8 @@ These routines print to standard error, and all take arguments in the same format as `printf`(1), except for `stat_done`, which doesn't take any arguments. +For each of these, <MESSAGE> is fed through `gettext` automatically. + * `plain` <MESSAGE> [<ARGS>...]: Prints "plain" message in bold, indented with 4 spaces. diff --git a/src/librefetch/librefetch.conf b/src/librefetch/librefetch.conf index 40d2078..ce328d8 100644 --- a/src/librefetch/librefetch.conf +++ b/src/librefetch/librefetch.conf @@ -1,2 +1,2 @@ -MIRROR='https://repo.parabolagnulinux.org/sources/' +MIRROR='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..4e59877 100644 --- a/src/librefetch/librefetch.conf.5.ronn +++ b/src/librefetch/librefetch.conf.5.ronn @@ -24,7 +24,7 @@ If `$XDG_CONFIG_HOME` is not set, a default value is set: ## OPTIONS - * `MIRROR='https://repo.parabolagnulinux.org/sources/'`: + * `MIRROR='https://repo.parabolagnulinux.org/other/'`: The location to download pre-built source tarball in download mode. * `DOWNLOADER='/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'`: diff --git a/src/libretools.conf b/src/libretools.conf index 50ded8b..ff989f0 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -5,14 +5,14 @@ ################################################################################ # The dir where you work on -WORKDIR=/home/$LIBREUSER/packages +WORKDIR="$LIBREHOME/packages" ## Blacklist URL BLACKLIST=https://repo.parabolagnulinux.org/docs/blacklist.txt ## Diff tool (vimdiff, gvimdiff, meld, etc) ## Used by `aur`, `diff-unfree` -DIFFTOOL=`which kdiff3 meld gvimdiff vimdiff colordiff diff 2>/dev/null|sed 's/\s.*//;1q'` +DIFFPROG=`which kdiff3 meld gvimdiff vimdiff colordiff diff 2>/dev/null|sed 's/\s.*//;1q'` ## The repos you'll be packaging for ## Used by `toru`, `createworkdir` @@ -28,7 +28,7 @@ ARCHES=('x86_64' 'i686' 'mips64el') ## ABSLibre ## Used by `createworkdir` -ABSLIBREREGV=git://projects.parabolagnulinux.org/abslibre.git +ABSLIBRERECV=git://projects.parabolagnulinux.org/abslibre.git ABSLIBRESEND=ssh://git@projects.parabolagnulinux.org:1863/srv/git/abslibre.git ################################################################################ diff --git a/src/treepkg b/src/treepkg index 5c1312d..e509dac 100755 --- a/src/treepkg +++ b/src/treepkg @@ -19,15 +19,15 @@ source libremessages source $(librelib conf.sh) load_files libretools -check_vars libretools HOOKPREBUILD FULLBUILDCMD HOOKLOCALRELEASE +check_vars libretools HOOKPREBUILD FULLBUILDCMD HOOKLOCALRELEASE || exit 1 load_files makepkg term_title "$(basename $0)" # End inmediately but print an useful message trap_exit() { - term_title "error!" - error "($(basename $0)) $@ (leftovers on ${BUILDDIR})" + term_title "${0##*/}: $(_ 'Error!')" + error "%s: %s (leftovers on %s" "${0##*/}" "$*" "${BUILDDIR}" exit 1 } @@ -59,10 +59,10 @@ bury() { # If there's a depth or the package is not the root of the build tree (which # can lead to funny chicken-and-egg problems), update the depth to the current # package next-depth and rename the dir too - if [ -z "${current_depth}" ]; then return; fi - if [ -z "${current_name}" ]; then return; fi - if [ ${current_depth} -eq 0 ]; then return; fi - if [ ${current_depth} -ge $2 ]; then return; fi + if [[ -z "${current_depth}" ]]; then return; fi + if [[ -z "${current_name}" ]]; then return; fi + if [[ ${current_depth} -eq 0 ]]; then return; fi + if [[ ${current_depth} -ge $2 ]]; then return; fi ${VERBOSE} && msg "Burying ${1} from ${current_depth} to ${2}" @@ -78,8 +78,8 @@ guess_repo() { basename "$(dirname "${1}")" } -if [ ! -f PKGBUILD ]; then - error "Missing PKGBUILD ($PWD)" +if [[ ! -f PKGBUILD ]]; then + error "Missing PKGBUILD (%s)" "$PWD" exit 1 fi @@ -103,7 +103,7 @@ done pkgbase="${pkgbase:-${pkgname[0]}}" # Get or set the work dir -BUILDDIR="${1:-$(mktemp -d /tmp/${pkgbase}-treepkg-XXXx)}" +BUILDDIR="${1:-$(mktemp --tmpdir -d ${pkgbase}-treepkg.XXXXXXXXXX)}" BUILDORDER="${BUILDDIR}/BUILDORDER" DEPTH=${2:-0} NEXTDEPTH=$((${DEPTH} + 1)) @@ -175,21 +175,21 @@ if ! ${BUILDNOW}; then fi # Only build at the end -if [ ${DEPTH} -eq 0 ]; then +if [[ ${DEPTH} -eq 0 ]]; then ${VERBOSE} && msg "Starting build" || true if ${BUILD}; then - ${VERBOSE} && msg "Build tree stored in ${BUILDORDER}" || true + ${VERBOSE} && msg "Build tree stored in %s" "${BUILDORDER}" || true # Build everything sorting the build dir # The reverse order ensures we start by the deepest packages for _pkg in $(ls -r "${BUILDDIR}"); do # Ignore if there's no PKGBUILD - if [ ! -f "${BUILDDIR}/${_pkg}/PKGBUILD" ]; then continue; fi + if [[ ! -f "${BUILDDIR}/${_pkg}/PKGBUILD" ]]; then continue; fi # Skip if already built (faster than calling is_build again) - if [ -f "${BUILDDIR}/${_pkg}/built_ok" ]; then continue; fi + if [[ -f "${BUILDDIR}/${_pkg}/built_ok" ]]; then continue; fi - ${VERBOSE} && msg "Building ${_pkg/_/ }" || true + ${VERBOSE} && msg "Building %s" "${_pkg/_/ }" || true # Remove leading zeros and space if any term_title "$(echo ${_pkg/_/ } | sed "s/^0\+ \?//")" @@ -214,11 +214,11 @@ if [ ${DEPTH} -eq 0 ]; then fi if ${CLEANUP} ; then - msg2 "Removing ${BUILDDIR}" + msg2 "Removing %s" "${BUILDDIR}" rm -rf "${BUILDDIR}" fi fi -term_title "done" +term_title "$(_ Done)" exit $? diff --git a/test/aur-test.sh b/test/aur-test.sh index 8b175eb..8bcb5ef 100644 --- a/test/aur-test.sh +++ b/test/aur-test.sh @@ -13,7 +13,7 @@ after() { } it_displays_help() { - LANG=C aur -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C aur -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr diff --git a/test/is_built-test.sh b/test/is_built-test.sh index e76ffc0..af754dc 100644 --- a/test/is_built-test.sh +++ b/test/is_built-test.sh @@ -13,7 +13,7 @@ after() { } it_displays_help() { - LANG=C is_built -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C is_built -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh index be54b47..640ed77 100644 --- a/test/lib-blacklist-test.sh +++ b/test/lib-blacklist-test.sh @@ -110,7 +110,7 @@ it_downloads_the_blacklist_repeatedly() { } it_displays_help_and_fails_with_no_args() { - LANG=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + LC_ALL=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? [[ $stat != 0 ]] empty $tmpdir/stdout @@ -118,14 +118,14 @@ it_displays_help_and_fails_with_no_args() { } it_displays_help_when_given_h() { - LANG=C libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist ' ]] empty $tmpdir/stderr } it_displays_help_when_given_h_cat() { - LANG=C libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" == 'Usage: libreblacklist cat' ]] empty $tmpdir/stderr diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh index 8efba67..5ca1b37 100644 --- a/test/librechroot-test.sh +++ b/test/librechroot-test.sh @@ -42,7 +42,7 @@ it_respects_exit_status_if_out_isnt_a_tty() ( it_displays_help_as_normal_user() { rm -rf "$XDG_CONFIG_HOME" - LANG=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr @@ -57,7 +57,7 @@ it_otherwise_fails_as_normal_user() { } it_displays_help_and_fails_with_0_args() { - LANG=C librechroot >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + LC_ALL=C librechroot >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? [[ $stat != 0 ]] empty $tmpdir/stdout diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh index 7408993..13ce80f 100644 --- a/test/librefetch-test.sh +++ b/test/librefetch-test.sh @@ -25,7 +25,7 @@ after() { } it_displays_help() { - LANG=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh index bef1db8..e684f18 100644 --- a/test/libremakepkg-test.sh +++ b/test/libremakepkg-test.sh @@ -72,7 +72,7 @@ it_handles_PKGDEST_not_existing() { it_displays_help_as_normal_user() { rm -rf "$XDG_CONFIG_HOME" - LANG=C libremakepkg -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C libremakepkg -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr diff --git a/test/librerelease-test.sh b/test/librerelease-test.sh index ebbd504..c395bc6 100644 --- a/test/librerelease-test.sh +++ b/test/librerelease-test.sh @@ -26,7 +26,7 @@ after() { it_displays_usage_text() { rm -rf "$XDG_CONFIG_HOME" - LANG=C librerelease -h >"$tmpdir/stdout" 2>"$tmpdir/stderr" + LC_ALL=C librerelease -h >"$tmpdir/stdout" 2>"$tmpdir/stderr" [[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]] empty "$tmpdir/stderr" @@ -40,7 +40,7 @@ it_lists_all_files() { "$WORKDIR/staging/repo1/file2" \ "$WORKDIR/staging/repo2/file with spaces" unset WORKDIR - LANG=C librerelease -l &>"$tmpdir/list" + LC_ALL=C librerelease -l &>"$tmpdir/list" cat > "$tmpdir/list-correct" <<EOF -> repo1 diff --git a/test/librestage-test.sh b/test/librestage-test.sh index 5c7487b..6728143 100644 --- a/test/librestage-test.sh +++ b/test/librestage-test.sh @@ -23,7 +23,7 @@ after() { it_displays_usage_text() { rm -rf "$XDG_CONFIG_HOME" - LANG=C librestage -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C librestage -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]] empty "$tmpdir/stderr" diff --git a/test/pkgbuild-check-nonfree-test.sh b/test/pkgbuild-check-nonfree-test.sh index b30204b..6463d64 100644 --- a/test/pkgbuild-check-nonfree-test.sh +++ b/test/pkgbuild-check-nonfree-test.sh @@ -27,7 +27,7 @@ after() { it_displays_usage_text() { # This test seems silly, but it makes sure that it is executable, # syntactically correct, and loading libraries works. - LANG=C $pcn -h >$tmpdir/stdout 2>$tmpdir/stderr + LC_ALL=C $pcn -h >$tmpdir/stdout 2>$tmpdir/stderr stat=$? [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] |