From 0a810af45a73a7cdb3c6a35db18a6063fcb5d695 2018-11-22 23:58:55 From: Unknown Date: 2018-11-22 23:58:55 Subject: [PATCH] fixes fixes and further shellcheck.net improvements --- diff --git a/bootstrap.d/13-kernel.sh b/bootstrap.d/13-kernel.sh index e86ae33..a662049 100644 --- a/bootstrap.d/13-kernel.sh +++ b/bootstrap.d/13-kernel.sh @@ -108,7 +108,7 @@ if [ "$BUILD_KERNEL" = true ] ; then echo "CONFIG_CRYPTO_XTS=y" echo "CONFIG_CRYPTO_SHA512=y" echo "CONFIG_CRYPTO_MANAGER=y" - } >> ${KERNEL_DIR}/.config + } >> "${KERNEL_DIR}"/.config fi fi @@ -139,7 +139,7 @@ if [ "$BUILD_KERNEL" = true ] ; then make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs # Cross compile kernel modules - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules fi fi @@ -153,16 +153,16 @@ if [ "$BUILD_KERNEL" = true ] ; then # Install kernel modules if [ "$ENABLE_REDUCE" = true ] ; then - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install fi else - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install fi # Install kernel firmware - if [ "$(grep "^firmware_install:" "${KERNEL_DIR}/Makefile")" ] ; then + if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install fi fi @@ -225,8 +225,8 @@ if [ "$BUILD_KERNEL" = true ] ; then rm -fr "${KERNEL_DIR}" else # Prepare compiled kernel modules - if [ "$(grep "CONFIG_MODULES=y" "${KERNEL_DIR}/.config")" ] ; then - if [ "$(grep "^modules_prepare:" "${KERNEL_DIR}/Makefile")" ] ; then + if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then + if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare fi diff --git a/bootstrap.d/15-rpi-config.sh b/bootstrap.d/15-rpi-config.sh index de86adf..91e16e1 100644 --- a/bootstrap.d/15-rpi-config.sh +++ b/bootstrap.d/15-rpi-config.sh @@ -104,6 +104,12 @@ if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then # Copy downloaded sources mv "${temp_dir}/pi-bluetooth" "${R}/tmp/" + # Raspberry-sys-mod package for /dev/serial device needed by bluetooth service + as_nobody wget -q -O "${R}/tmp/pi-bluetooth/99-com.rules" https://raw.githubusercontent.com/RPi-Distro/raspberrypi-sys-mods/master/etc.armhf/udev/rules.d/99-com.rules + # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/ + as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth + as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth + # Set permissions chown -R root:root "${R}/tmp/pi-bluetooth" @@ -116,12 +122,15 @@ if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then # Install Firmware Flash file and apropiate licence mkdir "${ETC_DIR}/firmware/" - - wget -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth - wget -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth - - # Get /dev/serial back for compability - wget -O "${ETC_DIR}/udev/rules.d/99-com.rules" https://raw.githubusercontent.com/RPi-Distro/raspberrypi-sys-mods/master/etc.armhf/udev/rules.d/99-com.rules + install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${ETC_DIR}/firmware/LICENCE.broadcom_bcm43xx" + install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${ETC_DIR}/firmware/LICENCE.broadcom_bcm43xx" + install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service" + install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service" + # Install udev rule for bluetooth device + install_readonly "${R}/tmp/pi-bluetooth/99-com.rules" "${ETC_DIR}/udev/rules.d/99-com.rules" + + # Remove temporary directory + rm -fr "${temp_dir}" fi fi diff --git a/bootstrap.d/30-security.sh b/bootstrap.d/30-security.sh index 5fbfc7a..8ad8275 100644 --- a/bootstrap.d/30-security.sh +++ b/bootstrap.d/30-security.sh @@ -11,8 +11,8 @@ ENCRYPTED_USER_PASSWORD=$(mkpasswd -m sha-512 "${USER_PASSWORD}") # Setup default user if [ "$ENABLE_USER" = true ] ; then - chroot_exec adduser --gecos $USER_NAME --add_extra_groups --disabled-password $USER_NAME - chroot_exec usermod -a -G sudo -p "${ENCRYPTED_USER_PASSWORD}" $USER_NAME + chroot_exec adduser --gecos "$USER_NAME" --add_extra_groups --disabled-password "$USER_NAME" + chroot_exec usermod -a -G sudo -p "${ENCRYPTED_USER_PASSWORD}" "$USER_NAME" fi # Setup root password or not diff --git a/bootstrap.d/41-uboot.sh b/bootstrap.d/41-uboot.sh index 6d42bde..c96b673 100644 --- a/bootstrap.d/41-uboot.sh +++ b/bootstrap.d/41-uboot.sh @@ -41,7 +41,7 @@ if [ "$ENABLE_UBOOT" = true ] ; then # Install and setup U-Boot command file install_readonly files/boot/uboot.mkimage "${BOOT_DIR}/uboot.mkimage" - printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat ${BOOT_DIR}/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" + printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat "${BOOT_DIR}"/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" if [ "$ENABLE_INITRAMFS" = true ] ; then # Convert generated initramfs for U-Boot using mkimage @@ -51,7 +51,7 @@ if [ "$ENABLE_UBOOT" = true ] ; then rm -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" # Configure U-Boot to load generated initramfs - printf "# Set initramfs file\nsetenv initramfs initramfs-${KERNEL_VERSION}.uboot\n\n$(cat ${BOOT_DIR}/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" + printf "# Set initramfs file\nsetenv initramfs initramfs-${KERNEL_VERSION}.uboot\n\n$(cat "${BOOT_DIR}"/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" printf "\nbootz \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r}" >> "${BOOT_DIR}/uboot.mkimage" else # ENABLE_INITRAMFS=false # Remove initramfs from U-Boot mkfile @@ -65,14 +65,16 @@ if [ "$ENABLE_UBOOT" = true ] ; then printf "\nbootz \${kernel_addr_r} - \${fdt_addr_r}" >> "${BOOT_DIR}/uboot.mkimage" fi fi - - if [ "$KERNEL_ARCH" = "arm64" ] ; then - echo "Setting up config.txt to boot 64bit uboot" - - printf "\n# 64bit-mode" >> "${BOOT_DIR}/config.txt" - printf "\n# arm_control=0x200 is deprecated https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md" >> "${BOOT_DIR}/config.txt" - printf "\narm_64bit=1" >> "${BOOT_DIR}/config.txt" + if [ "$SET_ARCH" = 64 ] ; then + echo "Setting up config.txt to boot 64bit uboot" + { + printf "\n# 64bit-mode" + printf "\n# arm_control=0x200 is deprecated https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md" + printf "\narm_64bit=1" + } >> "${BOOT_DIR}/config.txt" + + #in 64bit uboot booti is used instead of bootz [like in KERNEL_BIN_IMAGE=zImage (armv7)|| Image(armv8)] sed -i "s|bootz|booti|g" "${BOOT_DIR}/uboot.mkimage" fi diff --git a/bootstrap.d/43-videocore.sh b/bootstrap.d/43-videocore.sh index d42590c..b8ff518 100644 --- a/bootstrap.d/43-videocore.sh +++ b/bootstrap.d/43-videocore.sh @@ -8,16 +8,16 @@ if [ "$ENABLE_VIDEOCORE" = true ] ; then # Copy existing videocore sources into chroot directory if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then - # Copy local U-Boot sources + # Copy local videocore sources cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp/userland" else - # Create temporary directory for U-Boot sources + # Create temporary directory for videocore sources temp_dir=$(as_nobody mktemp -d) - # Fetch U-Boot sources + # Fetch videocore sources as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}" - # Copy downloaded U-Boot sources + # Copy downloaded videocore sources mv "${temp_dir}/userland" "${R}/tmp/" # Set permissions of the U-Boot sources @@ -31,7 +31,7 @@ if [ "$ENABLE_VIDEOCORE" = true ] ; then mkdir "${R}"/tmp/userland/build # push us to build directory - pushd "${R}"/tmp/userland/build + cd "${R}"/tmp/userland/build if [ "$RELEASE_ARCH" = "arm64" ] ; then cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DVIDEOCORE_BUILD_DIR="${R}" "${R}/tmp/userland" @@ -48,6 +48,6 @@ if [ "$ENABLE_VIDEOCORE" = true ] ; then #build userland make -j "$(nproc)" - #pop us out of build dir - popd + #back to root of scriptdir + cd "${WORKDIR}" fi diff --git a/functions.sh b/functions.sh index 6ee31da..74ca846 100644 --- a/functions.sh +++ b/functions.sh @@ -30,22 +30,22 @@ cleanup (){ chroot_exec() { # Exec command in chroot - LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $* + LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot "${R}" "$@" } as_nobody() { # Exec command as user nobody - sudo -E -u nobody LANG=C LC_ALL=C $* + sudo -E -u nobody LANG=C LC_ALL=C "$@" } install_readonly() { # Install file with user read-only permissions - install -o root -g root -m 644 $* + install -o root -g root -m 644 "$@" } install_exec() { # Install file with root exec permissions - install -o root -g root -m 744 $* + install -o root -g root -m 744 "$@" } use_template () { @@ -64,14 +64,14 @@ chroot_install_cc() { if [ -z "${COMPILER_PACKAGES}" ] ; then COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }') # Install COMPILER_PACKAGES in chroot - chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES} + chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install "${COMPILER_PACKAGES}" fi } chroot_remove_cc() { # Remove c/c++ build environment from the chroot - if [ ! -z "${COMPILER_PACKAGES}" ] ; then - chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES} + if [ -n "${COMPILER_PACKAGES}" ] ; then + chroot_exec apt-get -qq -y --auto-remove purge "${COMPILER_PACKAGES}" COMPILER_PACKAGES="" fi }