diff --git a/.travis.yml b/.travis.yml index 5700ce6..34b11be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ env: - SH=bash script: - find bin lib -type f | xargs shellcheck -s sh + - shfmt -i 4 -ci -p -l -s -w lib/ bin/ + - git diff --exit-code - make check notifications: irc: "chat.freenode.net#freight" diff --git a/README.md b/README.md index ccb53b4..6cd70f3 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Serve `/var/cache/freight` via your favorite web server and install it as an APT ### From a Debian archive wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg|sudo apt-key add - - echo "deb http://build.openvpn.net/debian/freight_team $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/freight.list + echo "deb http://build.openvpn.net/debian/freight_team $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/freight.list sudo apt-get update sudo apt-get -y install freight @@ -91,8 +91,12 @@ Freight is [BSD-licensed](https://github.com/freight-team/freight/blob/master/LI * Issue tracker: * Wiki: +### Static analysis and code style + +[Shellcheck](https://www.shellcheck.net/) and [shfmt](https://github.com/mvdan/sh) are used to ensure consistency, please see the Travis configuration for the actual tests. + ### Test suite -The Freight test suite can be executed by running `make check` from any git checkout of this repository. git and GnuPG are required for most tests, and extended tests require apt. +The Freight test suite can be executed by running `make check` from any git checkout of this repository. git and GnuPG are required for most tests, and extended tests require apt. Contributions should include a new test case where possible by extending one or more of the `test/*.bats` files. diff --git a/bin/freight-add b/bin/freight-add index 03b24b4..dd89828 100755 --- a/bin/freight-add +++ b/bin/freight-add @@ -15,17 +15,19 @@ usage() { grep "^#/" "$0" | cut -c"4-" >&2 exit "$1" } -while [ "$#" -gt 0 ] -do +while [ "$#" -gt 0 ]; do case "$1" in - -c|--conf) CONF="$2" shift 2;; - -c*) CONF="$(echo "$1" | cut -c"3-")" shift;; - --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift;; - -v|--verbose) VERBOSE=1 shift;; - -e|--add-error) FREIGHT_ADD_ERROR="YES" shift;; - -h|--help) usage 0;; - -*) echo "# [freight] unknown switch: $1" >&2; usage 1;; - *) break;; + -c | --conf) CONF="$2" shift 2 ;; + -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; + --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; + -v | --verbose) VERBOSE=1 shift ;; + -e | --add-error) FREIGHT_ADD_ERROR="YES" shift ;; + -h | --help) usage 0 ;; + -*) + echo "# [freight] unknown switch: $1" >&2 + usage 1 + ;; + *) break ;; esac done @@ -35,14 +37,14 @@ done # Binary packages have only one but source packages require two or three. # When the last of these is found, the remaining arguments are each assumed # to be `/` pairs for this (source) package. -while [ "$#" -gt 0 ] -do +while [ "$#" -gt 0 ]; do case "$1" in - *.deb|*.dsc|*.orig.tar.gz|*.orig.tar.bz2|*.orig.tar.xz|*.orig.tar.lzma|*.diff.gz|*.debian.tar.gz|*.debian.tar.bz2|*.debian.tar.xz|*.debian.tar.lzma|*.tar.gz|*.tar.bz2|*.tar.xz|*.tar.lzma) + *.deb | *.dsc | *.orig.tar.gz | *.orig.tar.bz2 | *.orig.tar.xz | *.orig.tar.lzma | *.diff.gz | *.debian.tar.gz | *.debian.tar.bz2 | *.debian.tar.xz | *.debian.tar.lzma | *.tar.gz | *.tar.bz2 | *.tar.xz | *.tar.lzma) # shellcheck disable=SC2153 - PATHNAMES="$PATHNAMES $1" shift;; - *.build|*.changes) shift;; - *) break;; + PATHNAMES="$PATHNAMES $1" shift + ;; + *.build | *.changes) shift ;; + *) break ;; esac done [ -z "$PATHNAMES" ] && usage 1 @@ -55,8 +57,7 @@ mkdir -p "$VARLIB" TMP="$(mktemp -d "$VARLIB/freight.$$.XXXXXXXXXX")" # shellcheck disable=SC2064 trap "rm -rf \"$TMP\"" EXIT INT TERM -for PATHNAME in $PATHNAMES -do +for PATHNAME in $PATHNAMES; do cp "$PATHNAME" "$TMP/" done @@ -69,15 +70,12 @@ cd "$VARLIB" # PATHNAME. The first two are given fairly directly to ln(1); the final one # is used to create appropriate success or failure messages. add() { - if ln "$TMP/$1" "$2/$1" 2>"$TMP/ln" - then echo "# [freight] added $3 to $2${4+" as "}$4" >&2 + if ln "$TMP/$1" "$2/$1" 2>"$TMP/ln"; then echo "# [freight] added $3 to $2${4+" as "}$4" >&2 else - if grep -q "File exists" "$TMP/ln" - then echo "# [freight] $2 already has $3${4+" as "}$4" >&2 + if grep -q "File exists" "$TMP/ln"; then echo "# [freight] $2 already has $3${4+" as "}$4" >&2 else cat "$TMP/ln" >&2 fi - if [ -n "$FREIGHT_ADD_ERROR" ] - then exit 2 + if [ -n "$FREIGHT_ADD_ERROR" ]; then exit 2 fi fi } @@ -85,14 +83,12 @@ add() { # Hard link this package into every `/` given in `$@`. # These links will later be used to compile the `Release` and `Packages` # files in the Freight cache. -for PATHNAME in $PATHNAMES -do +for PATHNAME in $PATHNAMES; do FILENAME="$(basename "$PATHNAME")" - for DIRNAME in "$@" - do + for DIRNAME in "$@"; do mkdir -p "$DIRNAME" case "$FILENAME" in - *_*_*.deb) add "$FILENAME" "$DIRNAME" "$PATHNAME";; + *_*_*.deb) add "$FILENAME" "$DIRNAME" "$PATHNAME" ;; *.deb) . "$(dirname "$(dirname "$0")")/lib/freight/apt.sh" dpkg-deb -I "$TMP/$FILENAME" "control" >"$TMP/$FILENAME-control" @@ -103,8 +99,9 @@ do )_$( apt_binary_arch "$TMP/$FILENAME-control" ).deb" - add "$FILENAME" "$DIRNAME" "$PATHNAME" "$DEBNAME";; - *) add "$FILENAME" "$DIRNAME" "$PATHNAME";; + add "$FILENAME" "$DIRNAME" "$PATHNAME" "$DEBNAME" + ;; + *) add "$FILENAME" "$DIRNAME" "$PATHNAME" ;; esac done done diff --git a/bin/freight-cache b/bin/freight-cache index b5072f3..f1d78a6 100755 --- a/bin/freight-cache +++ b/bin/freight-cache @@ -8,7 +8,7 @@ #/ Usage: freight cache [-k] [-g ] [-p ] [-a ] [-c ] [-v] [-h] [/][...] #/ -k, --keep keep unreferenced versions of packages #/ -g , --gpg= GPG key to use, may be given multiple times -#/ -p , +#/ -p , #/ --passphrase-file= path to file containing the passphrase of the GPG key #/ -a , #/ --digest-algo= digest algorithm that GPG should use, e.g SHA512 @@ -22,44 +22,49 @@ usage() { grep "^#/" "$0" | cut -c"4-" >&2 exit "$1" } -while [ "$#" -gt 0 ] -do +while [ "$#" -gt 0 ]; do case "$1" in - -k|--keep) KEEP=1 shift;; - -g|--gpg) + -k | --keep) KEEP=1 shift ;; + -g | --gpg) if [ -z "$GPG" ]; then GPG=$2 else GPG="$GPG $2" fi - shift 2;; + shift 2 + ;; -g*) if [ -z "$GPG" ]; then GPG=$(echo "$1" | cut -c"3-") else GPG="$GPG $(echo "$1" | cut -c"3-")" fi - shift;; + shift + ;; --gpg=*) if [ -z "$GPG" ]; then GPG=$(echo "$1" | cut -c"7-") else GPG="$GPG $(echo "$1" | cut -c"7-")" fi - shift;; - -p|--passphrase-file) GPG_PASSPHRASE_FILE="$2" shift 2;; - -p*) GPG_PASSPHRASE_FILE="$(echo "$1" | cut -c"3-")" shift;; - --passphrase-file=*) GPG_PASSPHRASE_FILE="$(echo "$1" | cut -c"19-")" shift;; - -a|--digest-algo) GPG_DIGEST_ALGO="$2" shift 2;; - -a*) GPG_DIGEST_ALGO="$(echo "$1" | cut -c"3-")" shift;; - --digest-algo=*) GPG_DIGEST_ALGO="$(echo "$1" | cut -c"15-")" shift;; - -c|--conf) CONF="$2" shift 2;; - -c*) CONF="$(echo "$1" | cut -c"3-")" shift;; - --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift;; - -v|--verbose) VERBOSE=1 shift;; - -h|--help) usage 0;; - -*) echo "# [freight] unknown switch: $1" >&2; usage 1;; - *) break;; + shift + ;; + -p | --passphrase-file) GPG_PASSPHRASE_FILE="$2" shift 2 ;; + -p*) GPG_PASSPHRASE_FILE="$(echo "$1" | cut -c"3-")" shift ;; + --passphrase-file=*) GPG_PASSPHRASE_FILE="$(echo "$1" | cut -c"19-")" shift ;; + -a | --digest-algo) GPG_DIGEST_ALGO="$2" shift 2 ;; + -a*) GPG_DIGEST_ALGO="$(echo "$1" | cut -c"3-")" shift ;; + --digest-algo=*) GPG_DIGEST_ALGO="$(echo "$1" | cut -c"15-")" shift ;; + -c | --conf) CONF="$2" shift 2 ;; + -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; + --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; + -v | --verbose) VERBOSE=1 shift ;; + -h | --help) usage 0 ;; + -*) + echo "# [freight] unknown switch: $1" >&2 + usage 1 + ;; + *) break ;; esac done @@ -86,18 +91,16 @@ mkdir -p "$VARLIB" cd "$VARLIB" # Rebuild each distro serially. -if [ -z "$*" ] -then +if [ -z "$*" ]; then DIRS="$( find "$VARLIB"/ -mindepth 2 -maxdepth 2 -type d -printf "%P\n" | - grep -v "^\\." | - tr "\n" " " + grep -v '^\.' | + tr "\n" " " )" else DIRS=$* fi -for DIR in $DIRS -do +for DIR in $DIRS; do # Parse the manager and distro out of the Freight library path. DIR="$(readlink -f "$DIR")" @@ -115,8 +118,8 @@ do . "$LIB/$MANAGER.sh" SORT="$(sort -V <"/dev/null" 2>"/dev/null" && echo "sort -V" || echo "sort")" find $FIND_L "$DIR" -type "f" -printf "%P\n" 2>"/dev/null" | - eval "$SORT" | - eval "${MANAGER}_cache" "$DIST" + eval "$SORT" | + eval "${MANAGER}_cache" "$DIST" # Clean up old packages as dictated by the manager. if [ -z "$KEEP" ]; then diff --git a/bin/freight-clear-cache b/bin/freight-clear-cache index 2aa9e5a..96a9190 100755 --- a/bin/freight-clear-cache +++ b/bin/freight-clear-cache @@ -15,16 +15,18 @@ usage() { grep "^#/" "$0" | cut -c"4-" >&2 exit "$1" } -while [ "$#" -gt 0 ] -do +while [ "$#" -gt 0 ]; do case "$1" in - -c|--conf) CONF="$2" shift 2;; - -c*) CONF="$(echo "$1" | cut -c"3-")" shift;; - --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift;; - -v|--verbose) VERBOSE=1 shift;; - -h|--help) usage 0;; - -*) echo "# [freight] unknown switch: $1" >&2; usage 1;; - *) break;; + -c | --conf) CONF="$2" shift 2 ;; + -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; + --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; + -v | --verbose) VERBOSE=1 shift ;; + -h | --help) usage 0 ;; + -*) + echo "# [freight] unknown switch: $1" >&2 + usage 1 + ;; + *) break ;; esac done @@ -43,18 +45,16 @@ mkdir -p "$VARLIB" cd "$VARLIB" # Rebuild each distro serially. -if [ -z "$*" ] -then +if [ -z "$*" ]; then DIRS="$( find "$VARLIB" -mindepth 2 -maxdepth 2 -type d -printf "%P\n" | - grep -v "^\\." | - tr "\n" " " + grep -v '^\.' | + tr "\n" " " )" else DIRS=$* fi -for DIR in $DIRS -do +for DIR in $DIRS; do # Parse the manager and distro out of the Freight library path. DIR="$(readlink -f "$DIR")" diff --git a/bin/freight-init b/bin/freight-init index 606e436..867d74e 100755 --- a/bin/freight-init +++ b/bin/freight-init @@ -23,49 +23,54 @@ usage() { grep "^#/" "$0" | cut -c"4-" >&2 exit "$1" } -while [ "$#" -gt 0 ] -do +while [ "$#" -gt 0 ]; do case "$1" in - -g|--gpg) + -g | --gpg) if [ -z "$GPG" ]; then GPG=$2 else GPG="$GPG $2" fi - shift 2;; + shift 2 + ;; -g*) if [ -z "$GPG" ]; then GPG=$(echo "$1" | cut -c"3-") else GPG="$GPG $(echo "$1" | cut -c"3-")" fi - shift;; + shift + ;; --gpg=*) if [ -z "$GPG" ]; then GPG=$(echo "$1" | cut -c"7-") else GPG="$GPG $(echo "$1" | cut -c"7-")" fi - shift;; - -c|--conf) CONF="$2" shift 2;; - -c*) CONF="$(echo "$1" | cut -c"3-")" shift;; - --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift;; - --libdir) VARLIB="$2" shift 2;; - --libdir=*) VARLIB="$(echo "$1" | cut -c"10-")" shift;; - --cachedir) VARCACHE="$2" shift 2;; - --cachedir=*) VARCACHE="$(echo "$1" | cut -c"12-")" shift;; - --archs) ARCHS="$2" shift 2;; - --archs=*) ARCHS="$(echo "$1" | cut -c"9-")" shift;; - --origin) ORIGIN="$2" shift 2;; - --origin=*) ORIGIN="$(echo "$1" | cut -c"10-")" shift;; - --label) LABEL="$2" shift 2;; - --label=*) LABEL="$(echo "$1" | cut -c"9-")" shift;; - --suite) SUITE="$2" shift 2;; - --suite=*) SUITE="$(echo "$1" | cut -c"9-")" shift;; - -v|--verbose) VERBOSE=1 shift;; - -h|--help) usage 0;; - -*) echo "# [freight] unknown switch: $1" >&2; usage 1;; - *) break;; + shift + ;; + -c | --conf) CONF="$2" shift 2 ;; + -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; + --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; + --libdir) VARLIB="$2" shift 2 ;; + --libdir=*) VARLIB="$(echo "$1" | cut -c"10-")" shift ;; + --cachedir) VARCACHE="$2" shift 2 ;; + --cachedir=*) VARCACHE="$(echo "$1" | cut -c"12-")" shift ;; + --archs) ARCHS="$2" shift 2 ;; + --archs=*) ARCHS="$(echo "$1" | cut -c"9-")" shift ;; + --origin) ORIGIN="$2" shift 2 ;; + --origin=*) ORIGIN="$(echo "$1" | cut -c"10-")" shift ;; + --label) LABEL="$2" shift 2 ;; + --label=*) LABEL="$(echo "$1" | cut -c"9-")" shift ;; + --suite) SUITE="$2" shift 2 ;; + --suite=*) SUITE="$(echo "$1" | cut -c"9-")" shift ;; + -v | --verbose) VERBOSE=1 shift ;; + -h | --help) usage 0 ;; + -*) + echo "# [freight] unknown switch: $1" >&2 + usage 1 + ;; + *) break ;; esac done DIRNAME="$(cd "${1:-"."}" && pwd)" diff --git a/lib/freight/apt.sh b/lib/freight/apt.sh index 2b7214f..b5fd9ab 100644 --- a/lib/freight/apt.sh +++ b/lib/freight/apt.sh @@ -1,5 +1,5 @@ if tty -s; then - TTY="1" + TTY="1" fi # Fetch the given field from the package's control file. @@ -99,40 +99,36 @@ apt_cache() { mkdir -p "$VARCACHE/pool/$DIST" # Work through every package that should be part of this distro. - while read -r PATHNAME - do + while read -r PATHNAME; do # Extract the component, if present, from the package's pathname. case "$PATHNAME" in - */*) COMP="${PATHNAME%%/*}" PACKAGE="${PATHNAME##*/}";; - *) COMP="main" PACKAGE="$PATHNAME";; + */*) COMP="${PATHNAME%%/*}" PACKAGE="${PATHNAME##*/}" ;; + *) COMP="main" PACKAGE="$PATHNAME" ;; esac case "$PATHNAME" in # Binary packages. - *.deb) apt_cache_binary "$DIST" "$DISTCACHE" "$PATHNAME" "$COMP" "$PACKAGE";; + *.deb) apt_cache_binary "$DIST" "$DISTCACHE" "$PATHNAME" "$COMP" "$PACKAGE" ;; # Source packages. The *.dsc file is considered the "entrypoint" # and will find the associated *.orig.tar.gz, *.diff.gz, and/or # *.tar.gz as they are needed. - *.dsc) apt_cache_source "$DIST" "$DISTCACHE" "$PATHNAME" "$COMP" "$PACKAGE";; - *.debian.tar.gz|*.debian.tar.bz2|*.debian.tar.xz|*.debian.tar.lzma|*.diff.gz|*.orig.tar.gz|*.orig.tar.bz2|*.orig.tar.xz|*.orig.tar.lzma|*.tar.gz|*.tar.bz2|*.tar.xz|*.tar.lzma|*.deb-control|*.dsc-cached) ;; + *.dsc) apt_cache_source "$DIST" "$DISTCACHE" "$PATHNAME" "$COMP" "$PACKAGE" ;; + *.debian.tar.gz | *.debian.tar.bz2 | *.debian.tar.xz | *.debian.tar.lzma | *.diff.gz | *.orig.tar.gz | *.orig.tar.bz2 | *.orig.tar.xz | *.orig.tar.lzma | *.tar.gz | *.tar.bz2 | *.tar.xz | *.tar.lzma | *.deb-control | *.dsc-cached) ;; - *) echo "# [freight] skipping extraneous file $PATHNAME" >&2;; + *) echo "# [freight] skipping extraneous file $PATHNAME" >&2 ;; esac done COMPS="$(ls "$DISTCACHE")" # Build a `Release` file for each component and architecture. `gzip` # the `Packages` file, too. - for COMP in $COMPS - do + for COMP in $COMPS; do # shellcheck disable=SC2153 - for ARCH in $ARCHS - do - if [ -d "$DISTCACHE/$COMP/binary-$ARCH" ] - then + for ARCH in $ARCHS; do + if [ -d "$DISTCACHE/$COMP/binary-$ARCH" ]; then cat >"$DISTCACHE/$COMP/binary-$ARCH/Release" <"$DISTCACHE/$COMP/binary-$ARCH/Packages.gz" fi done - if [ -d "$DISTCACHE/$COMP/source" ] - then + if [ -d "$DISTCACHE/$COMP/source" ]; then cat >"$DISTCACHE/$COMP/source/Release" <&3 - echo " $(apt_sha1 "$DISTCACHE/$FILE" ) $SIZE $FILE" >&4 - echo " $(apt_sha256 "$DISTCACHE/$FILE" ) $SIZE $FILE" >&5 - echo " $(apt_sha512 "$DISTCACHE/$FILE" ) $SIZE $FILE" >&6 - done 3>"$TMP/md5sums" 4>"$TMP/sha1sums" 5>"$TMP/sha256sums" 6>"$TMP/sha512sums" + grep -v ^\\. | + while read -r FILE; do + SIZE="$(apt_filesize "$DISTCACHE/$FILE")" + echo " $(apt_md5 "$DISTCACHE/$FILE") $SIZE $FILE" >&3 + echo " $(apt_sha1 "$DISTCACHE/$FILE") $SIZE $FILE" >&4 + echo " $(apt_sha256 "$DISTCACHE/$FILE") $SIZE $FILE" >&5 + echo " $(apt_sha512 "$DISTCACHE/$FILE") $SIZE $FILE" >&6 + done 3>"$TMP/md5sums" 4>"$TMP/sha1sums" 5>"$TMP/sha256sums" 6>"$TMP/sha512sums" echo "MD5Sum:" cat "$TMP/md5sums" echo "SHA1:" @@ -219,11 +213,11 @@ EOF $([ "$GPG_PASSPHRASE_FILE" ] && echo " --batch --passphrase-fd 1 --passphrase-file $GPG_PASSPHRASE_FILE") \ $([ "$GPG_DIGEST_ALGO" ] && echo " --personal-digest-preferences $GPG_DIGEST_ALGO") \ -o"$DISTCACHE/Release.gpg" "$DISTCACHE/Release" && - # Create/Sign the top-level `InRelease` file with `gpg` - gpg --clearsign$([ "$TTY" ] || echo " --no-tty") --use-agent ${USERKEYS} \ - $([ "$GPG_PASSPHRASE_FILE" ] && echo " --batch --passphrase-fd 1 --passphrase-file $GPG_PASSPHRASE_FILE") \ - $([ "$GPG_DIGEST_ALGO" ] && echo " --personal-digest-preferences $GPG_DIGEST_ALGO") \ - -o"$DISTCACHE/InRelease" "$DISTCACHE/Release" || { + # Create/Sign the top-level `InRelease` file with `gpg` + gpg --clearsign$([ "$TTY" ] || echo " --no-tty") --use-agent ${USERKEYS} \ + $([ "$GPG_PASSPHRASE_FILE" ] && echo " --batch --passphrase-fd 1 --passphrase-file $GPG_PASSPHRASE_FILE") \ + $([ "$GPG_DIGEST_ALGO" ] && echo " --personal-digest-preferences $GPG_DIGEST_ALGO") \ + -o"$DISTCACHE/InRelease" "$DISTCACHE/Release" || { cat <= 2.1 from using the # new `pubring.kbx` format during an initial `gpg --import`. - : > "$TMP/gpg/pubring.gpg" && chmod 644 "$TMP/gpg/pubring.gpg" + : >"$TMP/gpg/pubring.gpg" && chmod 644 "$TMP/gpg/pubring.gpg" # shellcheck disable=SC2086 gpg -q --export -a $GPG | - tee "$VARCACHE/pubkey.gpg" | - gpg -q --homedir "$TMP/gpg" --import + tee "$VARCACHE/pubkey.gpg" | + gpg -q --homedir "$TMP/gpg" --import mv "$TMP/gpg/pubring.gpg" "$VARCACHE/keyring.gpg" # Move the symbolic link for this distro to this build. @@ -284,8 +278,8 @@ apt_cache_binary() { fi # If caching is off or if the binary has changed size, this will generate the # binary control file - if ! ( [ -e "$CONTROL" ] && \ - [ "$(apt_binary_filesize "$CONTROL")" -eq "$(apt_filesize "$VARLIB/apt/$DIST/$PATHNAME")" ] ); then + if ! ([ -e "$CONTROL" ] && + [ "$(apt_binary_filesize "$CONTROL")" -eq "$(apt_filesize "$VARLIB/apt/$DIST/$PATHNAME")" ]); then dpkg-deb -e "$VARLIB/apt/$DIST/$PATHNAME" "$TMP/DEBIAN" || { echo "# [freight] skipping invalid Debian package $PATHNAME" >&2 return @@ -298,8 +292,8 @@ apt_cache_binary() { # easily later with the real path. Strip out empty control fields # as these might cause problems. grep . "$TMP/DEBIAN/control" | - grep -E -v "^[A-Za-z-]+:\s+$" | - grep -v "^(Essential|Filename|MD5Sum|SHA1|SHA256|SHA512|Size)" + grep -E -v "^[A-Za-z-]+:\s+$" | + grep -v "^(Essential|Filename|MD5Sum|SHA1|SHA256|SHA512|Size)" cat < "$CONTROL" + echo + } >"$CONTROL" fi # Create all architecture-specific directories. This will allow # packages marked `all` to actually be placed in all architectures. - for ARCH in $ARCHS - do + for ARCH in $ARCHS; do mkdir -p "$DISTCACHE/$COMP/binary-$ARCH" touch "$DISTCACHE/$COMP/binary-$ARCH/Packages" done # Link or copy this package into this distro's `.refs` directory. mkdir -p "$DISTCACHE/.refs/$COMP" - ln "$VARLIB/apt/$DIST/$PATHNAME" "$DISTCACHE/.refs/$COMP" > /dev/null 2>&1 || - cp "$VARLIB/apt/$DIST/$PATHNAME" "$DISTCACHE/.refs/$COMP" + ln "$VARLIB/apt/$DIST/$PATHNAME" "$DISTCACHE/.refs/$COMP" >/dev/null 2>&1 || + cp "$VARLIB/apt/$DIST/$PATHNAME" "$DISTCACHE/.refs/$COMP" # Package properties. Remove the epoch from the version number # in the package filename, as is customary. @@ -337,10 +330,8 @@ EOF # Link this package into the pool. POOL="pool/$DIST/$COMP/$PREFIX/$SOURCE" mkdir -p "$VARCACHE/$POOL" - if [ ! -f "$VARCACHE/$POOL/$FILENAME" ] - then - if [ "$PACKAGE" != "$FILENAME" ] - then echo "# [freight] adding $PACKAGE to pool (as $FILENAME)" >&2 + if [ ! -f "$VARCACHE/$POOL/$FILENAME" ]; then + if [ "$PACKAGE" != "$FILENAME" ]; then echo "# [freight] adding $PACKAGE to pool (as $FILENAME)" >&2 else echo "# [freight] adding $PACKAGE to pool" >&2 fi ln "$DISTCACHE/.refs/$COMP/$PACKAGE" "$VARCACHE/$POOL/$FILENAME" @@ -348,8 +339,7 @@ EOF # Build a list of the one-or-more `Packages` files to append with # this package's info. - if [ "$ARCH" = "all" ] - then FILES="$(find "$DISTCACHE/$COMP" -type f -name "Packages")" + if [ "$ARCH" = "all" ]; then FILES="$(find "$DISTCACHE/$COMP" -type f -name "Packages")" else FILES="$DISTCACHE/$COMP/binary-$ARCH/Packages" fi @@ -357,7 +347,7 @@ EOF # package, starting with `pool/`. # shellcheck disable=SC2086 sed "s,^Filename: FILENAME$,Filename: $POOL/$FILENAME,g" "$CONTROL" | - tee -a $FILES >/dev/null + tee -a $FILES >/dev/null # Cleanup the extracted package if [ -d "$TMP/DEBIAN" ]; then @@ -390,14 +380,10 @@ apt_cache_source() { TAR_FILENAME="${NAME}_${VERSION%*:}.tar.gz" # Find which style of diff they're using. - if [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_GZ_FILENAME" ] - then DIFF_FILENAME=${DEBTAR_GZ_FILENAME} - elif [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_BZ2_FILENAME" ] - then DIFF_FILENAME=${DEBTAR_BZ2_FILENAME} - elif [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_XZ_FILENAME" ] - then DIFF_FILENAME=${DEBTAR_XZ_FILENAME} - elif [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_LZMA_FILENAME" ] - then DIFF_FILENAME=${DEBTAR_LZMA_FILENAME} + if [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_GZ_FILENAME" ]; then DIFF_FILENAME=${DEBTAR_GZ_FILENAME} + elif [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_BZ2_FILENAME" ]; then DIFF_FILENAME=${DEBTAR_BZ2_FILENAME} + elif [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_XZ_FILENAME" ]; then DIFF_FILENAME=${DEBTAR_XZ_FILENAME} + elif [ -f "$VARLIB/apt/$DIST/$DIRNAME/$DEBTAR_LZMA_FILENAME" ]; then DIFF_FILENAME=${DEBTAR_LZMA_FILENAME} else DIFF_FILENAME=${DIFFGZ_FILENAME} fi @@ -415,12 +401,11 @@ apt_cache_source() { # if it isn't already there (which can happen when two packages derive # from the same original tarball). mkdir -p "$DISTCACHE/.refs/$COMP" - for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME" - do + for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME"; do [ -f "$VARLIB/apt/$DIST/$DIRNAME/$FILENAME" ] || continue [ -f "$DISTCACHE/.refs/$COMP/$FILENAME" ] || - ln "$VARLIB/apt/$DIST/$DIRNAME/$FILENAME" "$DISTCACHE/.refs/$COMP" > /dev/null 2>&1 || - cp "$VARLIB/apt/$DIST/$DIRNAME/$FILENAME" "$DISTCACHE/.refs/$COMP" + ln "$VARLIB/apt/$DIST/$DIRNAME/$FILENAME" "$DISTCACHE/.refs/$COMP" >/dev/null 2>&1 || + cp "$VARLIB/apt/$DIST/$DIRNAME/$FILENAME" "$DISTCACHE/.refs/$COMP" done # Package properties. Remove the epoch from the version number @@ -429,10 +414,8 @@ apt_cache_source() { # Link this source package into the pool. POOL="pool/$DIST/$COMP/$(apt_prefix "$NAME")/$NAME" mkdir -p "$VARCACHE/$POOL" - for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME" - do - if [ -f "$DISTCACHE/.refs/$COMP/$FILENAME" ] && ! [ -f "$VARCACHE/$POOL/$FILENAME" ] - then + for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME"; do + if [ -f "$DISTCACHE/.refs/$COMP/$FILENAME" ] && ! [ -f "$VARCACHE/$POOL/$FILENAME" ]; then echo "# [freight] adding $FILENAME to pool" >&2 ln "$DISTCACHE/.refs/$COMP/$FILENAME" "$VARCACHE/$POOL" fi @@ -449,49 +432,45 @@ apt_cache_source() { if ! [ -e "$CONTROL" ]; then { grep -E "^[A-Z][^:]+: ." "$VARLIB/apt/$DIST/$PATHNAME" | - grep -E -v "^(Version: GnuPG|Hash: )" | - sed "s/^Source:/Package:/" + grep -E -v "^(Version: GnuPG|Hash: )" | + sed "s/^Source:/Package:/" echo "Directory: DIRECTORY" echo "Files:" - for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME" - do + for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME"; do [ -f "$VARCACHE/$POOL/$FILENAME" ] || continue SIZE="$(apt_filesize "$VARCACHE/$POOL/$FILENAME")" MD5="$(apt_md5 "$VARCACHE/$POOL/$FILENAME")" echo " $MD5 $SIZE $FILENAME" done echo "Checksums-Sha1:" - for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME" - do + for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME"; do [ -f "$VARCACHE/$POOL/$FILENAME" ] || continue SIZE="$(apt_filesize "$VARCACHE/$POOL/$FILENAME")" SHA1="$(apt_sha1 "$VARCACHE/$POOL/$FILENAME")" echo " $SHA1 $SIZE $FILENAME" done echo "Checksums-Sha256:" - for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME" - do + for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME"; do [ -f "$VARCACHE/$POOL/$FILENAME" ] || continue SIZE="$(apt_filesize "$VARCACHE/$POOL/$FILENAME")" SHA256="$(apt_sha256 "$VARCACHE/$POOL/$FILENAME")" echo " $SHA256 $SIZE $FILENAME" done echo "Checksums-Sha512:" - for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME" - do + for FILENAME in "$DSC_FILENAME" "$ORIG_FILENAME" "$DIFF_FILENAME" "$TAR_FILENAME"; do [ -f "$VARCACHE/$POOL/$FILENAME" ] || continue SIZE="$(apt_filesize "$VARCACHE/$POOL/$FILENAME")" SHA512="$(apt_sha512 "$VARCACHE/$POOL/$FILENAME")" echo " $SHA512 $SIZE $FILENAME" done echo - } > "$CONTROL" + } >"$CONTROL" fi sed "s,^Directory: DIRECTORY$,Directory: $POOL,g" "$CONTROL" | - tee -a "$DISTCACHE/$COMP/source/Sources" >/dev/null + tee -a "$DISTCACHE/$COMP/source/Sources" >/dev/null -# Clean up the tmp space + # Clean up the tmp space if [ -f "$TMP/source-control" ]; then rm "$TMP/source-control" fi diff --git a/lib/freight/conf.sh b/lib/freight/conf.sh index 9a987b5..07bdaaa 100644 --- a/lib/freight/conf.sh +++ b/lib/freight/conf.sh @@ -29,24 +29,20 @@ SYMLINKS="off" # Source all existing configuration files from lowest- to highest-priority. PREFIX="$(dirname "$(dirname "$0")")" -if [ "$PREFIX" = "/usr" ] -then [ -f "/etc/freight.conf" ] && . "/etc/freight.conf" +if [ "$PREFIX" = "/usr" ]; then [ -f "/etc/freight.conf" ] && . "/etc/freight.conf" else [ -f "$PREFIX/etc/freight.conf" ] && . "$PREFIX/etc/freight.conf" fi [ -f "$HOME/.freight.conf" ] && . "$HOME/.freight.conf" DIRNAME="$PWD" -while true -do +while true; do [ -f "$DIRNAME/etc/freight.conf" ] && . "$DIRNAME/etc/freight.conf" && break [ -f "$DIRNAME/.freight.conf" ] && . "$DIRNAME/.freight.conf" && break [ "$DIRNAME" = "/" ] && break DIRNAME="$(dirname "$DIRNAME")" done [ "$FREIGHT_CONF" ] && [ -f "$FREIGHT_CONF" ] && . "$FREIGHT_CONF" -if [ "$CONF" ] -then - if [ -f "$CONF" ] - then . "$CONF" +if [ "$CONF" ]; then + if [ -f "$CONF" ]; then . "$CONF" else echo "# [freight] $CONF does not exist" >&2 exit 1