From 68b6d2ead05ee66a6d548e008c77a135cbb9cdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Wed, 24 Jun 2020 02:15:20 +0200 Subject: [PATCH] Shellcheck fixes 3 (#2054) * lib/general.sh: Lint via shellcheck * lib/compilation-prepare.sh: Lint via shellcheck --- lib/compilation-prepare.sh | 279 ++++++++++++++-------------- lib/general.sh | 365 +++++++++++++++++++------------------ 2 files changed, 329 insertions(+), 315 deletions(-) diff --git a/lib/compilation-prepare.sh b/lib/compilation-prepare.sh index bdb4522040..8650bd4090 100644 --- a/lib/compilation-prepare.sh +++ b/lib/compilation-prepare.sh @@ -1,3 +1,5 @@ +#!/bin/bash +# # Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com # # This file is licensed under the terms of the GNU General Public @@ -18,54 +20,54 @@ compilation_prepare() # Maintaining one from central location starting with 5.3+ # Temporally set for new "default->legacy,next->current" family naming - if linux-version compare $version ge 5.6; then + if linux-version compare "${version}" ge 5.6; then display_alert "Adjusting" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-5.6.y.patch" "applying" else - if linux-version compare $version ge 5.3; then + if linux-version compare "${version}" ge 5.3; then display_alert "Adjusting" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-5.3.y.patch" "applying" fi fi - if [[ $version == "4.19."* ]] && [[ "$LINUXFAMILY" == sunxi* || "$LINUXFAMILY" == meson64 || \ + if [[ "${version}" == "4.19."* ]] && [[ "$LINUXFAMILY" == sunxi* || "$LINUXFAMILY" == meson64 || \ "$LINUXFAMILY" == mvebu64 || "$LINUXFAMILY" == mt7623 || "$LINUXFAMILY" == mvebu ]]; then display_alert "Adjustin" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-4.19.y.patch" "applying" fi - if [[ $version == "4.14."* ]] && [[ "$LINUXFAMILY" == s5p6818 || "$LINUXFAMILY" == mvebu64 || \ + if [[ "${version}" == "4.14."* ]] && [[ "$LINUXFAMILY" == s5p6818 || "$LINUXFAMILY" == mvebu64 || \ "$LINUXFAMILY" == imx7d || "$LINUXFAMILY" == odroidxu4 || "$LINUXFAMILY" == mvebu ]]; then display_alert "Adjustin" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-4.14.y.patch" "applying" fi - if [[ $version == "4.4."* || $version == "4.9."* ]] && \ + if [[ "${version}" == "4.4."* || "${version}" == "4.9."* ]] && \ [[ "$LINUXFAMILY" == rockpis || "$LINUXFAMILY" == rk3399 ]]; then display_alert "Adjustin" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-4.4.y-rk3399.patch" "applying" fi - if [[ $version == "4.4."* ]] && [[ "$LINUXFAMILY" == rockchip64 ]]; then + if [[ "${version}" == "4.4."* ]] && [[ "$LINUXFAMILY" == rockchip64 ]]; then display_alert "Adjustin" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-4.4.y-rockchip64.patch" "applying" fi - if [[ $version == "4.4."* ]] && [[ "$LINUXFAMILY" == rockchip || "$LINUXFAMILY" == rk322x ]]; then + if [[ "${version}" == "4.4."* ]] && [[ "$LINUXFAMILY" == rockchip || "$LINUXFAMILY" == rk322x ]]; then display_alert "Adjustin" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-4.4.y.patch" "applying" fi - if [[ $version == "4.9."* ]] && [[ "$LINUXFAMILY" == meson64 || "$LINUXFAMILY" == odroidc4 ]]; then + if [[ "${version}" == "4.9."* ]] && [[ "$LINUXFAMILY" == meson64 || "$LINUXFAMILY" == odroidc4 ]]; then display_alert "Adjustin" "packaging" "info" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/patch/misc/general-packaging-4.9.y.patch" "applying" fi @@ -73,7 +75,7 @@ compilation_prepare() # mac80211 wireless driver injection features from Kali Linux # - if linux-version compare $version ge 5.4; then + if linux-version compare "${version}" ge 5.4; then display_alert "Adding" "Wireless package injections for mac80211 compatible chipsets" "info" process_patch_file "${SRC}/patch/misc/kali-wifi-injection-1.patch" "applying" @@ -85,21 +87,22 @@ compilation_prepare() # # Older versions have AUFS support with a patch - if linux-version compare $version ge 5.1 && linux-version compare $version le 5.8 && [ "$AUFS" == yes ]; then + if linux-version compare "${version}" ge 5.1 && linux-version compare "${version}" le 5.8 && [ "$AUFS" == yes ]; then # attach to specifics tag or branch - local aufstag=$(echo ${version} | cut -f 1-2 -d ".") + local aufstag + aufstag=$(echo "${version}" | cut -f 1-2 -d ".") # manual overrides - if linux-version compare $version ge 5.4.3 && linux-version compare $version le 5.5 ; then aufstag="5.4.3"; fi + if linux-version compare "${version}" ge 5.4.3 && linux-version compare "${version}" le 5.5 ; then aufstag="5.4.3"; fi # check if Mr. Okajima already made a branch for this version - git ls-remote --exit-code --heads https://github.com/sfjro/aufs5-standalone aufs${aufstag} >/dev/null + git ls-remote --exit-code --heads https://github.com/sfjro/aufs5-standalone "aufs${aufstag}" >/dev/null if [ "$?" -ne "0" ]; then # then use rc branch aufstag="5.x-rcN" - git ls-remote --exit-code --heads https://github.com/sfjro/aufs5-standalone aufs${aufstag} >/dev/null + git ls-remote --exit-code --heads https://github.com/sfjro/aufs5-standalone "aufs${aufstag}" >/dev/null fi if [ "$?" -eq "0" ]; then @@ -107,13 +110,13 @@ compilation_prepare() display_alert "Adding" "AUFS ${aufstag}" "info" local aufsver="branch:aufs${aufstag}" fetch_from_repo "https://github.com/sfjro/aufs5-standalone" "aufs5" "branch:${aufsver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit process_patch_file "${SRC}/cache/sources/aufs5/${aufsver#*:}/aufs5-kbuild.patch" "applying" process_patch_file "${SRC}/cache/sources/aufs5/${aufsver#*:}/aufs5-base.patch" "applying" process_patch_file "${SRC}/cache/sources/aufs5/${aufsver#*:}/aufs5-mmap.patch" "applying" process_patch_file "${SRC}/cache/sources/aufs5/${aufsver#*:}/aufs5-standalone.patch" "applying" - cp -R ${SRC}/cache/sources/aufs5/${aufsver#*:}/{Documentation,fs} . - cp ${SRC}/cache/sources/aufs5/${aufsver#*:}/include/uapi/linux/aufs_type.h include/uapi/linux/ + cp -R "${SRC}/cache/sources/aufs5/${aufsver#*:}"/{Documentation,fs} . + cp "${SRC}/cache/sources/aufs5/${aufsver#*:}"/include/uapi/linux/aufs_type.h include/uapi/linux/ fi fi @@ -122,7 +125,7 @@ compilation_prepare() # WireGuard VPN for Linux 3.10 - 5.5 - if linux-version compare $version ge 3.10 && linux-version compare $version le 5.5 && [ "${WIREGUARD}" == yes ]; then + if linux-version compare "${version}" ge 3.10 && linux-version compare "${version}" le 5.5 && [ "${WIREGUARD}" == yes ]; then # attach to specifics tag or branch local wirever="branch:master" @@ -130,23 +133,23 @@ compilation_prepare() display_alert "Adding" "WireGuard VPN for Linux 3.10 - 5.5 ${wirever} " "info" fetch_from_repo "https://git.zx2c4.com/wireguard-linux-compat" "wireguard" "${wirever}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/wireguard - cp -R ${SRC}/cache/sources/wireguard/${wirever#*:}/src/ ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/wireguard + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/wireguard" + cp -R "${SRC}/cache/sources/wireguard/${wirever#*:}/src/" "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/wireguard" sed -i "/^obj-\\\$(CONFIG_NETFILTER).*+=/a obj-\$(CONFIG_WIREGUARD) += wireguard/" \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Makefile + "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Makefile" sed -i "/^if INET\$/a source \"net/wireguard/Kconfig\"" \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Kconfig" # remove duplicates - [[ $(cat ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Makefile | grep wireguard | wc -l) -gt 1 ]] && \ - sed -i '0,/wireguard/{/wireguard/d;}' ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Makefile - [[ $(cat ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Kconfig | grep wireguard | wc -l) -gt 1 ]] && \ - sed -i '0,/wireguard/{/wireguard/d;}' ${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Kconfig + [[ $(grep -c wireguard "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Makefile") -gt 1 ]] && \ + sed -i '0,/wireguard/{/wireguard/d;}' "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Makefile" + [[ $(grep -c wireguard "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Kconfig") -gt 1 ]] && \ + sed -i '0,/wireguard/{/wireguard/d;}' "${SRC}/cache/sources/${LINUXSOURCEDIR}/net/Kconfig" # headers workaround display_alert "Patching WireGuard" "Applying workaround for headers compilation" "info" sed -i '/mkdir -p "$destdir"/a mkdir -p "$destdir"/net/wireguard; \ touch "$destdir"/net/wireguard/{Kconfig,Makefile} # workaround for Wireguard' \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/scripts/package/builddeb + "${SRC}/cache/sources/${LINUXSOURCEDIR}/scripts/package/builddeb" fi @@ -155,7 +158,7 @@ compilation_prepare() # Wireless drivers for Realtek 8189ES chipsets - if linux-version compare $version ge 3.14 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 3.14 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl8189esver="branch:master" @@ -163,22 +166,22 @@ compilation_prepare() display_alert "Adding" "Wireless drivers for Realtek 8189ES chipsets ${rtl8189esver}" "info" fetch_from_repo "https://github.com/jwrdegoede/rtl8189ES_linux" "rtl8189es" "${rtl8189esver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es/ - cp -R ${SRC}/cache/sources/rtl8189es/${rtl8189esver#*:}/{core,hal,include,os_dep,platform} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es/" + cp -R "${SRC}/cache/sources/rtl8189es/${rtl8189esver#*:}"/{core,hal,include,os_dep,platform} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es" # Makefile - cp ${SRC}/cache/sources/rtl8189es/${rtl8189esver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es/Makefile - cp ${SRC}/cache/sources/rtl8189es/${rtl8189esver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es/Kconfig + cp "${SRC}/cache/sources/rtl8189es/${rtl8189esver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es/Makefile" + cp "${SRC}/cache/sources/rtl8189es/${rtl8189esver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189es/Kconfig" # Add to section Makefile - echo "obj-\$(CONFIG_RTL8189ES) += rtl8189es/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_RTL8189ES) += rtl8189es/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl8189es\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi @@ -187,7 +190,7 @@ compilation_prepare() # Wireless drivers for Realtek 8189FS chipsets - if linux-version compare $version ge 3.14 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 3.14 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl8189fsver="branch:rtl8189fs" @@ -195,22 +198,22 @@ compilation_prepare() display_alert "Adding" "Wireless drivers for Realtek 8189FS chipsets ${rtl8189fsver}" "info" fetch_from_repo "https://github.com/jwrdegoede/rtl8189ES_linux" "rtl8189fs" "${rtl8189fsver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs/ - cp -R ${SRC}/cache/sources/rtl8189fs/${rtl8189fsver#*:}/{core,hal,include,os_dep,platform} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs/" + cp -R "${SRC}/cache/sources/rtl8189fs/${rtl8189fsver#*:}"/{core,hal,include,os_dep,platform} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs" # Makefile - cp ${SRC}/cache/sources/rtl8189fs/${rtl8189fsver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs/Makefile - cp ${SRC}/cache/sources/rtl8189fs/${rtl8189fsver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs/Kconfig + cp "${SRC}/cache/sources/rtl8189fs/${rtl8189fsver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs/Makefile" + cp "${SRC}/cache/sources/rtl8189fs/${rtl8189fsver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8189fs/Kconfig" # Add to section Makefile - echo "obj-\$(CONFIG_RTL8189FS) += rtl8189fs/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_RTL8189FS) += rtl8189fs/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl8189fs\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi @@ -219,7 +222,7 @@ compilation_prepare() # Wireless drivers for Realtek 8811, 8812, 8814 and 8821 chipsets - if linux-version compare $version ge 3.14 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 3.14 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl8812auver="branch:v5.6.4.2" @@ -227,22 +230,22 @@ compilation_prepare() display_alert "Adding" "Wireless drivers for Realtek 8811, 8812, 8814 and 8821 chipsets ${rtl8812auver}" "info" fetch_from_repo "https://github.com/aircrack-ng/rtl8812au" "rtl8812au" "${rtl8812auver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au/ - cp -R ${SRC}/cache/sources/rtl8812au/${rtl8812auver#*:}/{core,hal,include,os_dep,platform} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au/" + cp -R "${SRC}/cache/sources/rtl8812au/${rtl8812auver#*:}"/{core,hal,include,os_dep,platform} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au" # Makefile - cp ${SRC}/cache/sources/rtl8812au/${rtl8812auver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au/Makefile - cp ${SRC}/cache/sources/rtl8812au/${rtl8812auver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au/Kconfig + cp "${SRC}/cache/sources/rtl8812au/${rtl8812auver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au/Makefile" + cp "${SRC}/cache/sources/rtl8812au/${rtl8812auver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8812au/Kconfig" # Add to section Makefile - echo "obj-\$(CONFIG_88XXAU) += rtl8812au/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_88XXAU) += rtl8812au/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl8812au\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi @@ -250,28 +253,28 @@ compilation_prepare() # Wireless drivers for Xradio XR819 chipsets - if linux-version compare $version ge 4.19 && [[ "$LINUXFAMILY" == sunxi* ]] && [[ "$EXTRAWIFI" == yes ]]; then + if linux-version compare "${version}" ge 4.19 && [[ "$LINUXFAMILY" == sunxi* ]] && [[ "$EXTRAWIFI" == yes ]]; then display_alert "Adding" "Wireless drivers for Xradio XR819 chipsets" "info" fetch_from_repo "https://github.com/karabek/xradio" "xradio" "branch:master" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/ - cp ${SRC}/cache/sources/xradio/master/*.{h,c} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/ + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/" + cp "${SRC}"/cache/sources/xradio/master/*.{h,c} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/" # Makefile - cp ${SRC}/cache/sources/xradio/master/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/Makefile - cp ${SRC}/cache/sources/xradio/master/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/Kconfig + cp "${SRC}/cache/sources/xradio/master/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/Makefile" + cp "${SRC}/cache/sources/xradio/master/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/xradio/Kconfig" # Add to section Makefile echo "obj-\$(CONFIG_WLAN_VENDOR_XRADIO) += xradio/" \ - >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/xradio\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi @@ -280,7 +283,7 @@ compilation_prepare() # Wireless drivers for Realtek RTL8811CU and RTL8821C chipsets - if linux-version compare $version ge 3.14 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 3.14 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl8811cuver="commit:2bebdb9a35c1d9b6e6a928e371fa39d5fcec8a62" @@ -288,30 +291,30 @@ compilation_prepare() display_alert "Adding" "Wireless drivers for Realtek RTL8811CU and RTL8821C chipsets ${rtl8811cuver}" "info" fetch_from_repo "https://github.com/brektrou/rtl8821CU" "rtl8811cu" "${rtl8811cuver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/ - cp -R ${SRC}/cache/sources/rtl8811cu/${rtl8811cuver#*:}/{core,hal,include,os_dep,platform,rtl8821c.mk} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/" + cp -R "${SRC}/cache/sources/rtl8811cu/${rtl8811cuver#*:}"/{core,hal,include,os_dep,platform,rtl8821c.mk} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu" # Makefile - cp ${SRC}/cache/sources/rtl8811cu/${rtl8811cuver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Makefile - cp ${SRC}/cache/sources/rtl8811cu/${rtl8811cuver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Kconfig + cp "${SRC}/cache/sources/rtl8811cu/${rtl8811cuver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Makefile" + cp "${SRC}/cache/sources/rtl8811cu/${rtl8811cuver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Kconfig" # Disable debug sed -i "s/^CONFIG_RTW_DEBUG.*/CONFIG_RTW_DEBUG = n/" \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Makefile + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Makefile" # Address ARM related bug https://github.com/aircrack-ng/rtl8812au/issues/233 sed -i "s/^CONFIG_MP_VHT_HW_TX_MODE.*/CONFIG_MP_VHT_HW_TX_MODE = n/" \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Makefile + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8811cu/Makefile" # Add to section Makefile - echo "obj-\$(CONFIG_RTL8821CU) += rtl8811cu/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_RTL8821CU) += rtl8811cu/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl8811cu\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi @@ -320,34 +323,34 @@ compilation_prepare() # Wireless drivers for Realtek 8188EU 8188EUS and 8188ETV chipsets - if linux-version compare $version ge 3.14 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 3.14 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl8188euver="branch:v5.7.6.1" - display_alert "Adding" "Wireless drivers for Realtek 8188EU 8188EUS and 8188ETV chipsets ${rtl8811euver}" "info" + display_alert "Adding" "Wireless drivers for Realtek 8188EU 8188EUS and 8188ETV chipsets ${rtl8188euver}" "info" fetch_from_repo "https://github.com/aircrack-ng/rtl8188eus" "rtl8188eu" "${rtl8188euver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/ - cp -R ${SRC}/cache/sources/rtl8188eu/${rtl8188euver#*:}/{core,hal,include,os_dep,platform} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/" + cp -R "${SRC}/cache/sources/rtl8188eu/${rtl8188euver#*:}"/{core,hal,include,os_dep,platform} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu" # Makefile - cp ${SRC}/cache/sources/rtl8188eu/${rtl8188euver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/Makefile - cp ${SRC}/cache/sources/rtl8188eu/${rtl8188euver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/Kconfig + cp "${SRC}/cache/sources/rtl8188eu/${rtl8188euver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/Makefile" + cp "${SRC}/cache/sources/rtl8188eu/${rtl8188euver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/Kconfig" # Disable debug sed -i "s/^CONFIG_RTW_DEBUG.*/CONFIG_RTW_DEBUG = n/" \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/Makefile + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8188eu/Makefile" # Add to section Makefile - echo "obj-\$(CONFIG_RTL8188EU) += rtl8188eu/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_RTL8188EU) += rtl8188eu/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl8188eu\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" # kernel 5.6 -> process_patch_file "${SRC}/patch/misc/wireless-rtl8188eu.patch" "applying" @@ -359,7 +362,7 @@ compilation_prepare() # Wireless drivers for Realtek 88x2bu chipsets - if linux-version compare $version ge 3.14 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 3.14 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl88x2buver="branch:5.6.1_30362.20181109_COEX20180928-6a6a" @@ -367,26 +370,26 @@ compilation_prepare() display_alert "Adding" "Wireless drivers for Realtek 88x2bu chipsets ${rtl88x2buver}" "info" fetch_from_repo "https://github.com/cilynx/rtl88x2bu" "rtl88x2bu" "${rtl88x2buver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/ - cp -R ${SRC}/cache/sources/rtl88x2bu/${rtl88x2buver#*:}/{core,hal,include,os_dep,platform,halmac.mk,rtl8822b.mk} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/" + cp -R "${SRC}/cache/sources/rtl88x2bu/${rtl88x2buver#*:}"/{core,hal,include,os_dep,platform,halmac.mk,rtl8822b.mk} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu" # Makefile - cp ${SRC}/cache/sources/rtl88x2bu/${rtl88x2buver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/Makefile - cp ${SRC}/cache/sources/rtl88x2bu/${rtl88x2buver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/Kconfig + cp "${SRC}/cache/sources/rtl88x2bu/${rtl88x2buver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/Makefile" + cp "${SRC}/cache/sources/rtl88x2bu/${rtl88x2buver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/Kconfig" # Adjust path sed -i 's/include $(src)\/rtl8822b.mk /include $(TopDIR)\/drivers\/net\/wireless\/rtl88x2bu\/rtl8822b.mk/' \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/Makefile + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl88x2bu/Makefile" # Add to section Makefile - echo "obj-\$(CONFIG_RTL8822BU) += rtl88x2bu/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_RTL8822BU) += rtl88x2bu/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl88x2bu\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi @@ -395,7 +398,7 @@ compilation_prepare() # Wireless drivers for Realtek 8723DS chipsets - if linux-version compare $version ge 5.0 && [ "$EXTRAWIFI" == yes ]; then + if linux-version compare "${version}" ge 5.0 && [ "$EXTRAWIFI" == yes ]; then # attach to specifics tag or branch local rtl8723dsver="branch:master" @@ -403,26 +406,26 @@ compilation_prepare() display_alert "Adding" "Wireless drivers for Realtek 8723DS chipsets ${rtl8723dsver}" "info" fetch_from_repo "https://github.com/lwfinger/rtl8723ds" "rtl8723ds" "${rtl8723dsver}" "yes" - cd ${SRC}/cache/sources/${LINUXSOURCEDIR} - rm -rf ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds - mkdir -p ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/ - cp -R ${SRC}/cache/sources/rtl8723ds/${rtl8723dsver#*:}/{core,hal,include,os_dep,platform} \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds + cd "${SRC}/cache/sources/${LINUXSOURCEDIR}" || exit + rm -rf "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds" + mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/" + cp -R "${SRC}/cache/sources/rtl8723ds/${rtl8723dsver#*:}"/{core,hal,include,os_dep,platform} \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds" # Makefile - cp ${SRC}/cache/sources/rtl8723ds/${rtl8723dsver#*:}/Makefile \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/Makefile - cp ${SRC}/cache/sources/rtl8723ds/${rtl8723dsver#*:}/Kconfig \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/Kconfig + cp "${SRC}/cache/sources/rtl8723ds/${rtl8723dsver#*:}/Makefile" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/Makefile" + cp "${SRC}/cache/sources/rtl8723ds/${rtl8723dsver#*:}/Kconfig" \ + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/Kconfig" # Disable debug sed -i "s/^CONFIG_RTW_DEBUG.*/CONFIG_RTW_DEBUG = n/" \ - ${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/Makefile + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/rtl8723ds/Makefile" # Add to section Makefile - echo "obj-\$(CONFIG_RTL8723DS) += rtl8723ds/" >> $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile + echo "obj-\$(CONFIG_RTL8723DS) += rtl8723ds/" >> "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Makefile" sed -i '/source "drivers\/net\/wireless\/ti\/Kconfig"/a source "drivers\/net\/wireless\/rtl8723ds\/Kconfig"' \ - $SRC/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig + "${SRC}/cache/sources/${LINUXSOURCEDIR}/drivers/net/wireless/Kconfig" fi diff --git a/lib/general.sh b/lib/general.sh index dfe70bde29..1667588a74 100644 --- a/lib/general.sh +++ b/lib/general.sh @@ -1,3 +1,5 @@ +#!/bin/bash +# # Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com # # This file is licensed under the terms of the GNU General Public @@ -38,50 +40,50 @@ cleaning() { case $1 in debs) # delete ${DEB_STORAGE} for current branch and family - if [[ -d ${DEB_STORAGE} ]]; then + if [[ -d "${DEB_STORAGE}" ]]; then display_alert "Cleaning ${DEB_STORAGE} for" "$BOARD $BRANCH" "info" # easier than dealing with variable expansion and escaping dashes in file names - find ${DEB_STORAGE} -name "${CHOSEN_UBOOT}_*.deb" -delete - find ${DEB_STORAGE} \( -name "${CHOSEN_KERNEL}_*.deb" -o \ + find "${DEB_STORAGE}" -name "${CHOSEN_UBOOT}_*.deb" -delete + find "${DEB_STORAGE}" \( -name "${CHOSEN_KERNEL}_*.deb" -o \ -name "armbian-*.deb" -o \ -name "${CHOSEN_KERNEL/image/dtb}_*.deb" -o \ -name "${CHOSEN_KERNEL/image/headers}_*.deb" -o \ -name "${CHOSEN_KERNEL/image/source}_*.deb" -o \ -name "${CHOSEN_KERNEL/image/firmware-image}_*.deb" \) -delete - [[ -n $RELEASE ]] && rm -f ${DEB_STORAGE}/$RELEASE/${CHOSEN_ROOTFS}_*.deb - [[ -n $RELEASE ]] && rm -f ${DEB_STORAGE}/$RELEASE/armbian-desktop-${RELEASE}_*.deb + [[ -n $RELEASE ]] && rm -f "${DEB_STORAGE}/${RELEASE}/${CHOSEN_ROOTFS}"_*.deb + [[ -n $RELEASE ]] && rm -f "${DEB_STORAGE}/${RELEASE}/armbian-desktop-${RELEASE}"_*.deb fi ;; extras) # delete ${DEB_STORAGE}/extra/$RELEASE for all architectures if [[ -n $RELEASE && -d ${DEB_STORAGE}/extra/$RELEASE ]]; then display_alert "Cleaning ${DEB_STORAGE}/extra for" "$RELEASE" "info" - rm -rf ${DEB_STORAGE}/extra/$RELEASE + rm -rf "${DEB_STORAGE}/extra/${RELEASE}" fi ;; alldebs) # delete output/debs - [[ -d ${DEB_STORAGE} ]] && display_alert "Cleaning" "${DEB_STORAGE}" "info" && rm -rf ${DEB_STORAGE}/* + [[ -d "${DEB_STORAGE}" ]] && display_alert "Cleaning" "${DEB_STORAGE}" "info" && rm -rf "${DEB_STORAGE}"/* ;; cache) # delete output/cache - [[ -d $SRC/cache/rootfs ]] && display_alert "Cleaning" "rootfs cache (all)" "info" && find $SRC/cache/rootfs -type f -delete + [[ -d "${SRC}"/cache/rootfs ]] && display_alert "Cleaning" "rootfs cache (all)" "info" && find "${SRC}"/cache/rootfs -type f -delete ;; images) # delete output/images - [[ -d $DEST/images ]] && display_alert "Cleaning" "output/images" "info" && rm -rf $DEST/images/* + [[ -d "${DEST}"/images ]] && display_alert "Cleaning" "output/images" "info" && rm -rf "${DEST}"/images/* ;; sources) # delete output/sources and output/buildpkg - [[ -d $SRC/cache/sources ]] && display_alert "Cleaning" "sources" "info" && rm -rf $SRC/cache/sources/* $DEST/buildpkg/* + [[ -d "${SRC}"/cache/sources ]] && display_alert "Cleaning" "sources" "info" && rm -rf "${SRC}"/cache/sources/* "${DEST}"/buildpkg/* ;; oldcache) # remove old `cache/rootfs` except for the newest 8 files - if [[ -d $SRC/cache/rootfs && $(ls -1 $SRC/cache/rootfs/*.lz4 2> /dev/null | wc -l) -gt ${ROOTFS_CACHE_MAX} ]]; then + if [[ -d "${SRC}"/cache/rootfs && $(ls -1 "${SRC}"/cache/rootfs/*.lz4 2> /dev/null | wc -l) -gt "${ROOTFS_CACHE_MAX}" ]]; then display_alert "Cleaning" "rootfs cache (old)" "info" - (cd $SRC/cache/rootfs; ls -t *.lz4 | sed -e "1,${ROOTFS_CACHE_MAX}d" | xargs -d '\n' rm -f) + (cd "${SRC}"/cache/rootfs; ls -t *.lz4 | sed -e "1,${ROOTFS_CACHE_MAX}d" | xargs -d '\n' rm -f) # Remove signatures if they are present. We use them for internal purpose - (cd $SRC/cache/rootfs; ls -t *.asc | sed -e "1,${ROOTFS_CACHE_MAX}d" | xargs -d '\n' rm -f) + (cd "${SRC}"/cache/rootfs; ls -t *.asc | sed -e "1,${ROOTFS_CACHE_MAX}d" | xargs -d '\n' rm -f) fi ;; esac @@ -95,11 +97,12 @@ cleaning() exit_with_error() { - local _file=$(basename ${BASH_SOURCE[1]}) + local _file local _line=${BASH_LINENO[0]} local _function=${FUNCNAME[1]} local _description=$1 local _highlight=$2 + _file=$(basename "${BASH_SOURCE[1]}") display_alert "ERROR in function $_function" "$_file:$_line" "err" display_alert "$_description" "$_highlight" "err" @@ -108,9 +111,9 @@ exit_with_error() overlayfs_wrapper "cleanup" # unlock loop device access in case of starvation exec {FD}>/var/lock/armbian-debootstrap-losetup - flock -u $FD + flock -u "${FD}" - exit -1 + exit 255 } # get_package_list_hash @@ -119,7 +122,7 @@ exit_with_error() get_package_list_hash() { - ( printf '%s\n' $PACKAGE_LIST | sort -u; printf '%s\n' $PACKAGE_LIST_EXCLUDE | sort -u; echo "$1" ) \ + ( printf '%s\n' "${PACKAGE_LIST}" | sort -u; printf '%s\n' "${PACKAGE_LIST_EXCLUDE}" | sort -u; echo "${1}" ) \ | md5sum | cut -d' ' -f 1 } @@ -136,7 +139,7 @@ create_sources_list() case $release in stretch|buster|bullseye) - cat <<-EOF > $basedir/etc/apt/sources.list + cat <<-EOF > "${basedir}"/etc/apt/sources.list deb http://${DEBIAN_MIRROR} $release main contrib non-free #deb-src http://${DEBIAN_MIRROR} $release main contrib non-free @@ -152,7 +155,7 @@ create_sources_list() ;; xenial|bionic|eoan|focal) - cat <<-EOF > $basedir/etc/apt/sources.list + cat <<-EOF > "${basedir}"/etc/apt/sources.list deb http://${UBUNTU_MIRROR} $release main restricted universe multiverse #deb-src http://${UBUNTU_MIRROR} $release main restricted universe multiverse @@ -171,7 +174,7 @@ create_sources_list() # workaround for Chromium by downloading it from Debian if [[ $release == focal || $release == eoan ]]; then - cat <<-EOF > $basedir/etc/apt/preferences.d/chromium.pref + cat <<-EOF > "${basedir}"/etc/apt/preferences.d/chromium.pref # Note: 2 blank lines are required between entries Package: * Pin: release a=${release} @@ -188,7 +191,7 @@ create_sources_list() Pin-Priority: 700 EOF - cat <<-EOF > $basedir/etc/apt/sources.list.d/debian.list + cat <<-EOF > "${basedir}"/etc/apt/sources.list.d/debian.list deb http://${DEBIAN_MIRROR} stable main deb http://${DEBIAN_MIRROR} stable-updates main deb http://${DEBIAN_MIRROR}-security stable/updates main @@ -200,18 +203,18 @@ create_sources_list() # stage: add armbian repository and install key if [[ $DOWNLOAD_MIRROR == "china" ]]; then - echo "deb http://mirrors.tuna.tsinghua.edu.cn/armbian $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" > $SDCARD/etc/apt/sources.list.d/armbian.list + echo "deb http://mirrors.tuna.tsinghua.edu.cn/armbian $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" > "${SDCARD}"/etc/apt/sources.list.d/armbian.list else - echo "deb http://apt.armbian.com $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" > $SDCARD/etc/apt/sources.list.d/armbian.list + echo "deb http://apt.armbian.com $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" > "${SDCARD}"/etc/apt/sources.list.d/armbian.list fi # add local package server if defined. Suitable for development - [[ -n $LOCAL_MIRROR ]] && echo "deb http://$LOCAL_MIRROR $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" >> $SDCARD/etc/apt/sources.list.d/armbian.list + [[ -n $LOCAL_MIRROR ]] && echo "deb http://$LOCAL_MIRROR $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" >> "${SDCARD}"/etc/apt/sources.list.d/armbian.list display_alert "Adding Armbian repository and authentication key" "/etc/apt/sources.list.d/armbian.list" "info" - cp $SRC/config/armbian.key $SDCARD - chroot $SDCARD /bin/bash -c "cat armbian.key | apt-key add - > /dev/null 2>&1" - rm $SDCARD/armbian.key + cp "${SRC}"/config/armbian.key "${SDCARD}" + chroot "${SDCARD}" /bin/bash -c "cat armbian.key | apt-key add - > /dev/null 2>&1" + rm "${SDCARD}"/armbian.key } # fetch_from_repo @@ -261,10 +264,10 @@ fetch_from_repo() local workdir=$dir fi - mkdir -p $SRC/cache/sources/$workdir 2>/dev/null || \ - exit_with_error "No path or no write permission" "$SRC/cache/sources/$workdir" + mkdir -p "${SRC}/cache/sources/${workdir}" 2>/dev/null || \ + exit_with_error "No path or no write permission" "${SRC}/cache/sources/${workdir}" - cd $SRC/cache/sources/$workdir + cd "${SRC}/cache/sources/${workdir}" || exit # check if existing remote URL for the repo or branch does not match current one # may not be supported by older git versions @@ -274,13 +277,13 @@ fetch_from_repo() if [[ "$(git rev-parse --git-dir 2>/dev/null)" == ".git" && \ "$url" != "$(git remote get-url origin 2>/dev/null)" ]]; then display_alert "Remote URL does not match, removing existing local copy" - rm -rf .git * + rm -rf .git ./* fi if [[ "$(git rev-parse --git-dir 2>/dev/null)" != ".git" ]]; then display_alert "Creating local copy" git init -q . - git remote add origin $url + git remote add origin "${url}" # Here you need to upload from a new address offline=false fi @@ -289,26 +292,30 @@ fetch_from_repo() # when we work offline we simply return the sources to their original state if ! $offline; then - local local_hash=$(git rev-parse @ 2>/dev/null) + local local_hash + local_hash=$(git rev-parse @ 2>/dev/null) case $ref_type in branch) # TODO: grep refs/heads/$name - local remote_hash=$(git ls-remote -h $url "$ref_name" | head -1 | cut -f1) - [[ -z $local_hash || $local_hash != $remote_hash ]] && changed=true + local remote_hash + remote_hash=$(git ls-remote -h "${url}" "$ref_name" | head -1 | cut -f1) + [[ -z $local_hash || "${local_hash}" != "${remote_hash}" ]] && changed=true ;; tag) - local remote_hash=$(git ls-remote -t $url "$ref_name" | cut -f1) - if [[ -z $local_hash || $local_hash != $remote_hash ]]; then - remote_hash=$(git ls-remote -t $url "$ref_name^{}" | cut -f1) - [[ -z $remote_hash || $local_hash != $remote_hash ]] && changed=true + local remote_hash + remote_hash=$(git ls-remote -t "${url}" "$ref_name" | cut -f1) + if [[ -z $local_hash || "${local_hash}" != "${remote_hash}" ]]; then + remote_hash=$(git ls-remote -t "${url}" "$ref_name^{}" | cut -f1) + [[ -z $remote_hash || "${local_hash}" != "${remote_hash}" ]] && changed=true fi ;; head) - local remote_hash=$(git ls-remote $url HEAD | cut -f1) - [[ -z $local_hash || $local_hash != $remote_hash ]] && changed=true + local remote_hash + remote_hash=$(git ls-remote "${url}" HEAD | cut -f1) + [[ -z $local_hash || "${local_hash}" != "${remote_hash}" ]] && changed=true ;; commit) @@ -323,22 +330,22 @@ fetch_from_repo() # remote was updated, fetch and check out updates display_alert "Fetching updates" case $ref_type in - branch) git fetch --depth 1 origin $ref_name ;; - tag) git fetch --depth 1 origin tags/$ref_name ;; + branch) git fetch --depth 1 origin "${ref_name}" ;; + tag) git fetch --depth 1 origin tags/"${ref_name}" ;; head) git fetch --depth 1 origin HEAD ;; esac # commit type needs support for older git servers that doesn't support fetching id directly if [[ $ref_type == commit ]]; then - git fetch --depth 1 origin $ref_name + git fetch --depth 1 origin "${ref_name}" # cover old type if [[ $? -ne 0 ]]; then display_alert "Commit checkout not supported on this repository. Doing full clone." "" "wrn" git pull - git checkout -fq $ref_name + git checkout -fq "${ref_name}" display_alert "Checkout out to" "$(git --no-pager log -2 --pretty=format:"$ad%s [%an]" | head -1)" "info" else @@ -374,9 +381,10 @@ fetch_from_repo() display_alert "Updating submodules" "" "ext" # FML: http://stackoverflow.com/a/17692710 for i in $(git config -f .gitmodules --get-regexp path | awk '{ print $2 }'); do - cd $SRC/cache/sources/$workdir - local surl=$(git config -f .gitmodules --get "submodule.$i.url") - local sref=$(git config -f .gitmodules --get "submodule.$i.branch") + cd "${SRC}/cache/sources/${workdir}" || exit + local surl sref + surl=$(git config -f .gitmodules --get "submodule.$i.url") + sref=$(git config -f .gitmodules --get "submodule.$i.branch") if [[ -n $sref ]]; then sref="branch:$sref" else @@ -393,7 +401,7 @@ fetch_from_repo() display_alert() { # log function parameters to install.log - [[ -n $DEST ]] && echo "Displaying message: $@" >> $DEST/debug/output.log + [[ -n "${DEST}" ]] && echo "Displaying message: $@" >> "${DEST}"/debug/output.log local tmp="" [[ -n $2 ]] && tmp="[\e[0;33m $2 \x1B[0m]" @@ -428,7 +436,7 @@ display_alert() fingerprint_image() { display_alert "Fingerprinting" - cat <<-EOF > $1 + cat <<-EOF > "${1}" -------------------------------------------------------------------------------- Title: Armbian $REVISION ${BOARD^} $DISTRIBUTION $RELEASE $BRANCH Kernel: Linux $VER @@ -442,7 +450,7 @@ fingerprint_image() EOF if [ -n "$2" ]; then - cat <<-EOF >> $1 + cat <<-EOF >> "${1}" -------------------------------------------------------------------------------- Partitioning configuration: Root partition type: $ROOTFS_TYPE @@ -465,9 +473,9 @@ fingerprint_image() EOF fi - cat <<-EOF >> $1 + cat <<-EOF >> "${1}" -------------------------------------------------------------------------------- - $(cat $SRC/LICENSE) + $(cat "${SRC}"/LICENSE) -------------------------------------------------------------------------------- EOF } @@ -482,7 +490,7 @@ function distro_menu () for i in "${!distro_name[@]}" do - if [[ $i == $1 ]]; then + if [[ "${i}" == "${1}" ]]; then if [[ "${distro_support[$i]}" != "supported" && $EXPERT != "yes" ]]; then : else @@ -505,16 +513,17 @@ adding_packages() # add deb files to repository if they are not already there display_alert "Checking and adding to repository $release" "$3" "ext" - for f in ${DEB_STORAGE}$2/*.deb + for f in "${DEB_STORAGE}${2}"/*.deb do - local name=$(dpkg-deb -I $f | grep Package | awk '{print $2}') - local version=$(dpkg-deb -I $f | grep Version | awk '{print $2}') - local arch=$(dpkg-deb -I $f | grep Architecture | awk '{print $2}') + local name version arch + name=$(dpkg-deb -I "${f}" | grep Package | awk '{print $2}') + version=$(dpkg-deb -I "${f}" | grep Version | awk '{print $2}') + arch=$(dpkg-deb -I "${f}" | grep Architecture | awk '{print $2}') # add if not already there - aptly repo search -architectures=$arch -config=${SCRIPTPATH}config/${REPO_CONFIG} $1 'Name (% '$name'), $Version (='$version'), $Architecture (='$arch')' &>/dev/null + aptly repo search -architectures="${arch}" -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${1}" 'Name (% '${name}'), $Version (='${version}'), $Architecture (='${arch}')' &>/dev/null if [[ $? -ne 0 ]]; then display_alert "Adding" "$name" "info" - aptly repo add -force-replace=true -config=${SCRIPTPATH}config/${REPO_CONFIG} $1 ${f} &>/dev/null + aptly repo add -force-replace=true -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${1}" "${f}" &>/dev/null fi done @@ -538,74 +547,75 @@ addtorepo() local forceoverwrite="" # let's drop from publish if exits - if [[ -n $(aptly publish list -config=${SCRIPTPATH}config/${REPO_CONFIG} -raw | awk '{print $(NF)}' | grep $release) ]]; then - aptly publish drop -config=${SCRIPTPATH}config/${REPO_CONFIG} $release > /dev/null 2>&1 + if [[ -n $(aptly publish list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}") ]]; then + aptly publish drop -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" > /dev/null 2>&1 fi # create local repository if not exist - if [[ -z $(aptly repo list -config=${SCRIPTPATH}config/${REPO_CONFIG} -raw | awk '{print $(NF)}' | grep $release) ]]; then + if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}") ]]; then display_alert "Creating section" "$release" "info" - aptly repo create -config=${SCRIPTPATH}config/${REPO_CONFIG} -distribution=$release -component="main" \ - -comment="Armbian main repository" ${release} >/dev/null + aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="main" \ + -comment="Armbian main repository" "${release}" >/dev/null fi - if [[ -z $(aptly repo list -config=${SCRIPTPATH}config/${REPO_CONFIG} -raw | awk '{print $(NF)}' | grep "^utils") ]]; then - aptly repo create -config=${SCRIPTPATH}config/${REPO_CONFIG} -distribution=$release -component="utils" \ + if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "^utils") ]]; then + aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="utils" \ -comment="Armbian utilities (backwards compatibility)" utils >/dev/null fi - if [[ -z $(aptly repo list -config=${SCRIPTPATH}config/${REPO_CONFIG} -raw | awk '{print $(NF)}' | grep "${release}-utils") ]]; then - aptly repo create -config=${SCRIPTPATH}config/${REPO_CONFIG} -distribution=$release -component="${release}-utils" \ - -comment="Armbian ${release} utilities" ${release}-utils >/dev/null + if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}-utils") ]]; then + aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="${release}-utils" \ + -comment="Armbian ${release} utilities" "${release}-utils" >/dev/null fi - if [[ -z $(aptly repo list -config=${SCRIPTPATH}config/${REPO_CONFIG} -raw | awk '{print $(NF)}' | grep "${release}-desktop") ]]; then - aptly repo create -config=${SCRIPTPATH}config/${REPO_CONFIG} -distribution=$release -component="${release}-desktop" \ - -comment="Armbian ${release} desktop" ${release}-desktop >/dev/null + if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}-desktop") ]]; then + aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="${release}-desktop" \ + -comment="Armbian ${release} desktop" "${release}-desktop" >/dev/null fi # adding main - if find ${DEB_STORAGE}/ -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then + if find "${DEB_STORAGE}"/ -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then adding_packages "$release" "" "main" else - aptly repo add -config=${SCRIPTPATH}config/${REPO_CONFIG} $release ${SCRIPTPATH}config/templates/example.deb >/dev/null + aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" "${SCRIPTPATH}config/templates/example.deb" >/dev/null fi local COMPONENTS="main" # adding main distribution packages - if find ${DEB_STORAGE}/${release} -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then + if find "${DEB_STORAGE}/${release}" -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then adding_packages "$release" "/${release}" "release" else # workaround - add dummy package to not trigger error - aptly repo add -config=${SCRIPTPATH}config/${REPO_CONFIG} $release ${SCRIPTPATH}config/templates/example.deb >/dev/null + aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" "${SCRIPTPATH}config/templates/example.deb" >/dev/null fi # adding release-specific utils - if find ${DEB_STORAGE}/extra/${release}-utils -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then + if find "${DEB_STORAGE}/extra/${release}-utils" -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then adding_packages "${release}-utils" "/extra/${release}-utils" "release utils" else - aptly repo add -config=${SCRIPTPATH}config/${REPO_CONFIG} "${release}-utils" ${SCRIPTPATH}config/templates/example.deb >/dev/null + aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-utils" "${SCRIPTPATH}config/templates/example.deb" >/dev/null fi COMPONENTS="${COMPONENTS} ${release}-utils" # adding desktop - if find ${DEB_STORAGE}/extra/${release}-desktop -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then + if find "${DEB_STORAGE}/extra/${release}-desktop" -maxdepth 1 -type f -name "*.deb" 2>/dev/null | grep -q .; then adding_packages "${release}-desktop" "/extra/${release}-desktop" "desktop" else # workaround - add dummy package to not trigger error - aptly repo add -config=${SCRIPTPATH}config/${REPO_CONFIG} "${release}-desktop" ${SCRIPTPATH}config/templates/example.deb >/dev/null + aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" "${SCRIPTPATH}config/templates/example.deb" >/dev/null fi COMPONENTS="${COMPONENTS} ${release}-desktop" - local mainnum=$(aptly repo show -with-packages -config=${SCRIPTPATH}config/${REPO_CONFIG} $release | grep "Number of packages" | awk '{print $NF}') - local utilnum=$(aptly repo show -with-packages -config=${SCRIPTPATH}config/${REPO_CONFIG} ${release}-desktop | grep "Number of packages" | awk '{print $NF}') - local desknum=$(aptly repo show -with-packages -config=${SCRIPTPATH}config/${REPO_CONFIG} ${release}-utils | grep "Number of packages" | awk '{print $NF}') + local mainnum utilnum desknum + mainnum=$(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" | grep "Number of packages" | awk '{print $NF}') + utilnum=$(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" | grep "Number of packages" | awk '{print $NF}') + desknum=$(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-utils" | grep "Number of packages" | awk '{print $NF}') if [ $mainnum -gt 0 ] && [ $utilnum -gt 0 ] && [ $desknum -gt 0 ]; then # publish - aptly publish -force-overwrite -passphrase=$GPG_PASS -origin=Armbian -label=Armbian -config=${SCRIPTPATH}config/${REPO_CONFIG} -component=${COMPONENTS// /,} \ - --distribution=$release repo $release ${COMPONENTS//main/} >/dev/null + aptly publish -force-overwrite -passphrase="${GPG_PASS}" -origin=Armbian -label=Armbian -config="${SCRIPTPATH}config/${REPO_CONFIG}" -component="${COMPONENTS// /,}" \ + --distribution="${release}" repo "${release}" "${COMPONENTS//main/}" >/dev/null if [[ $? -ne 0 ]]; then - display_alert "Publishing failed" "$release" "err" + display_alert "Publishing failed" "${release}" "err" errors=$((errors+1)) exit 0 fi @@ -618,18 +628,18 @@ addtorepo() # cleanup display_alert "Cleaning repository" "${DEB_STORAGE}" "info" - aptly db cleanup -config=${SCRIPTPATH}config/${REPO_CONFIG} + aptly db cleanup -config="${SCRIPTPATH}config/${REPO_CONFIG}" # display what we have echo "" display_alert "List of local repos" "local" "info" - (aptly repo list -config=${SCRIPTPATH}config/${REPO_CONFIG}) | egrep packages + (aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}") | grep -E packages # remove debs if no errors found if [[ $errors -eq 0 ]]; then if [[ "$2" == "delete" ]]; then display_alert "Purging incoming debs" "all" "ext" - find ${DEB_STORAGE} -name "*.deb" -type f -delete + find "${DEB_STORAGE}" -name "*.deb" -type f -delete fi else display_alert "There were some problems $err_txt" "leaving incoming directory intact" "err" @@ -646,18 +656,18 @@ repo-manipulate() { serve) # display repository content display_alert "Serving content" "common utils" "ext" - aptly serve -listen=$(ip -f inet addr | grep -Po 'inet \K[\d.]+' | grep -v 127.0.0.1 | head -1):8080 -config="${SCRIPTPATH}"config/${REPO_CONFIG} + aptly serve -listen=$(ip -f inet addr | grep -Po 'inet \K[\d.]+' | grep -v 127.0.0.1 | head -1):8080 -config="${SCRIPTPATH}config/${REPO_CONFIG}" exit 0 ;; show) # display repository content for release in "${DISTROS[@]}"; do display_alert "Displaying repository contents for" "$release" "ext" - aptly repo show -with-packages -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${release}" | tail -n +7 - aptly repo show -with-packages -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${release}-desktop" | tail -n +7 + aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" | tail -n +7 + aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" | tail -n +7 done display_alert "Displaying repository contents for" "common utils" "ext" - aptly repo show -with-packages -config="${SCRIPTPATH}"config/${REPO_CONFIG} utils | tail -n +7 + aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" utils | tail -n +7 echo "done." exit 0 ;; @@ -667,10 +677,10 @@ repo-manipulate() { while true; do LIST=() for release in "${DISTROS[@]}"; do - LIST+=( $(aptly repo show -with-packages -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${release}" | tail -n +7) ) - LIST+=( $(aptly repo show -with-packages -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${release}-desktop" | tail -n +7) ) + LIST+=( $(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" | tail -n +7) ) + LIST+=( $(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" | tail -n +7) ) done - LIST+=( $(aptly repo show -with-packages -config="${SCRIPTPATH}"config/${REPO_CONFIG} utils | tail -n +7) ) + LIST+=( $(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" utils | tail -n +7) ) LIST=( $(echo "${LIST[@]}" | tr ' ' '\n' | sort -u)) new_list=() # create a human readable menu @@ -687,10 +697,10 @@ repo-manipulate() { exec 3>&- if [[ $exitstatus -eq 0 ]]; then for release in "${DISTROS[@]}"; do - aptly repo remove -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${release}" "$TARGET_VERSION" - aptly repo remove -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${release}-desktop" "$TARGET_VERSION" + aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" "$TARGET_VERSION" + aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" "$TARGET_VERSION" done - aptly repo remove -config="${SCRIPTPATH}"config/${REPO_CONFIG} "utils" "$TARGET_VERSION" + aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "utils" "$TARGET_VERSION" else exit 1 fi @@ -709,16 +719,16 @@ repo-manipulate() { repo-remove-old-packages "$release" "armhf" "5" repo-remove-old-packages "$release" "arm64" "5" repo-remove-old-packages "$release" "all" "5" - aptly -config="${SCRIPTPATH}"config/${REPO_CONFIG} -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 + aptly -config="${SCRIPTPATH}config/${REPO_CONFIG}" -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 done exit 0 ;; purgesource) for release in "${DISTROS[@]}"; do - aptly repo remove -config=${SCRIPTPATH}config/${REPO_CONFIG} ${release} 'Name (% *-source*)' - aptly -config="${SCRIPTPATH}"config/${REPO_CONFIG} -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 + aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" 'Name (% *-source*)' + aptly -config="${SCRIPTPATH}config/${REPO_CONFIG}" -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 done - aptly db cleanup -config=${SCRIPTPATH}config/${REPO_CONFIG} > /dev/null 2>&1 + aptly db cleanup -config="${SCRIPTPATH}config/${REPO_CONFIG}" > /dev/null 2>&1 exit 0 ;; *) @@ -745,7 +755,7 @@ repo-remove-old-packages() { local arch=$2 local keep=$3 - for pkg in $(aptly repo search -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${repo}" "Architecture ($arch)" | grep -v "ERROR: no results" | sort -rV); do + for pkg in $(aptly repo search -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${repo}" "Architecture ($arch)" | grep -v "ERROR: no results" | sort -rV); do local pkg_name pkg_name=$(echo "${pkg}" | cut -d_ -f1) if [ "$pkg_name" != "$cur_pkg" ]; then @@ -757,7 +767,7 @@ repo-remove-old-packages() { ((count+=1)) if [[ $count -gt $keep ]]; then pkg_version=$(echo "${pkg}" | cut -d_ -f2) - aptly repo remove -config="${SCRIPTPATH}"config/${REPO_CONFIG} "${repo}" "Name ($pkg_name), Version (<= $pkg_version)" + aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${repo}" "Name ($pkg_name), Version (<= $pkg_version)" deleted='yes' fi done @@ -921,9 +931,9 @@ prepare_host() # distribution packages are buggy, download from author if [[ ! -f /etc/apt/sources.list.d/aptly.list ]]; then display_alert "Updating from external repository" "aptly" "info" - if [ x"" != x$http_proxy ]; then - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=$http_proxy --recv-keys ED75B5A4483DA07C >/dev/null 2>&1 - apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --keyserver-options http-proxy=$http_proxy --recv-keys ED75B5A4483DA07C >/dev/null 2>&1 + if [ x"" != x"${http_proxy}" ]; then + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy="${http_proxy}" --recv-keys ED75B5A4483DA07C >/dev/null 2>&1 + apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --keyserver-options http-proxy="${http_proxy}" --recv-keys ED75B5A4483DA07C >/dev/null 2>&1 else apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ED75B5A4483DA07C >/dev/null 2>&1 apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys ED75B5A4483DA07C >/dev/null 2>&1 @@ -937,14 +947,14 @@ prepare_host() display_alert "Installing build dependencies" apt-get -q update apt-get -y upgrade - apt-get -q -y --no-install-recommends install -o Dpkg::Options::='--force-confold' "${deps[@]}" | tee -a $DEST/debug/hostdeps.log + apt-get -q -y --no-install-recommends install -o Dpkg::Options::='--force-confold' "${deps[@]}" | tee -a "${DEST}"/debug/hostdeps.log update-ccache-symlinks fi # sync clock if [[ $SYNC_CLOCK != no ]]; then display_alert "Syncing clock" "host" "info" - ntpdate -s ${NTP_SERVER:- pool.ntp.org} + ntpdate -s "${NTP_SERVER:- pool.ntp.org}" fi if [[ $(dpkg-query -W -f='${db:Status-Abbrev}\n' 'zlib1g:i386' 2>/dev/null) != *ii* ]]; then @@ -952,16 +962,16 @@ prepare_host() fi # create directory structure - mkdir -p $SRC/{cache,output} $USERPATCHES_PATH + mkdir -p "${SRC}"/{cache,output} "${USERPATCHES_PATH}" if [[ -n $SUDO_USER ]]; then - chgrp --quiet sudo cache output $USERPATCHES_PATH + chgrp --quiet sudo cache output "${USERPATCHES_PATH}" # SGID bit on cache/sources breaks kernel dpkg packaging - chmod --quiet g+w,g+s output $USERPATCHES_PATH + chmod --quiet g+w,g+s output "${USERPATCHES_PATH}" # fix existing permissions - find $SRC/output $USERPATCHES_PATH -type d ! -group sudo -exec chgrp --quiet sudo {} \; - find $SRC/output $USERPATCHES_PATH -type d ! -perm -g+w,g+s -exec chmod --quiet g+w,g+s {} \; + find "${SRC}"/output "${USERPATCHES_PATH}" -type d ! -group sudo -exec chgrp --quiet sudo {} \; + find "${SRC}"/output "${USERPATCHES_PATH}" -type d ! -perm -g+w,g+s -exec chmod --quiet g+w,g+s {} \; fi - mkdir -p $DEST/debs-beta/extra $DEST/debs/extra $DEST/{config,debug,patch} $USERPATCHES_PATH/overlay $SRC/cache/{sources,hash,toolchains,utility,rootfs} $SRC/.tmp + mkdir -p "${DEST}"/debs-beta/extra "${DEST}"/debs/extra "${DEST}"/{config,debug,patch} "${USERPATCHES_PATH}"/overlay "${SRC}"/cache/{sources,hash,toolchains,utility,rootfs} "${SRC}"/.tmp display_alert "Checking for external GCC compilers" "" "info" # download external Linaro compiler and missing special dependencies since they are needed for certain sources @@ -990,8 +1000,8 @@ prepare_host() download_and_verify "_toolchains" "${toolchain##*/}" done - rm -rf $SRC/cache/toolchains/*.tar.xz* - local existing_dirs=( $(ls -1 $SRC/cache/toolchains) ) + rm -rf "${SRC}"/cache/toolchains/*.tar.xz* + local existing_dirs=( $(ls -1 "${SRC}"/cache/toolchains) ) for dir in ${existing_dirs[@]}; do local found=no for toolchain in ${toolchains[@]}; do @@ -1001,7 +1011,7 @@ prepare_host() done if [[ $found == no ]]; then display_alert "Removing obsolete toolchain" "$dir" - rm -rf $SRC/cache/toolchains/$dir + rm -rf "${SRC}/cache/toolchains/${dir}" fi done @@ -1015,19 +1025,19 @@ prepare_host() test -e /proc/sys/fs/binfmt_misc/qemu-aarch64 || update-binfmts --enable qemu-aarch64 fi - [[ ! -f $USERPATCHES_PATH/customize-image.sh ]] && cp $SRC/config/templates/customize-image.sh.template $USERPATCHES_PATH/customize-image.sh + [[ ! -f "${USERPATCHES_PATH}"/customize-image.sh ]] && cp "${SRC}"/config/templates/customize-image.sh.template "${USERPATCHES_PATH}"/customize-image.sh - if [[ ! -f $USERPATCHES_PATH/README ]]; then - rm -f $USERPATCHES_PATH/readme.txt - echo 'Please read documentation about customizing build configuration' > $USERPATCHES_PATH/README - echo 'http://www.armbian.com/using-armbian-tools/' >> $USERPATCHES_PATH/README + if [[ ! -f "${USERPATCHES_PATH}"/README ]]; then + rm -f "${USERPATCHES_PATH}"/readme.txt + echo 'Please read documentation about customizing build configuration' > "${USERPATCHES_PATH}"/README + echo 'http://www.armbian.com/using-armbian-tools/' >> "${USERPATCHES_PATH}"/README # create patches directory structure under USERPATCHES_PATH - find $SRC/patch -maxdepth 2 -type d ! -name . | sed "s%/.*patch%/$USERPATCHES_PATH%" | xargs mkdir -p + find "${SRC}"/patch -maxdepth 2 -type d ! -name . | sed "s%/.*patch%/$USERPATCHES_PATH%" | xargs mkdir -p fi # check free space (basic) - local freespace=$(findmnt --target $SRC -n -o AVAIL -b 2>/dev/null) # in bytes + local freespace=$(findmnt --target "${SRC}" -n -o AVAIL -b 2>/dev/null) # in bytes if [[ -n $freespace && $(( $freespace / 1073741824 )) -lt 10 ]]; then display_alert "Low free space left" "$(( $freespace / 1073741824 )) GiB" "wrn" # pause here since dialog-based menu will hide this message otherwise @@ -1063,12 +1073,12 @@ WEBSEED=( fi for toolchain in ${WEBSEED[@]}; do # use only live - if [[ `wget -S --spider $toolchain$1 2>&1 >/dev/null | grep 'HTTP/1.1 200 OK'` ]]; then - text=$text" "$toolchain$1 + if [[ $(wget -S --spider "${toolchain}${1}" 2>&1 >/dev/null | grep 'HTTP/1.1 200 OK') ]]; then + text="${text} ${toolchain}${1}" fi done text="${text:1}" - echo $text + echo "${text}" } @@ -1079,7 +1089,7 @@ download_and_verify() local remotedir=$1 local filename=$2 - local localdir=$SRC/cache/${remotedir//_} + local localdir="${SRC}"/cache/${remotedir//_} local dirname=${filename//.tar.xz} if [[ $DOWNLOAD_MIRROR == china ]]; then @@ -1092,19 +1102,19 @@ download_and_verify() return fi - cd ${localdir} + cd "${localdir}" || exit # use local control file - if [[ -f $SRC/config/torrents/${filename}.asc ]]; then - local torrent=$SRC/config/torrents/${filename}.torrent - ln -s $SRC/config/torrents/${filename}.asc ${localdir}/${filename}.asc - elif [[ ! `wget -S --spider ${server}${remotedir}/${filename}.asc 2>&1 >/dev/null | grep 'HTTP/1.1 200 OK'` ]]; then + if [[ -f "${SRC}"/config/torrents/${filename}.asc ]]; then + local torrent="${SRC}"/config/torrents/${filename}.torrent + ln -s "${SRC}/config/torrents/${filename}.asc" "${localdir}/${filename}.asc" + elif [[ ! $(wget -S --spider "${server}${remotedir}/${filename}.asc" 2>&1 >/dev/null | grep 'HTTP/1.1 200 OK') ]]; then return else # download control file local torrent=${server}torrent/${filename}.torrent aria2c --download-result=hide --disable-ipv6=true --summary-interval=0 --console-log-level=error --auto-file-renaming=false \ - --continue=false --allow-overwrite=true --dir=${localdir} $(webseed "$remotedir/${filename}.asc") -o "${filename}.asc" + --continue=false --allow-overwrite=true --dir="${localdir}" "$(webseed "$remotedir/${filename}.asc")" -o "${filename}.asc" [[ $? -ne 0 ]] && display_alert "Failed to download control file" "" "wrn" fi @@ -1115,75 +1125,75 @@ download_and_verify() local ariatorrent="--summary-interval=0 --auto-save-interval=0 --seed-time=0 --bt-stop-timeout=15 --console-log-level=error \ --allow-overwrite=true --download-result=hide --rpc-save-upload-metadata=false --auto-file-renaming=false \ --file-allocation=trunc --continue=true ${torrent} \ - --dht-file-path=$SRC/cache/.aria2/dht.dat --disable-ipv6=true --stderr --follow-torrent=mem --dir=${localdir}" + --dht-file-path=${SRC}/cache/.aria2/dht.dat --disable-ipv6=true --stderr --follow-torrent=mem --dir=${localdir}" # exception. It throws error if dht.dat file does not exists. Error suppress needed only at first download. - if [[ -f $SRC/cache/.aria2/dht.dat ]]; then - aria2c ${ariatorrent} + if [[ -f "${SRC}"/cache/.aria2/dht.dat ]]; then + aria2c "${ariatorrent}" else - aria2c ${ariatorrent} &> $DEST/debug/torrent.log + aria2c "${ariatorrent}" &> "${DEST}"/debug/torrent.log fi # mark complete - [[ $? -eq 0 ]] && touch ${localdir}/${filename}.complete + [[ $? -eq 0 ]] && touch "${localdir}/${filename}.complete" fi # direct download if torrent fails - if [[ ! -f ${localdir}/${filename}.complete ]]; then - if [[ `wget -S --spider ${server}${remotedir}/${filename} 2>&1 >/dev/null \ - | grep 'HTTP/1.1 200 OK'` ]]; then + if [[ ! -f "${localdir}/${filename}.complete" ]]; then + if [[ $(wget -S --spider "${server}${remotedir}/${filename}" 2>&1 >/dev/null \ + | grep 'HTTP/1.1 200 OK') ]]; then display_alert "downloading using http(s) network" "$filename" aria2c --download-result=hide --rpc-save-upload-metadata=false --console-log-level=error \ - --dht-file-path=$SRC/cache/.aria2/dht.dat --disable-ipv6=true --summary-interval=0 --auto-file-renaming=false --dir=${localdir} $(webseed "$remotedir/$filename") -o ${filename} + --dht-file-path="${SRC}"/cache/.aria2/dht.dat --disable-ipv6=true --summary-interval=0 --auto-file-renaming=false --dir="${localdir}" "$(webseed "${remotedir}/${filename}")" -o "${filename}" # mark complete - [[ $? -eq 0 ]] && touch ${localdir}/${filename}.complete && echo "" + [[ $? -eq 0 ]] && touch "${localdir}/${filename}.complete" && echo "" fi fi if [[ -f ${localdir}/${filename}.asc ]]; then - if grep -q 'BEGIN PGP SIGNATURE' ${localdir}/${filename}.asc; then + if grep -q 'BEGIN PGP SIGNATURE' "${localdir}/${filename}.asc"; then - if [[ ! -d $SRC/cache/.gpg ]]; then - mkdir -p $SRC/cache/.gpg - chmod 700 $SRC/cache/.gpg - touch $SRC/cache/.gpg/gpg.conf - chmod 600 $SRC/cache/.gpg/gpg.conf + if [[ ! -d "${SRC}"/cache/.gpg ]]; then + mkdir -p "${SRC}"/cache/.gpg + chmod 700 "${SRC}"/cache/.gpg + touch "${SRC}"/cache/.gpg/gpg.conf + chmod 600 "${SRC}"/cache/.gpg/gpg.conf fi # Verify archives with Linaro and Armbian GPG keys - if [ x"" != x$http_proxy ]; then - (gpg --homedir $SRC/cache/.gpg --no-permission-warning --list-keys 8F427EAF >> $DEST/debug/output.log 2>&1\ - || gpg --homedir $SRC/cache/.gpg --no-permission-warning \ - --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=$http_proxy \ - --recv-keys 8F427EAF >> $DEST/debug/output.log 2>&1) + if [ x"" != x"${http_proxy}" ]; then + (gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning --list-keys 8F427EAF >> "${DEST}"/debug/output.log 2>&1\ + || gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning \ + --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy="${http_proxy}" \ + --recv-keys 8F427EAF >> "${DEST}"/debug/output.log 2>&1) - (gpg --homedir $SRC/cache/.gpg --no-permission-warning --list-keys 9F0E78D5 >> $DEST/debug/output.log 2>&1\ - || gpg --homedir $SRC/cache/.gpg --no-permission-warning \ - --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=$http_proxy \ - --recv-keys 9F0E78D5 >> $DEST/debug/output.log 2>&1) + (gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning --list-keys 9F0E78D5 >> "${DEST}"/debug/output.log 2>&1\ + || gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning \ + --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy="${http_proxy}" \ + --recv-keys 9F0E78D5 >> "${DEST}"/debug/output.log 2>&1) else - (gpg --homedir $SRC/cache/.gpg --no-permission-warning --list-keys 8F427EAF >> $DEST/debug/output.log 2>&1\ - || gpg --homedir $SRC/cache/.gpg --no-permission-warning \ + (gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning --list-keys 8F427EAF >> "${DEST}"/debug/output.log 2>&1\ + || gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning \ --keyserver hkp://keyserver.ubuntu.com:80 \ - --recv-keys 8F427EAF >> $DEST/debug/output.log 2>&1) + --recv-keys 8F427EAF >> "${DEST}"/debug/output.log 2>&1) - (gpg --homedir $SRC/cache/.gpg --no-permission-warning --list-keys 9F0E78D5 >> $DEST/debug/output.log 2>&1\ - || gpg --homedir $SRC/cache/.gpg --no-permission-warning \ + (gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning --list-keys 9F0E78D5 >> "${DEST}"/debug/output.log 2>&1\ + || gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning \ --keyserver hkp://keyserver.ubuntu.com:80 \ - --recv-keys 9F0E78D5 >> $DEST/debug/output.log 2>&1) + --recv-keys 9F0E78D5 >> "${DEST}"/debug/output.log 2>&1) fi - gpg --homedir $SRC/cache/.gpg --no-permission-warning --verify \ - --trust-model always -q ${localdir}/${filename}.asc >> $DEST/debug/output.log 2>&1 + gpg --homedir "${SRC}"/cache/.gpg --no-permission-warning --verify \ + --trust-model always -q "${localdir}/${filename}.asc" >> "${DEST}"/debug/output.log 2>&1 [[ ${PIPESTATUS[0]} -eq 0 ]] && verified=true && display_alert "Verified" "PGP" "info" else - md5sum -c --status ${localdir}/${filename}.asc && verified=true && display_alert "Verified" "MD5" "info" + md5sum -c --status "${localdir}/${filename}.asc" && verified=true && display_alert "Verified" "MD5" "info" fi @@ -1191,8 +1201,8 @@ download_and_verify() if [[ "${filename:(-6)}" == "tar.xz" ]]; then display_alert "decompressing" - pv -p -b -r -c -N "[ .... ] ${filename}" $filename | xz -dc | tar xp --xattrs --no-same-owner --overwrite - [[ $? -eq 0 ]] && touch ${localdir}/$dirname/.download-complete + pv -p -b -r -c -N "[ .... ] ${filename}" "${filename}" | xz -dc | tar xp --xattrs --no-same-owner --overwrite + [[ $? -eq 0 ]] && touch "${localdir}/${dirname}/.download-complete" fi else exit_with_error "verification failed" @@ -1206,8 +1216,9 @@ download_and_verify() show_developer_warning() { - local temp_rc=$(mktemp) - cat <<-'EOF' > $temp_rc + local temp_rc + temp_rc=$(mktemp) + cat <<-'EOF' > "${temp_rc}" screen_color = (WHITE,RED,ON) EOF local warn_text="You are switching to the \Z1EXPERT MODE\Zn @@ -1222,8 +1233,8 @@ show_developer_warning() - Forum posts related to dev kernel, CSC, WIP and EOS boards should be created in the \Z2\"Community forums\"\Zn section " - DIALOGRC=$temp_rc dialog --title "Expert mode warning" --backtitle "$backtitle" --colors --defaultno --no-label "I do not agree" \ - --yes-label "I understand and agree" --yesno "$warn_text" $TTY_Y $TTY_X + DIALOGRC=$temp_rc dialog --title "Expert mode warning" --backtitle "${backtitle}" --colors --defaultno --no-label "I do not agree" \ + --yes-label "I understand and agree" --yesno "$warn_text" "${TTY_Y}" "${TTY_X}" [[ $? -ne 0 ]] && exit_with_error "Error switching to the expert mode" SHOW_WARNING=no }