Skip to content

Commit 2d2a349

Browse files
author
Jacob Hrbek
committed
ci/before-install: Attempt to improve Code Quality
I'm forking this configuration in https://github.com/Kreyrock/Kreyrock so i rewrote it to what i consider better code quality excluding over-sanitization in this scenario. - Now this is compatible with POSIX shell and bash - Fixed Shellcheck excluding SC1090 since i don't know where the source for it is (probably in docker image to which we don't have an access?) - Unset variables since shell doesn't support `local var=value` - Added simplified error handling - Replaced echo with printf which is sligtly faster (https://unix.stackexchange.com/a/77564) and more reliable POSIX and cross-platform (https://unix.stackexchange.com/a/65819) - Rewrote if statements to be more readable - Replaced ${var} with $var since they are not needed and still require double quoting Signed-off-by: Jacob Hrbek <[email protected]>
1 parent 3e670ff commit 2d2a349

File tree

1 file changed

+77
-70
lines changed

1 file changed

+77
-70
lines changed

ci/before-install

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22
#
33
# Travis CI Scripts
44
# Copyright (C) 2018-2019 by Thomas Dreibholz
@@ -18,76 +18,83 @@
1818
#
1919
2020

21-
# Bash options:
21+
# Shell options:
2222
set -e
2323

24-
25-
. `dirname $0`/get-container
26-
27-
28-
# ###### Linux as-is ########################################################
29-
if [ "${TRAVIS_OS_NAME}" == "linux" -a "${DOCKER}" == "" -a "${QEMU}" == "" ] ; then
30-
31-
# Nothing to be done here.
32-
true
33-
34-
35-
# ###### Linux via Docker ###################################################
36-
elif [ "${TRAVIS_OS_NAME}" == "linux" -a "${DOCKER}" != "" -a "${QEMU}" == "" ] ; then
37-
38-
# NOTE: Using tmpfs for pbuilder and mock!
39-
# The build machine therefore needs a sufficient amount of RAM!
40-
sudo docker rm -f ${CONTAINER} || true
41-
sudo docker run -d \
42-
--name ${CONTAINER} \
43-
--tmpfs /var/cache/pbuilder:rw,exec,dev,size=4g \
44-
--tmpfs /var/lib/mock:rw,exec,dev,size=4g \
45-
--cap-add=SYS_ADMIN --cap-add=NET_ADMIN \
46-
--security-opt apparmor:unconfined \
47-
-v $(pwd):/travis -w /travis \
48-
$DOCKER tail -f /dev/null
49-
sudo docker ps
50-
51-
52-
# ###### FreeBSD via QEMU ###################################################
53-
elif [ "${TRAVIS_OS_NAME}" == "linux" -a "${QEMU}" == "FreeBSD" ] ; then
54-
if [ "${VARIANT}" != "" ] ; then
55-
56-
sudo mkdir -p /vservers/qemu-freebsd
57-
sudo chown $USER:$USER /vservers/qemu-freebsd
58-
mkdir -p /vservers/qemu-freebsd/mnt
59-
cd /vservers/qemu-freebsd
60-
61-
# ====== Download image ============================================
62-
imageName="FreeBSD-${VARIANT}-amd64.raw"
63-
if [ -e ${imageName}.xz -a ! -e ${imageName} ] ; then
64-
echo "Extracting existing ${imageName}.xz ..."
65-
xz -T0 -dk ${imageName}.xz
66-
elif [ ! -e ${imageName}.xz -o ! -e ${imageName} ] ; then
67-
imageURL="https://download.freebsd.org/ftp/releases/VM-IMAGES/${VARIANT}/amd64/Latest/${imageName}.xz"
68-
echo "Downloading FreeBSD VM image from ${imageURL} ..."
69-
curl "${imageURL}" | tee ${imageName}.xz.tmp | xz -T0 -d - >${imageName}
70-
mv ${imageName}.xz.tmp ${imageName}.xz
71-
fi
72-
73-
# ====== Download fuse-ufs2 ========================================
74-
if [ ! -d fuse-ufs2/ ] ; then
75-
echo "Downloading fuse-ufs2 ..."
76-
git clone https://github.com/dreibh/fuse-ufs2 -b dreibh/ubuntu-disco-fix
77-
# git clone https://github.com/mkatiyar/fuse-ufs2
78-
fi
79-
fi
80-
81-
82-
# ###### MacOS X ############################################################
83-
elif [ "${TRAVIS_OS_NAME}" == "osx" ] ; then
84-
85-
# Nothing to be done here.
86-
true
87-
88-
89-
# ###### Error ##############################################################
24+
# Simplified error handling
25+
die() {
26+
printf 'FATAL: %s\n' "$*"
27+
exit 1
28+
}
29+
info() {
30+
printf 'FATAL: %s\n' "$?"
31+
}
32+
33+
# shellcheck source=ci/get-container
34+
. "$(dirname $0)/get-container"
35+
36+
37+
# Linux as-is
38+
if [ "$TRAVIS_OS_NAME" = linux ] && [ -z "$DOCKER" ] && [ -z "$QEMU" ]; then
39+
40+
# Nothing to be done here.
41+
true
42+
43+
# Linux via Docker
44+
elif [ "$TRAVIS_OS_NAME" = linux ] && [ -n "$DOCKER" ] && [ -n "$QEMU" ]; then
45+
46+
# NOTE: Using tmpfs for pbuilder and mock!
47+
# The build machine therefore needs a sufficient amount of RAM!
48+
[ -e "$CONTAINER" ] && sudo docker rm -f "$CONTAINER"
49+
sudo docker run -d \
50+
--name "$CONTAINER" \
51+
--tmpfs /var/cache/pbuilder:rw,exec,dev,size=4g \
52+
--tmpfs /var/lib/mock:rw,exec,dev,size=4g \
53+
--cap-add=SYS_ADMIN --cap-add=NET_ADMIN \
54+
--security-opt apparmor:unconfined \
55+
-v "$(pwd):/travis" -w /travis \
56+
"$DOCKER" tail -f /dev/null
57+
sudo docker ps
58+
59+
60+
# FreeBSD via QEMU
61+
elif [ "$TRAVIS_OS_NAME" = linux ] && [ "$QEMU" = FreeBSD ]; then
62+
if [ -n "$VARIANT" ]; then
63+
sudo mkdir -p /vservers/qemu-freebsd
64+
sudo chown "$USER:$USER" /vservers/qemu-freebsd
65+
mkdir -p /vservers/qemu-freebsd/mnt
66+
cd /vservers/qemu-freebsd || die "Unable to change directory in '/vservers/qemu-freebsd'"
67+
68+
# ====== Download image ============================================
69+
imageName="FreeBSD-$VARIANT-amd64.raw"
70+
if [ -e "$imageName.xz" ] && [ ! -e "$imageName" ]; then
71+
info "Extracting existing $imageName.xz ..."
72+
xz -T0 -dk "$imageName.xz"
73+
elif [ ! -e "$imageName.xz" ] || [ ! -e "$imageName" ]; then
74+
imageURL="https://download.freebsd.org/ftp/releases/VM-IMAGES/$VARIANT/amd64/Latest/$imageName.xz"
75+
info "Downloading FreeBSD VM image from $imageURL ..."
76+
curl "$imageURL" | tee "$imageName.xz.tmp" | xz -T0 -d - ">$imageName"
77+
mv "$imageName.xz.tmp" "$imageName.xz"
78+
fi
79+
80+
# ====== Download fuse-ufs2 ========================================
81+
if [ ! -d fuse-ufs2/ ]; then
82+
info "Downloading fuse-ufs2 ..."
83+
git clone https://github.com/dreibh/fuse-ufs2 -b dreibh/ubuntu-disco-fix
84+
# git clone https://github.com/mkatiyar/fuse-ufs2
85+
fi
86+
87+
unset imageName imageURL
88+
fi
89+
90+
91+
# MacOS X
92+
elif [ "$TRAVIS_OS_NAME" = osx ]; then
93+
94+
# Nothing to be done here.
95+
true
96+
97+
# Error
9098
else
91-
echo >&2 "ERROR: Invalid setting of TRAVIS_OS_NAME=${TRAVIS_OS_NAME}, DOCKER=${DOCKER}, QEMU=${QEMU}!"
92-
exit 1
99+
die "Invalid setting of TRAVIS_OS_NAME=$TRAVIS_OS_NAME, DOCKER=$DOCKER, QEMU=$QEMU!"
93100
fi

0 commit comments

Comments
 (0)