Skip to content

Commit

Permalink
use shfmt and add it to travis
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoll committed Apr 11, 2018
1 parent 105c1dc commit 92dc0e2
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 190 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -91,8 +91,12 @@ Freight is [BSD-licensed](https://github.com/freight-team/freight/blob/master/LI
* Issue tracker: <https://github.com/freight-team/freight/issues>
* Wiki: <https://github.com/freight-team/freight/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.
59 changes: 28 additions & 31 deletions bin/freight-add
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 `<manager>/<distro>` 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
Expand All @@ -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

Expand All @@ -69,30 +70,25 @@ 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
}

# Hard link this package into every `<manager>/<distro>` 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"
Expand All @@ -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
Expand Down
61 changes: 32 additions & 29 deletions bin/freight-cache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#/ Usage: freight cache [-k] [-g <email>] [-p <passphrase-file>] [-a <digest-algorithm>] [-c <conf>] [-v] [-h] [<manager>/<distro>][...]
#/ -k, --keep keep unreferenced versions of packages
#/ -g <email>, --gpg=<email> GPG key to use, may be given multiple times
#/ -p <passphrase file>,
#/ -p <passphrase file>,
#/ --passphrase-file=<passphrase-file> path to file containing the passphrase of the GPG key
#/ -a <digest algorithm>,
#/ --digest-algo=<digest-algorithm> digest algorithm that GPG should use, e.g SHA512
Expand All @@ -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

Expand All @@ -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")"
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions bin/freight-clear-cache
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")"
Expand Down
55 changes: 30 additions & 25 deletions bin/freight-init
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
Loading

0 comments on commit 92dc0e2

Please sign in to comment.