From ff2d5edee18efbb7ba2498e5bf8d308c186c4866 Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Fri, 2 Mar 2018 20:08:24 +0000 Subject: [PATCH] shellcheck --- build-docker.sh | 4 +- build.sh | 93 ++++++++++++++------------ export-image/00-allow-rerun/00-run.sh | 4 +- export-image/02-network/01-run.sh | 2 +- export-image/03-set-partuuid/00-run.sh | 8 +-- export-image/04-finalise/01-run.sh | 81 +++++++++++----------- export-image/prerun.sh | 34 +++++----- export-noobs/00-release/00-run.sh | 44 ++++++------ export-noobs/prerun.sh | 30 ++++----- scripts/common | 6 +- scripts/dependencies_check | 4 +- stage0/00-configure-apt/00-run.sh | 10 +-- stage0/prerun.sh | 4 +- stage1/00-boot-files/00-run.sh | 4 +- stage1/01-sys-tweaks/00-run.sh | 6 +- stage1/02-net-tweaks/00-run.sh | 6 +- stage1/prerun.sh | 2 +- stage2/01-sys-tweaks/01-run.sh | 18 ++--- stage2/02-net-tweaks/01-run.sh | 8 +-- stage2/prerun.sh | 2 +- stage3/01-tweaks/00-run.sh | 2 +- stage3/prerun.sh | 2 +- stage4/01-console-autologin/00-run.sh | 3 +- stage4/02-extras/00-run.sh | 16 ++--- stage4/prerun.sh | 2 +- stage5/prerun.sh | 2 +- 26 files changed, 203 insertions(+), 194 deletions(-) diff --git a/build-docker.sh b/build-docker.sh index b683d4b..16d20f5 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -57,7 +57,7 @@ if [ "$CONTAINER_EXISTS" != "" ]; then trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}_cont" SIGINT SIGTERM time $DOCKER run --rm --privileged \ --volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \ - -e IMG_NAME=${IMG_NAME}\ + -e IMG_NAME="${IMG_NAME}"\ pi-gen \ bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && cd /pi-gen; ./build.sh; @@ -66,7 +66,7 @@ if [ "$CONTAINER_EXISTS" != "" ]; then else trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}" SIGINT SIGTERM time $DOCKER run --name "${CONTAINER_NAME}" --privileged \ - -e IMG_NAME=${IMG_NAME}\ + -e IMG_NAME="${IMG_NAME}"\ "${config_file[@]}" \ pi-gen \ bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && diff --git a/build.sh b/build.sh index d72d4f5..f0597b7 100755 --- a/build.sh +++ b/build.sh @@ -1,22 +1,23 @@ #!/bin/bash -e - +# shellcheck disable=SC2119,SC1091 run_sub_stage() { log "Begin ${SUB_STAGE_DIR}" - pushd ${SUB_STAGE_DIR} > /dev/null + pushd "${SUB_STAGE_DIR}" > /dev/null for i in {00..99}; do - if [ -f ${i}-debconf ]; then + if [ -f "${i}-debconf" ]; then log "Begin ${SUB_STAGE_DIR}/${i}-debconf" on_chroot << EOF debconf-set-selections < /dev/null + pushd "${STAGE_WORK_DIR}" > /dev/null if [ "${CLEAN}" = "1" ]; then rm -rf .pc - rm -rf *-pc + rm -rf "./*-pc" fi - QUILT_PATCHES=${SUB_STAGE_DIR}/${i}-patches - SUB_STAGE_QUILT_PATCH_DIR="$(basename $SUB_STAGE_DIR)-pc" - mkdir -p $SUB_STAGE_QUILT_PATCH_DIR - ln -snf $SUB_STAGE_QUILT_PATCH_DIR .pc - if [ -e ${SUB_STAGE_DIR}/${i}-patches/EDIT ]; then + QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches" + SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc" + mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR" + ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc + if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then echo "Dropping into bash to edit patches..." bash fi @@ -80,20 +81,20 @@ EOF run_stage(){ log "Begin ${STAGE_DIR}" - STAGE=$(basename ${STAGE_DIR}) - pushd ${STAGE_DIR} > /dev/null - unmount ${WORK_DIR}/${STAGE} - STAGE_WORK_DIR=${WORK_DIR}/${STAGE} - ROOTFS_DIR=${STAGE_WORK_DIR}/rootfs + STAGE="$(basename "${STAGE_DIR}")" + pushd "${STAGE_DIR}" > /dev/null + unmount "${WORK_DIR}/${STAGE}" + STAGE_WORK_DIR="${WORK_DIR}/${STAGE}" + ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs if [ ! -f SKIP_IMAGES ]; then - if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then + if [ -f "${STAGE_DIR}/EXPORT_IMAGE" ]; then EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}" fi fi if [ ! -f SKIP ]; then if [ "${CLEAN}" = "1" ]; then - if [ -d ${ROOTFS_DIR} ]; then - rm -rf ${ROOTFS_DIR} + if [ -d "${ROOTFS_DIR}" ]; then + rm -rf "${ROOTFS_DIR}" fi fi if [ -x prerun.sh ]; then @@ -102,16 +103,16 @@ run_stage(){ log "End ${STAGE_DIR}/prerun.sh" fi for SUB_STAGE_DIR in ${STAGE_DIR}/*; do - if [ -d ${SUB_STAGE_DIR} ] && - [ ! -f ${SUB_STAGE_DIR}/SKIP ]; then + if [ -d "${SUB_STAGE_DIR}" ] && + [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then run_sub_stage fi done fi - unmount ${WORK_DIR}/${STAGE} - PREV_STAGE=${STAGE} - PREV_STAGE_DIR=${STAGE_DIR} - PREV_ROOTFS_DIR=${ROOTFS_DIR} + unmount "${WORK_DIR}/${STAGE}" + PREV_STAGE="${STAGE}" + PREV_STAGE_DIR="${STAGE_DIR}" + PREV_ROOTFS_DIR="${ROOTFS_DIR}" popd > /dev/null log "End ${STAGE_DIR}" } @@ -131,15 +132,17 @@ if [ -z "${IMG_NAME}" ]; then exit 1 fi -export USE_QEMU=${USE_QEMU:-0} -export IMG_DATE=${IMG_DATE:-"$(date +%Y-%m-%d)"} +export USE_QEMU="${USE_QEMU:-0}" +export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}" -export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export SCRIPT_DIR="${BASE_DIR}/scripts" -export WORK_DIR=${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"} +export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}" export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"} export LOG_FILE="${WORK_DIR}/build.log" +export BASE_DIR + export CLEAN export IMG_NAME export APT_PROXY @@ -162,29 +165,33 @@ export QUILT_NO_DIFF_INDEX=1 export QUILT_NO_DIFF_TIMESTAMPS=1 export QUILT_REFRESH_ARGS="-p ab" -source ${SCRIPT_DIR}/common -source ${SCRIPT_DIR}/dependencies_check +# shellcheck source=scripts/common +source "${SCRIPT_DIR}/common" +# shellcheck source=scripts/dependencies_check +source "${SCRIPT_DIR}/dependencies_check" -dependencies_check ${BASE_DIR}/depends +dependencies_check "${BASE_DIR}/depends" -mkdir -p ${WORK_DIR} +mkdir -p "${WORK_DIR}" log "Begin ${BASE_DIR}" -for STAGE_DIR in ${BASE_DIR}/stage*; do +for STAGE_DIR in "${BASE_DIR}/stage"*; do run_stage done CLEAN=1 for EXPORT_DIR in ${EXPORT_DIRS}; do STAGE_DIR=${BASE_DIR}/export-image + # shellcheck source=/dev/null source "${EXPORT_DIR}/EXPORT_IMAGE" - EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename ${EXPORT_DIR})/rootfs + EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs run_stage if [ "${USE_QEMU}" != "1" ]; then - if [ -e ${EXPORT_DIR}/EXPORT_NOOBS ]; then - source ${EXPORT_DIR}/EXPORT_NOOBS - STAGE_DIR=${BASE_DIR}/export-noobs + if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then + # shellcheck source=/dev/null + source "${EXPORT_DIR}/EXPORT_NOOBS" + STAGE_DIR="${BASE_DIR}/export-noobs" run_stage fi fi diff --git a/export-image/00-allow-rerun/00-run.sh b/export-image/00-allow-rerun/00-run.sh index b77c30e..f7c5b4e 100755 --- a/export-image/00-allow-rerun/00-run.sh +++ b/export-image/00-allow-rerun/00-run.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -x ${ROOTFS_DIR}/usr/bin/qemu-arm-static ]; then - cp /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/ +if [ ! -x "${ROOTFS_DIR}/usr/bin/qemu-arm-static" ]; then + cp /usr/bin/qemu-arm-static "${ROOTFS_DIR}/usr/bin/" fi diff --git a/export-image/02-network/01-run.sh b/export-image/02-network/01-run.sh index e21b791..4150732 100755 --- a/export-image/02-network/01-run.sh +++ b/export-image/02-network/01-run.sh @@ -1,3 +1,3 @@ #!/bin/bash -e -install -m 644 files/resolv.conf ${ROOTFS_DIR}/etc/ +install -m 644 files/resolv.conf "${ROOTFS_DIR}/etc/" diff --git a/export-image/03-set-partuuid/00-run.sh b/export-image/03-set-partuuid/00-run.sh index 4b18405..29edc67 100755 --- a/export-image/03-set-partuuid/00-run.sh +++ b/export-image/03-set-partuuid/00-run.sh @@ -2,12 +2,12 @@ IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img" -IMGID="$(dd if=${IMG_FILE} skip=440 bs=1 count=4 2>/dev/null | xxd -e | cut -f 2 -d' ')" +IMGID="$(dd if="${IMG_FILE}" skip=440 bs=1 count=4 2>/dev/null | xxd -e | cut -f 2 -d' ')" BOOT_PARTUUID="${IMGID}-01" ROOT_PARTUUID="${IMGID}-02" -sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" ${ROOTFS_DIR}/etc/fstab -sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" ${ROOTFS_DIR}/etc/fstab +sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" +sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" -sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" ${ROOTFS_DIR}/boot/cmdline.txt +sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${ROOTFS_DIR}/boot/cmdline.txt" diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index b093f01..b706774 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -8,74 +8,75 @@ on_chroot << EOF hardlink -t /usr/share/doc EOF -if [ -d ${ROOTFS_DIR}/home/pi/.config ]; then - chmod 700 ${ROOTFS_DIR}/home/pi/.config +if [ -d "${ROOTFS_DIR}/home/pi/.config" ]; then + chmod 700 "${ROOTFS_DIR}/home/pi/.config" fi -rm -f ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache -rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static +rm -f "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache" +rm -f "${ROOTFS_DIR}/usr/bin/qemu-arm-static" -rm -f ${ROOTFS_DIR}/etc/apt/sources.list~ -rm -f ${ROOTFS_DIR}/etc/apt/trusted.gpg~ +rm -f "${ROOTFS_DIR}/etc/apt/sources.list~" +rm -f "${ROOTFS_DIR}/etc/apt/trusted.gpg~" -rm -f ${ROOTFS_DIR}/etc/passwd- -rm -f ${ROOTFS_DIR}/etc/group- -rm -f ${ROOTFS_DIR}/etc/shadow- -rm -f ${ROOTFS_DIR}/etc/gshadow- +rm -f "${ROOTFS_DIR}/etc/passwd-" +rm -f "${ROOTFS_DIR}/etc/group-" +rm -f "${ROOTFS_DIR}/etc/shadow-" +rm -f "${ROOTFS_DIR}/etc/gshadow-" -rm -f ${ROOTFS_DIR}/var/cache/debconf/*-old -rm -f ${ROOTFS_DIR}/var/lib/dpkg/*-old +rm -f "${ROOTFS_DIR}/var/cache/debconf/*-old" +rm -f "${ROOTFS_DIR}/var/lib/dpkg/*-old" -rm -f ${ROOTFS_DIR}/usr/share/icons/*/icon-theme.cache +rm -f "${ROOTFS_DIR}/usr/share/icons/*/icon-theme.cache" -rm -f ${ROOTFS_DIR}/var/lib/dbus/machine-id +rm -f "${ROOTFS_DIR}/var/lib/dbus/machine-id" -true > ${ROOTFS_DIR}/etc/machine-id +true > "${ROOTFS_DIR}/etc/machine-id" -ln -nsf /proc/mounts ${ROOTFS_DIR}/etc/mtab +ln -nsf /proc/mounts "${ROOTFS_DIR}/etc/mtab" -for _FILE in $(find ${ROOTFS_DIR}/var/log/ -type f); do - true > ${_FILE} -done +find "${ROOTFS_DIR}/var/log/" -type f -exec cp /dev/null {} \; rm -f "${ROOTFS_DIR}/root/.vnc/private.key" rm -f "${ROOTFS_DIR}/etc/vnc/updateid" -update_issue $(basename ${EXPORT_DIR}) -install -m 644 ${ROOTFS_DIR}/etc/rpi-issue ${ROOTFS_DIR}/boot/issue.txt -install files/LICENSE.oracle ${ROOTFS_DIR}/boot/ +update_issue "$(basename "${EXPORT_DIR}")" +install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/issue.txt" +install files/LICENSE.oracle "${ROOTFS_DIR}/boot/" cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" -firmware=$(zgrep "firmware as of" "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" | \ - head -n1 | \ - sed -n 's|.* \([^ ]*\)$|\1|p') -printf "\nFirmware: https://github.com/raspberrypi/firmware/tree/%s\n" "$firmware" >> "$INFO_FILE" +{ + firmware=$(zgrep "firmware as of" \ + "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" | \ + head -n1 | sed -n 's|.* \([^ ]*\)$|\1|p') + printf "\nFirmware: https://github.com/raspberrypi/firmware/tree/%s\n" "$firmware" -kernel=$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/git_hash") -printf "Kernel: https://github.com/raspberrypi/linux/tree/%s\n" "$kernel" >> "$INFO_FILE" + kernel="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/git_hash")" + printf "Kernel: https://github.com/raspberrypi/linux/tree/%s\n" "$kernel" -uname=$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/uname_string7") -printf "Uname string: %s\n" "$uname" >> "$INFO_FILE" + uname="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/uname_string7")" -printf "\nPackages:\n">> "$INFO_FILE" -dpkg -l --root "$ROOTFS_DIR" >> "$INFO_FILE" + printf "Uname string: %s\n" "$uname" + printf "\nPackages:\n" + dpkg -l --root "$ROOTFS_DIR" +} >> "$INFO_FILE" -ROOT_DEV=$(mount | grep "${ROOTFS_DIR} " | cut -f1 -d' ') +ROOT_DEV="$(mount | grep "${ROOTFS_DIR} " | cut -f1 -d' ')" -unmount ${ROOTFS_DIR} -zerofree -v ${ROOT_DEV} +unmount "${ROOTFS_DIR}" +zerofree -v "${ROOT_DEV}" -unmount_image ${IMG_FILE} +unmount_image "${IMG_FILE}" -mkdir -p ${DEPLOY_DIR} +mkdir -p "${DEPLOY_DIR}" -rm -f ${DEPLOY_DIR}/image_${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.zip +rm -f "${DEPLOY_DIR}/image_${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.zip" -pushd ${STAGE_WORK_DIR} > /dev/null -zip ${DEPLOY_DIR}/image_${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.zip $(basename ${IMG_FILE}) +pushd "${STAGE_WORK_DIR}" > /dev/null +zip "${DEPLOY_DIR}/image_${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.zip" \ + "$(basename "${IMG_FILE}")" popd > /dev/null cp "$INFO_FILE" "$DEPLOY_DIR" diff --git a/export-image/prerun.sh b/export-image/prerun.sh index 72cb299..0ac7181 100755 --- a/export-image/prerun.sh +++ b/export-image/prerun.sh @@ -2,22 +2,22 @@ IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img" -unmount_image ${IMG_FILE} +unmount_image "${IMG_FILE}" -rm -f ${IMG_FILE} +rm -f "${IMG_FILE}" -rm -rf ${ROOTFS_DIR} -mkdir -p ${ROOTFS_DIR} +rm -rf "${ROOTFS_DIR}" +mkdir -p "${ROOTFS_DIR}" -BOOT_SIZE=$(du --apparent-size -s ${EXPORT_ROOTFS_DIR}/boot --block-size=1 | cut -f 1) -TOTAL_SIZE=$(du --apparent-size -s ${EXPORT_ROOTFS_DIR} --exclude var/cache/apt/archives --block-size=1 | cut -f 1) +BOOT_SIZE=$(du --apparent-size -s "${EXPORT_ROOTFS_DIR}/boot" --block-size=1 | cut -f 1) +TOTAL_SIZE=$(du --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --block-size=1 | cut -f 1) ROUND_SIZE="$((4 * 1024 * 1024))" ROUNDED_ROOT_SECTOR=$(((2 * BOOT_SIZE + ROUND_SIZE) / ROUND_SIZE * ROUND_SIZE / 512 + 8192)) IMG_SIZE=$(((BOOT_SIZE + TOTAL_SIZE + (800 * 1024 * 1024) + ROUND_SIZE - 1) / ROUND_SIZE * ROUND_SIZE)) -truncate -s ${IMG_SIZE} ${IMG_FILE} -fdisk -H 255 -S 63 ${IMG_FILE} < /dev/null -mkfs.ext4 -L rootfs -O $ROOT_FEATURES $ROOT_DEV > /dev/null +mkdosfs -n boot -F 32 -v "$BOOT_DEV" > /dev/null +mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null -mount -v $ROOT_DEV ${ROOTFS_DIR} -t ext4 -mkdir -p ${ROOTFS_DIR}/boot -mount -v $BOOT_DEV ${ROOTFS_DIR}/boot -t vfat +mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4 +mkdir -p "${ROOTFS_DIR}/boot" +mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot" -t vfat -rsync -aHAXx --exclude var/cache/apt/archives ${EXPORT_ROOTFS_DIR}/ ${ROOTFS_DIR}/ +rsync -aHAXx --exclude var/cache/apt/archives "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/" diff --git a/export-noobs/00-release/00-run.sh b/export-noobs/00-release/00-run.sh index 25f62fd..5874944 100755 --- a/export-noobs/00-release/00-run.sh +++ b/export-noobs/00-release/00-run.sh @@ -2,35 +2,35 @@ NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}" -install -v -m 744 files/partition_setup.sh ${NOOBS_DIR}/ -install -v files/partitions.json ${NOOBS_DIR}/ -install -v files/os.json ${NOOBS_DIR}/ -install -v files/OS.png ${NOOBS_DIR}/ -install -v files/release_notes.txt ${NOOBS_DIR}/ +install -v -m 744 files/partition_setup.sh "${NOOBS_DIR}/" +install -v files/partitions.json "${NOOBS_DIR}/" +install -v files/os.json "${NOOBS_DIR}/" +install -v files/OS.png "${NOOBS_DIR}/" +install -v files/release_notes.txt "${NOOBS_DIR}/" -tar -v -c -C files/marketing -f ${NOOBS_DIR}/marketing.tar . +tar -v -c -C files/marketing -f "${NOOBS_DIR}/marketing.tar" . -BOOT_SIZE=$(xz --robot -l ${NOOBS_DIR}/boot.tar.xz | grep totals | cut -f 5) -ROOT_SIZE=$(xz --robot -l ${NOOBS_DIR}/root.tar.xz | grep totals | cut -f 5) +BOOT_SIZE="$(xz --robot -l "${NOOBS_DIR}/boot.tar.xz" | grep totals | cut -f 5)" +ROOT_SIZE="$(xz --robot -l "${NOOBS_DIR}/root.tar.xz" | grep totals | cut -f 5)" -BOOT_SIZE=$(expr ${BOOT_SIZE} / 1000000 \+ 1) -ROOT_SIZE=$(expr ${ROOT_SIZE} / 1000000 \+ 1) +BOOT_SIZE="$(( BOOT_SIZE / 1000000 + 1))" +ROOT_SIZE="$(( ROOT_SIZE / 1000000 + 1))" -BOOT_NOM=$(expr ${BOOT_SIZE} \* 3) -ROOT_NOM=$(expr ${ROOT_SIZE} \+ 400) +BOOT_NOM="$(( BOOT_SIZE * 3 ))" +ROOT_NOM="$(( ROOT_SIZE + 400 ))" -mv "${NOOBS_DIR}/OS.png" "${NOOBS_DIR}/$(echo ${NOOBS_NAME} | sed 's/ /_/g').png" +mv "${NOOBS_DIR}/OS.png" "${NOOBS_DIR}/${NOOBS_NAME// /_}.png" -sed ${NOOBS_DIR}/partitions.json -i -e "s|BOOT_SIZE|${BOOT_SIZE}|" -sed ${NOOBS_DIR}/partitions.json -i -e "s|ROOT_SIZE|${ROOT_SIZE}|" +sed "${NOOBS_DIR}/partitions.json" -i -e "s|BOOT_SIZE|${BOOT_SIZE}|" +sed "${NOOBS_DIR}/partitions.json" -i -e "s|ROOT_SIZE|${ROOT_SIZE}|" -sed ${NOOBS_DIR}/partitions.json -i -e "s|BOOT_NOM|${BOOT_NOM}|" -sed ${NOOBS_DIR}/partitions.json -i -e "s|ROOT_NOM|${ROOT_NOM}|" +sed "${NOOBS_DIR}/partitions.json" -i -e "s|BOOT_NOM|${BOOT_NOM}|" +sed "${NOOBS_DIR}/partitions.json" -i -e "s|ROOT_NOM|${ROOT_NOM}|" -sed ${NOOBS_DIR}/os.json -i -e "s|UNRELEASED|${IMG_DATE}|" -sed ${NOOBS_DIR}/os.json -i -e "s|NOOBS_NAME|${NOOBS_NAME}|" -sed ${NOOBS_DIR}/os.json -i -e "s|NOOBS_DESCRIPTION|${NOOBS_DESCRIPTION}|" +sed "${NOOBS_DIR}/os.json" -i -e "s|UNRELEASED|${IMG_DATE}|" +sed "${NOOBS_DIR}/os.json" -i -e "s|NOOBS_NAME|${NOOBS_NAME}|" +sed "${NOOBS_DIR}/os.json" -i -e "s|NOOBS_DESCRIPTION|${NOOBS_DESCRIPTION}|" -sed ${NOOBS_DIR}/release_notes.txt -i -e "s|UNRELEASED|${IMG_DATE}|" +sed "${NOOBS_DIR}/release_notes.txt" -i -e "s|UNRELEASED|${IMG_DATE}|" -cp -a ${NOOBS_DIR} ${DEPLOY_DIR}/ +cp -a "${NOOBS_DIR}" "${DEPLOY_DIR}/" diff --git a/export-noobs/prerun.sh b/export-noobs/prerun.sh index dafe654..1889567 100755 --- a/export-noobs/prerun.sh +++ b/export-noobs/prerun.sh @@ -2,14 +2,14 @@ IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img" NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}" -unmount_image ${IMG_FILE} +unmount_image "${IMG_FILE}" -mkdir -p ${STAGE_WORK_DIR} -cp ${WORK_DIR}/export-image/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img ${STAGE_WORK_DIR}/ +mkdir -p "${STAGE_WORK_DIR}" +cp "${WORK_DIR}/export-image/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img" "${STAGE_WORK_DIR}/" -rm -rf ${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX} +rm -rf "${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}" -PARTED_OUT=$(parted -s ${IMG_FILE} unit b print) +PARTED_OUT=$(parted -s "${IMG_FILE}" unit b print) BOOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^ 1'| xargs echo -n \ | cut -d" " -f 2 | tr -d B) BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^ 1'| xargs echo -n \ @@ -20,21 +20,21 @@ ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^ 2'| xargs echo -n \ ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^ 2'| xargs echo -n \ | cut -d" " -f 4 | tr -d B) -BOOT_DEV=$(losetup --show -f -o ${BOOT_OFFSET} --sizelimit ${BOOT_LENGTH} ${IMG_FILE}) -ROOT_DEV=$(losetup --show -f -o ${ROOT_OFFSET} --sizelimit ${ROOT_LENGTH} ${IMG_FILE}) +BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}") +ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}") echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH" echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH" -mkdir -p ${STAGE_WORK_DIR}/rootfs -mkdir -p ${NOOBS_DIR} +mkdir -p "${STAGE_WORK_DIR}/rootfs" +mkdir -p "${NOOBS_DIR}" -mount $ROOT_DEV ${STAGE_WORK_DIR}/rootfs -mount $BOOT_DEV ${STAGE_WORK_DIR}/rootfs/boot +mount "$ROOT_DEV" "${STAGE_WORK_DIR}/rootfs" +mount "$BOOT_DEV" "${STAGE_WORK_DIR}/rootfs/boot" ln -sv "/lib/systemd/system/apply_noobs_os_config.service" "$ROOTFS_DIR/etc/systemd/system/multi-user.target.wants/apply_noobs_os_config.service" -bsdtar --numeric-owner --format gnutar --use-compress-program pxz -C ${STAGE_WORK_DIR}/rootfs/boot -cpf ${NOOBS_DIR}/boot.tar.xz . -umount ${STAGE_WORK_DIR}/rootfs/boot -bsdtar --numeric-owner --format gnutar --use-compress-program pxz -C ${STAGE_WORK_DIR}/rootfs --one-file-system -cpf ${NOOBS_DIR}/root.tar.xz . +bsdtar --numeric-owner --format gnutar --use-compress-program pxz -C "${STAGE_WORK_DIR}/rootfs/boot" -cpf "${NOOBS_DIR}/boot.tar.xz" . +umount "${STAGE_WORK_DIR}/rootfs/boot" +bsdtar --numeric-owner --format gnutar --use-compress-program pxz -C "${STAGE_WORK_DIR}/rootfs" --one-file-system -cpf "${NOOBS_DIR}/root.tar.xz" . -unmount_image ${IMG_FILE} +unmount_image "${IMG_FILE}" diff --git a/scripts/common b/scripts/common index f18fd89..efd867e 100644 --- a/scripts/common +++ b/scripts/common @@ -1,5 +1,5 @@ log (){ - date +"[%T] $@" | tee -a "${LOG_FILE}" + date +"[%T] $*" | tee -a "${LOG_FILE}" } export -f log @@ -15,10 +15,10 @@ bootstrap(){ local BOOTSTRAP_CMD=debootstrap fi - capsh --drop=cap_setfcap -- -c "${BOOTSTRAP_CMD} --components=main,contrib,non-free \ + capsh --drop=cap_setfcap -- "${BOOTSTRAP_CMD}" --components=main,contrib,non-free \ --arch armhf \ --keyring "${STAGE_DIR}/files/raspberrypi.gpg" \ - $1 $2 $3" || rmdir "$2/debootstrap" + "$1" "$2" "$3" || rmdir "$2/debootstrap" } export -f bootstrap diff --git a/scripts/dependencies_check b/scripts/dependencies_check index d649f0c..1b92a9c 100644 --- a/scripts/dependencies_check +++ b/scripts/dependencies_check @@ -10,11 +10,11 @@ dependencies_check() for depfile in "$@"; do if [[ -e "$depfile" ]]; then - deps="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${BASE_DIR}/depends)" + deps="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${BASE_DIR}/depends")" fi for dep in $deps; do - if ! hash ${dep%:*} 2>/dev/null; then + if ! hash "${dep%:*}" 2>/dev/null; then missing="${missing:+$missing }${dep#*:}" fi done diff --git a/stage0/00-configure-apt/00-run.sh b/stage0/00-configure-apt/00-run.sh index 7966ef1..9d21ffb 100755 --- a/stage0/00-configure-apt/00-run.sh +++ b/stage0/00-configure-apt/00-run.sh @@ -1,13 +1,13 @@ #!/bin/bash -e -install -m 644 files/sources.list ${ROOTFS_DIR}/etc/apt/ -install -m 644 files/raspi.list ${ROOTFS_DIR}/etc/apt/sources.list.d/ +install -m 644 files/sources.list "${ROOTFS_DIR}/etc/apt/" +install -m 644 files/raspi.list "${ROOTFS_DIR}/etc/apt/sources.list.d/" if [ -n "$APT_PROXY" ]; then - install -m 644 files/51cache ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache - sed ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache -i -e "s|APT_PROXY|${APT_PROXY}|" + install -m 644 files/51cache "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache" + sed "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache" -i -e "s|APT_PROXY|${APT_PROXY}|" else - rm -f ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache + rm -f "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache" fi on_chroot apt-key add - < files/raspberrypi.gpg.key diff --git a/stage0/prerun.sh b/stage0/prerun.sh index 14c09c3..80c43f7 100755 --- a/stage0/prerun.sh +++ b/stage0/prerun.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -d ${ROOTFS_DIR} ]; then - bootstrap stretch ${ROOTFS_DIR} http://mirrordirector.raspbian.org/raspbian/ +if [ ! -d "${ROOTFS_DIR}" ]; then + bootstrap stretch "${ROOTFS_DIR}" http://mirrordirector.raspbian.org/raspbian/ fi diff --git a/stage1/00-boot-files/00-run.sh b/stage1/00-boot-files/00-run.sh index 2c976a8..bc61397 100755 --- a/stage1/00-boot-files/00-run.sh +++ b/stage1/00-boot-files/00-run.sh @@ -1,4 +1,4 @@ #!/bin/bash -e -install -m 644 files/cmdline.txt ${ROOTFS_DIR}/boot/ -install -m 644 files/config.txt ${ROOTFS_DIR}/boot/ +install -m 644 files/cmdline.txt "${ROOTFS_DIR}/boot/" +install -m 644 files/config.txt "${ROOTFS_DIR}/boot/" diff --git a/stage1/01-sys-tweaks/00-run.sh b/stage1/01-sys-tweaks/00-run.sh index 4454056..61ba51b 100755 --- a/stage1/01-sys-tweaks/00-run.sh +++ b/stage1/01-sys-tweaks/00-run.sh @@ -1,8 +1,8 @@ #!/bin/bash -e -install -d ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d -install -m 644 files/noclear.conf ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/noclear.conf -install -v -m 644 files/fstab ${ROOTFS_DIR}/etc/fstab +install -d "${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d" +install -m 644 files/noclear.conf "${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/noclear.conf" +install -v -m 644 files/fstab "${ROOTFS_DIR}/etc/fstab" on_chroot << EOF if ! id -u pi >/dev/null 2>&1; then diff --git a/stage1/02-net-tweaks/00-run.sh b/stage1/02-net-tweaks/00-run.sh index 174b9f8..96a1774 100755 --- a/stage1/02-net-tweaks/00-run.sh +++ b/stage1/02-net-tweaks/00-run.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -install -m 644 files/ipv6.conf ${ROOTFS_DIR}/etc/modprobe.d/ipv6.conf -install -m 644 files/hostname ${ROOTFS_DIR}/etc/hostname +install -m 644 files/ipv6.conf "${ROOTFS_DIR}/etc/modprobe.d/ipv6.conf" +install -m 644 files/hostname "${ROOTFS_DIR}/etc/hostname" -ln -sf /dev/null ${ROOTFS_DIR}/etc/systemd/network/99-default.link +ln -sf /dev/null "${ROOTFS_DIR}/etc/systemd/network/99-default.link" diff --git a/stage1/prerun.sh b/stage1/prerun.sh index ebb5d35..9acd13c 100755 --- a/stage1/prerun.sh +++ b/stage1/prerun.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -d ${ROOTFS_DIR} ]; then +if [ ! -d "${ROOTFS_DIR}" ]; then copy_previous fi diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 9eb7629..4e9c7d0 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -1,15 +1,15 @@ #!/bin/bash -e -install -m 755 files/resize2fs_once ${ROOTFS_DIR}/etc/init.d/ +install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/" -install -d ${ROOTFS_DIR}/etc/systemd/system/rc-local.service.d -install -m 644 files/ttyoutput.conf ${ROOTFS_DIR}/etc/systemd/system/rc-local.service.d/ +install -d "${ROOTFS_DIR}/etc/systemd/system/rc-local.service.d" +install -m 644 files/ttyoutput.conf "${ROOTFS_DIR}/etc/systemd/system/rc-local.service.d/" -install -m 644 files/50raspi ${ROOTFS_DIR}/etc/apt/apt.conf.d/ +install -m 644 files/50raspi "${ROOTFS_DIR}/etc/apt/apt.conf.d/" -install -m 644 files/console-setup ${ROOTFS_DIR}/etc/default/ +install -m 644 files/console-setup "${ROOTFS_DIR}/etc/default/" -install -m 755 files/rc.local ${ROOTFS_DIR}/etc/ +install -m 755 files/rc.local "${ROOTFS_DIR}/etc/" on_chroot << EOF systemctl disable hwclock.sh @@ -21,7 +21,7 @@ EOF if [ "${USE_QEMU}" = "1" ]; then echo "enter QEMU mode" - install -m 644 files/90-qemu.rules ${ROOTFS_DIR}/etc/udev/rules.d/ + install -m 644 files/90-qemu.rules "${ROOTFS_DIR}/etc/udev/rules.d/" on_chroot << EOF systemctl disable resize2fs_once EOF @@ -34,7 +34,7 @@ fi on_chroot << \EOF for GRP in input spi i2c gpio; do - groupadd -f -r $GRP + groupadd -f -r "$GRP" done for GRP in adm dialout cdrom audio users sudo video games plugdev input gpio spi i2c netdev; do adduser pi $GRP @@ -49,4 +49,4 @@ on_chroot << EOF usermod --pass='*' root EOF -rm -f ${ROOTFS_DIR}/etc/ssh/ssh_host_*_key* +rm -f "${ROOTFS_DIR}/etc/ssh/"ssh_host_*_key* diff --git a/stage2/02-net-tweaks/01-run.sh b/stage2/02-net-tweaks/01-run.sh index a96b556..d21419e 100755 --- a/stage2/02-net-tweaks/01-run.sh +++ b/stage2/02-net-tweaks/01-run.sh @@ -1,8 +1,8 @@ #!/bin/bash -e -install -v -d ${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d -install -v -m 644 files/wait.conf ${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/ +install -v -d "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d" +install -v -m 644 files/wait.conf "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/" -install -v -d ${ROOTFS_DIR}/etc/wpa_supplicant -install -v -m 600 files/wpa_supplicant.conf ${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/" diff --git a/stage2/prerun.sh b/stage2/prerun.sh index ebb5d35..9acd13c 100755 --- a/stage2/prerun.sh +++ b/stage2/prerun.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -d ${ROOTFS_DIR} ]; then +if [ ! -d "${ROOTFS_DIR}" ]; then copy_previous fi diff --git a/stage3/01-tweaks/00-run.sh b/stage3/01-tweaks/00-run.sh index f64961c..5da7c1a 100755 --- a/stage3/01-tweaks/00-run.sh +++ b/stage3/01-tweaks/00-run.sh @@ -1,3 +1,3 @@ #!/bin/bash -e -rm -f ${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/wait.conf +rm -f "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/wait.conf" diff --git a/stage3/prerun.sh b/stage3/prerun.sh index ebb5d35..9acd13c 100755 --- a/stage3/prerun.sh +++ b/stage3/prerun.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -d ${ROOTFS_DIR} ]; then +if [ ! -d "${ROOTFS_DIR}" ]; then copy_previous fi diff --git a/stage4/01-console-autologin/00-run.sh b/stage4/01-console-autologin/00-run.sh index 11ee373..2189bef 100755 --- a/stage4/01-console-autologin/00-run.sh +++ b/stage4/01-console-autologin/00-run.sh @@ -1,3 +1,4 @@ #!/bin/bash -e -ln -sf /etc/systemd/system/autologin@.service ${ROOTFS_DIR}/etc/systemd/system/getty.target.wants/getty@tty1.service +ln -sf /etc/systemd/system/autologin@.service \ + "${ROOTFS_DIR}/etc/systemd/system/getty.target.wants/getty@tty1.service" diff --git a/stage4/02-extras/00-run.sh b/stage4/02-extras/00-run.sh index e24f351..08c6c1e 100755 --- a/stage4/02-extras/00-run.sh +++ b/stage4/02-extras/00-run.sh @@ -1,22 +1,22 @@ #!/bin/bash -e -HASH=`wget https://api.github.com/repos/KenT2/python-games/git/refs/heads/master -qO -| grep \"sha\" | cut -f 2 -d ':' | cut -f 2 -d \"` +HASH="$(wget https://api.github.com/repos/KenT2/python-games/git/refs/heads/master -qO -| grep \"sha\" | cut -f 2 -d ':' | cut -f 2 -d \")" if [ -f files/python_games.hash ]; then - HASH_LOCAL=`cat files/python_games.hash` + HASH_LOCAL="$(cat files/python_games.hash)" fi if [ ! -e files/python_games.tar.gz ] || [ "$HASH" != "$HASH_LOCAL" ]; then wget "https://github.com/KenT2/python-games/tarball/master" -O files/python_games.tar.gz - echo $HASH > files/python_games.hash + echo "$HASH" > files/python_games.hash fi -ln -sf pip3 ${ROOTFS_DIR}/usr/bin/pip-3.2 +ln -sf pip3 "${ROOTFS_DIR}/usr/bin/pip-3.2" -install -v -o 1000 -g 1000 -d ${ROOTFS_DIR}/home/pi/python_games -tar xvf files/python_games.tar.gz -C ${ROOTFS_DIR}/home/pi/python_games --strip-components=1 -chown 1000:1000 ${ROOTFS_DIR}/home/pi/python_games -Rv -chmod +x ${ROOTFS_DIR}/home/pi/python_games/launcher.sh +install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/pi/python_games" +tar xvf files/python_games.tar.gz -C "${ROOTFS_DIR}/home/pi/python_games" --strip-components=1 +chown 1000:1000 "${ROOTFS_DIR}/home/pi/python_games" -Rv +chmod +x "${ROOTFS_DIR}/home/pi/python_games/launcher.sh" #Alacarte fixes install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/pi/.local" diff --git a/stage4/prerun.sh b/stage4/prerun.sh index ebb5d35..9acd13c 100755 --- a/stage4/prerun.sh +++ b/stage4/prerun.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -d ${ROOTFS_DIR} ]; then +if [ ! -d "${ROOTFS_DIR}" ]; then copy_previous fi diff --git a/stage5/prerun.sh b/stage5/prerun.sh index ebb5d35..9acd13c 100755 --- a/stage5/prerun.sh +++ b/stage5/prerun.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -if [ ! -d ${ROOTFS_DIR} ]; then +if [ ! -d "${ROOTFS_DIR}" ]; then copy_previous fi