Silence shellcheck warnings (#255)

* Made more specific shellcheck disables
* Fixed variable quoting (SC2086,SC2064)
* Use `$*` expansion instead of `$@` when not using arrays (SC2124)
* Use cleaner `$()` syntax instead of back quotes (SC2006)
* Improved comparator (SC2166)
* Minor improvements in coding style

Tested clean output using: `find -name "*.sh" | xargs -n1 shellcheck -x`.
pull/262/head
Hugo Hromic 2019-02-18 12:54:15 +00:00 committed by XECDesign
parent 7068086c94
commit 564f8ef1b8
4 changed files with 21 additions and 15 deletions

View File

@ -1,11 +1,10 @@
#!/bin/bash -e #!/bin/bash -e
BUILD_OPTS="$@" BUILD_OPTS="$*"
DOCKER="docker" DOCKER="docker"
set +e set +e
$DOCKER ps >/dev/null 2>&1 if ! $DOCKER ps >/dev/null 2>&1; then
if [ $? != 0 ]; then
DOCKER="sudo docker" DOCKER="sudo docker"
fi fi
if ! $DOCKER ps >/dev/null; then if ! $DOCKER ps >/dev/null; then
@ -23,8 +22,11 @@ while getopts "c:" flag
do do
case "$flag" in case "$flag" in
c) c)
# shellcheck disable=SC1090
source "$OPTARG" source "$OPTARG"
;; ;;
*)
;;
esac esac
done done
@ -53,7 +55,7 @@ fi
$DOCKER build -t pi-gen . $DOCKER build -t pi-gen .
if [ "$CONTAINER_EXISTS" != "" ]; then if [ "$CONTAINER_EXISTS" != "" ]; then
trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}_cont" SIGINT SIGTERM trap 'echo "got CTRL+C... please wait 5s"; $DOCKER stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
time $DOCKER run --rm --privileged \ time $DOCKER run --rm --privileged \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \ --volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
pi-gen \ pi-gen \
@ -62,7 +64,7 @@ if [ "$CONTAINER_EXISTS" != "" ]; then
rsync -av work/*/build.log deploy/" & rsync -av work/*/build.log deploy/" &
wait "$!" wait "$!"
else else
trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}" SIGINT SIGTERM trap 'echo "got CTRL+C... please wait 5s"; $DOCKER stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
time $DOCKER run --name "${CONTAINER_NAME}" --privileged \ time $DOCKER run --name "${CONTAINER_NAME}" --privileged \
pi-gen \ pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
@ -76,7 +78,7 @@ ls -lah deploy
# cleanup # cleanup
if [ "$PRESERVE_CONTAINER" != "1" ]; then if [ "$PRESERVE_CONTAINER" != "1" ]; then
$DOCKER rm -v $CONTAINER_NAME $DOCKER rm -v "$CONTAINER_NAME"
fi fi
echo "Done! Your image(s) should be in deploy/" echo "Done! Your image(s) should be in deploy/"

View File

@ -1,5 +1,5 @@
#!/bin/bash -e #!/bin/bash -e
# shellcheck disable=SC2119,SC1091 # shellcheck disable=SC2119
run_sub_stage() run_sub_stage()
{ {
log "Begin ${SUB_STAGE_DIR}" log "Begin ${SUB_STAGE_DIR}"
@ -102,7 +102,7 @@ run_stage(){
./prerun.sh ./prerun.sh
log "End ${STAGE_DIR}/prerun.sh" log "End ${STAGE_DIR}/prerun.sh"
fi fi
for SUB_STAGE_DIR in ${STAGE_DIR}/*; do for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
if [ -d "${SUB_STAGE_DIR}" ] && if [ -d "${SUB_STAGE_DIR}" ] &&
[ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
run_sub_stage run_sub_stage
@ -124,6 +124,7 @@ fi
if [ -f config ]; then if [ -f config ]; then
# shellcheck disable=SC1091
source config source config
fi fi
@ -132,8 +133,11 @@ do
case "$flag" in case "$flag" in
c) c)
EXTRA_CONFIG="$OPTARG" EXTRA_CONFIG="$OPTARG"
# shellcheck disable=SC1090
source "$EXTRA_CONFIG" source "$EXTRA_CONFIG"
;; ;;
*)
;;
esac esac
done done
@ -206,8 +210,8 @@ log "Begin ${BASE_DIR}"
STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*} STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*}
for STAGE_DIR_ in $STAGE_LIST; do for STAGE_DIR in $STAGE_LIST; do
STAGE_DIR=`realpath "${STAGE_DIR_}"` STAGE_DIR=$(realpath "${STAGE_DIR}")
run_stage run_stage
done done

View File

@ -3,6 +3,7 @@
set -ex set -ex
# shellcheck disable=SC2154
if [ -z "$part1" ] || [ -z "$part2" ]; then if [ -z "$part1" ] || [ -z "$part2" ]; then
printf "Error: missing environment variable part1 or part2\n" 1>&2 printf "Error: missing environment variable part1 or part2\n" 1>&2
exit 1 exit 1
@ -17,7 +18,8 @@ sed /tmp/1/cmdline.txt -i -e "s|root=[^ ]*|root=${part2}|"
sed /tmp/2/etc/fstab -i -e "s|^[^#].* / |${part2} / |" sed /tmp/2/etc/fstab -i -e "s|^[^#].* / |${part2} / |"
sed /tmp/2/etc/fstab -i -e "s|^[^#].* /boot |${part1} /boot |" sed /tmp/2/etc/fstab -i -e "s|^[^#].* /boot |${part1} /boot |"
if [ -z $restore ]; then # shellcheck disable=SC2154
if [ -z "$restore" ]; then
if [ -f /mnt/ssh ]; then if [ -f /mnt/ssh ]; then
cp /mnt/ssh /tmp/1/ cp /mnt/ssh /tmp/1/
fi fi

View File

@ -6,13 +6,11 @@ install -v -m 644 files/wait.conf "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.serv
install -v -d "${ROOTFS_DIR}/etc/wpa_supplicant" install -v -d "${ROOTFS_DIR}/etc/wpa_supplicant"
install -v -m 600 files/wpa_supplicant.conf "${ROOTFS_DIR}/etc/wpa_supplicant/" install -v -m 600 files/wpa_supplicant.conf "${ROOTFS_DIR}/etc/wpa_supplicant/"
if [ -v WPA_COUNTRY ] if [ -v WPA_COUNTRY ]; then
then
echo "country=${WPA_COUNTRY}" >> "${ROOTFS_DIR}/etc/wpa_supplicant/wpa_supplicant.conf" echo "country=${WPA_COUNTRY}" >> "${ROOTFS_DIR}/etc/wpa_supplicant/wpa_supplicant.conf"
fi fi
if [ -v WPA_ESSID -a -v WPA_PASSWORD ] if [ -v WPA_ESSID ] && [ -v WPA_PASSWORD ]; then
then
on_chroot <<EOF on_chroot <<EOF
wpa_passphrase "${WPA_ESSID}" "${WPA_PASSWORD}" >> "/etc/wpa_supplicant/wpa_supplicant.conf" wpa_passphrase "${WPA_ESSID}" "${WPA_PASSWORD}" >> "/etc/wpa_supplicant/wpa_supplicant.conf"
EOF EOF