diff --git a/compile.sh b/compile.sh index fd9ec62d8b..19fec5f1a2 100755 --- a/compile.sh +++ b/compile.sh @@ -13,33 +13,36 @@ # use configuration files like config-default.conf to set the build configuration # check Armbian documentation for more info -SRC="$(dirname "$(realpath "${BASH_SOURCE}")")" +SRC="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" # fallback for Trusty [[ -z "${SRC}" ]] && SRC="$(pwd)" # check for whitespace in $SRC and exit for safety reasons grep -q "[[:space:]]" <<<"${SRC}" && { echo "\"${SRC}\" contains whitespace. Not supported. Aborting." >&2 ; exit 1 ; } -cd $SRC +cd "${SRC}" || exit -if [[ -f $SRC/lib/general.sh && -L $SRC/main.sh ]]; then - source $SRC/lib/general.sh +if [[ -f "${SRC}"/lib/general.sh && -L "${SRC}"/main.sh ]]; then + # shellcheck source=lib/general.sh + source "${SRC}"/lib/general.sh else echo "Error: missing build directory structure" echo "Please clone the full repository https://github.com/armbian/build/" - exit -1 + exit 255 fi # copy default config from the template -[[ ! -f $SRC/config-default.conf ]] && cp $SRC/config/templates/config-example.conf $SRC/config-default.conf +[[ ! -f "${SRC}"/config-default.conf ]] && cp "${SRC}"/config/templates/config-example.conf "${SRC}"/config-default.conf # source build configuration file -if [[ -n $1 && -f $SRC/config-$1.conf ]]; then +if [[ -n $1 && -f "${SRC}/config-$1.conf" ]]; then display_alert "Using config file" "config-$1.conf" "info" - source $SRC/config-$1.conf + # shellcheck source=/dev/null + source "${SRC}/config-$1.conf" else display_alert "Using config file" "config-default.conf" "info" - source $SRC/config-default.conf + # shellcheck source=/dev/null + source "${SRC}"/config-default.conf fi if [[ $EUID != 0 ]]; then @@ -54,7 +57,7 @@ for i in "$@"; do parameter=${i%%=*} value=${i##*=} display_alert "Command line: setting $parameter to" "${value:-(empty)}" "info" - eval $parameter=\"$value\" + eval "$parameter=\"$value\"" fi done @@ -65,14 +68,16 @@ if [[ ! -f $SRC/.ignore_changes ]]; then if [[ -n $CHANGED_FILES ]]; then echo -e "[\e[0;35m warn \x1B[0m] Can't update since you made changes to: \e[0;32m\n${CHANGED_FILES}\x1B[0m" echo -e "Press \e[0;33m\x1B[0m to abort compilation, \e[0;33m\x1B[0m to ignore and continue" - read + read -r else - git checkout ${LIB_TAG:- master} + git checkout "${LIB_TAG:-master}" fi fi if [[ $BUILD_ALL == yes || $BUILD_ALL == demo ]]; then - source $SRC/lib/build-all.sh + # shellcheck source=lib/build-all.sh + source "${SRC}"/lib/build-all.sh else - source $SRC/lib/main.sh + # shellcheck source=lib/main.sh + source "${SRC}"/lib/main.sh fi diff --git a/lib/desktop.sh b/lib/desktop.sh index 910cc39c09..f362639d68 100644 --- a/lib/desktop.sh +++ b/lib/desktop.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 @@ -13,12 +15,12 @@ create_desktop_package () PACKAGE_LIST_DESKTOP=${PACKAGE_LIST_DESKTOP// /,}; PACKAGE_LIST_DESKTOP=${PACKAGE_LIST_DESKTOP//[[:space:]]/} PACKAGE_LIST_DESKTOP_RECOMMENDS=${PACKAGE_LIST_DESKTOP_RECOMMENDS// /,}; PACKAGE_LIST_DESKTOP_RECOMMENDS=${PACKAGE_LIST_DESKTOP_RECOMMENDS//[[:space:]]/} - local destination=$SRC/.tmp/${RELEASE}/${BOARD}/${CHOSEN_DESKTOP}_${REVISION}_all - rm -rf $destination - mkdir -p $destination/DEBIAN + local destination=${SRC}/.tmp/${RELEASE}/${BOARD}/${CHOSEN_DESKTOP}_${REVISION}_all + rm -rf "${destination}" + mkdir -p "${destination}"/DEBIAN # set up control file - cat <<-EOF > $destination/DEBIAN/control + cat <<-EOF > "${destination}"/DEBIAN/control Package: ${CHOSEN_DESKTOP} Version: $REVISION Architecture: all @@ -32,7 +34,7 @@ create_desktop_package () Description: Armbian desktop for ${DISTRIBUTION} ${RELEASE} EOF - cat <<-EOF > $destination/DEBIAN/postinst + cat <<-EOF > "${destination}"/DEBIAN/postinst #!/bin/sh -e # overwrite stock chromium and firefox configuration @@ -65,67 +67,67 @@ create_desktop_package () exit 0 EOF - chmod 755 $destination/DEBIAN/postinst + chmod 755 "${destination}"/DEBIAN/postinst # add loading desktop splash service - mkdir -p $destination/etc/systemd/system/ - cp $SRC/packages/blobs/desktop/desktop-splash/desktop-splash.service $destination/etc/systemd/system/desktop-splash.service + mkdir -p "${destination}"/etc/systemd/system/ + cp "${SRC}"/packages/blobs/desktop/desktop-splash/desktop-splash.service "${destination}"/etc/systemd/system/desktop-splash.service # install optimized browser configurations - mkdir -p $destination/etc/armbian - cp $SRC/packages/blobs/desktop/chromium.conf $destination/etc/armbian - cp $SRC/packages/blobs/desktop/firefox.conf $destination/etc/armbian - cp -R $SRC/packages/blobs/desktop/chromium $destination/etc/armbian + mkdir -p "${destination}"/etc/armbian + cp "${SRC}"/packages/blobs/desktop/chromium.conf "${destination}"/etc/armbian + cp "${SRC}"/packages/blobs/desktop/firefox.conf "${destination}"/etc/armbian + cp -R "${SRC}"/packages/blobs/desktop/chromium "${destination}"/etc/armbian # install lightdm greeter - cp -R $SRC/packages/blobs/desktop/lightdm $destination/etc/armbian + cp -R "${SRC}"/packages/blobs/desktop/lightdm "${destination}"/etc/armbian # install default desktop settings - mkdir -p $destination/etc/skel - cp -R $SRC/packages/blobs/desktop/skel/. $destination/etc/skel + mkdir -p "${destination}"/etc/skel + cp -R "${SRC}"/packages/blobs/desktop/skel/. "${destination}"/etc/skel # using different icon pack. Workaround due to this bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=867779 if [[ ${RELEASE} == bionic || ${RELEASE} == stretch || ${RELEASE} == buster || ${RELEASE} == disco ]]; then sed -i 's//g' \ - $destination/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml + "${destination}"/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml fi # install dedicated startup icons - mkdir -p $destination/usr/share/pixmaps $destination/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/ - cp $SRC/packages/blobs/desktop/icons/${DISTRIBUTION,,}.png $destination/usr/share/pixmaps - sed 's/xenial.png/'${DISTRIBUTION,,}'.png/' -i $destination/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml + mkdir -p "${destination}"/usr/share/pixmaps "${destination}"/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/ + cp "${SRC}/packages/blobs/desktop/icons/${DISTRIBUTION,,}.png" "${destination}"/usr/share/pixmaps + sed 's/xenial.png/'"${DISTRIBUTION,,}"'.png/' -i "${destination}"/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml # install logo for login screen - cp $SRC/packages/blobs/desktop/icons/armbian.png $destination/usr/share/pixmaps + cp "${SRC}"/packages/blobs/desktop/icons/armbian.png "${destination}"/usr/share/pixmaps # install wallpapers - mkdir -p $destination/usr/share/backgrounds/xfce/ - cp $SRC/packages/blobs/desktop/wallpapers/armbian*.jpg $destination/usr/share/backgrounds/xfce/ + mkdir -p "${destination}"/usr/share/backgrounds/xfce/ + cp "${SRC}"/packages/blobs/desktop/wallpapers/armbian*.jpg "${destination}"/usr/share/backgrounds/xfce/ # create board DEB file display_alert "Building desktop package" "${CHOSEN_DESKTOP}_${REVISION}_all" "info" - fakeroot dpkg-deb -b $destination ${destination}.deb >/dev/null - mkdir -p ${DEST}/debs/${RELEASE} - mv ${destination}.deb $DEST/debs/${RELEASE} + fakeroot dpkg-deb -b "${destination}" "${destination}.deb" >/dev/null + mkdir -p "${DEST}/debs/${RELEASE}" + mv "${destination}.deb" "${DEST}/debs/${RELEASE}" # cleanup - rm -rf $destination + rm -rf "${destination}" } desktop_postinstall () { # stage: install display manager display_alert "Installing" "display manager: $DISPLAY_MANAGER" "info" - chroot $SDCARD /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::=\"--force-confold\" -y -qq install $PACKAGE_LIST_DISPLAY_MANAGER" >> $DEST/debug/install.log 2>&1 - [[ -f $SDCARD/etc/default/nodm ]] && sed "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=false/g" -i $SDCARD/etc/default/nodm - [[ -d $SDCARD/etc/lightdm ]] && chroot $SDCARD /bin/bash -c "systemctl --no-reload disable lightdm.service >/dev/null 2>&1" + chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::=\"--force-confold\" -y -qq install $PACKAGE_LIST_DISPLAY_MANAGER" >> "${DEST}"/debug/install.log 2>&1 + [[ -f "${SDCARD}"/etc/default/nodm ]] && sed "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=false/g" -i "${SDCARD}"/etc/default/nodm + [[ -d "${SDCARD}"/etc/lightdm ]] && chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload disable lightdm.service >/dev/null 2>&1" # Compile Turbo Frame buffer for sunxi if [[ $LINUXFAMILY == sun* && $BRANCH == default ]]; then - sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i $SDCARD/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml + sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i "${SDCARD}"/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml # enable memory reservations - echo "disp_mem_reserves=on" >> $SDCARD/boot/armbianEnv.txt - echo "extraargs=cma=96M" >> $SDCARD/boot/armbianEnv.txt + echo "disp_mem_reserves=on" >> "${SDCARD}"/boot/armbianEnv.txt + echo "extraargs=cma=96M" >> "${SDCARD}"/boot/armbianEnv.txt fi } diff --git a/lib/main.sh b/lib/main.sh index e2be88911f..2803f9c303 100644 --- a/lib/main.sh +++ b/lib/main.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 @@ -10,9 +12,9 @@ # Main program # -if [[ $(basename $0) == main.sh ]]; then +if [[ $(basename "$0") == main.sh ]]; then echo "Please use compile.sh to start the build process" - exit -1 + exit 255 fi # default umask for root is 022 so parent directories won't be group writeable without this @@ -37,22 +39,30 @@ backtitle="Armbian building script, http://www.armbian.com | Author: Igor Pecovn [[ -z $FORCE_CHECKOUT ]] && FORCE_CHECKOUT=yes # Load libraries -source $SRC/lib/debootstrap-ng.sh # System specific install -source $SRC/lib/image-helpers.sh # helpers for OS image building -source $SRC/lib/distributions.sh # System specific install -source $SRC/lib/desktop.sh # Desktop specific install -source $SRC/lib/compilation.sh # Patching and compilation of kernel, uboot, ATF -source $SRC/lib/makeboarddeb.sh # Create board support package -source $SRC/lib/general.sh # General functions -source $SRC/lib/chroot-buildpackages.sh # Building packages in chroot +# shellcheck source=debootstrap-ng.sh +source "${SRC}"/lib/debootstrap-ng.sh # System specific install +# shellcheck source=image-helpers.sh +source "${SRC}"/lib/image-helpers.sh # helpers for OS image building +# shellcheck source=distributions.sh +source "${SRC}"/lib/distributions.sh # System specific install +# shellcheck source=desktop.sh +source "${SRC}"/lib/desktop.sh # Desktop specific install +# shellcheck source=compilation.sh +source "${SRC}"/lib/compilation.sh # Patching and compilation of kernel, uboot, ATF +# shellcheck source=makeboarddeb.sh +source "${SRC}"/lib/makeboarddeb.sh # Create board support package +# shellcheck source=general.sh +source "${SRC}"/lib/general.sh # General functions +# shellcheck source=chroot-buildpackages.sh +source "${SRC}"/lib/chroot-buildpackages.sh # Building packages in chroot # compress and remove old logs -mkdir -p $DEST/debug -(cd $DEST/debug && tar -czf logs-$( /dev/null 2>&1 -rm -f $DEST/debug/*.log > /dev/null 2>&1 -date +"%d_%m_%Y-%H_%M_%S" > $DEST/debug/timestamp +mkdir -p "${DEST}"/debug +(cd "${DEST}"/debug && tar -czf logs-"$( /dev/null 2>&1 +rm -f "${DEST}"/debug/*.log > /dev/null 2>&1 +date +"%d_%m_%Y-%H_%M_%S" > "${DEST}"/debug/timestamp # delete compressed logs older than 7 days -(cd $DEST/debug && find . -name '*.tgz' -mtime +7 -delete) > /dev/null +(cd "${DEST}"/debug && find . -name '*.tgz' -mtime +7 -delete) > /dev/null if [[ $PROGRESS_DISPLAY == none ]]; then OUTPUT_VERYSILENT=yes @@ -82,7 +92,7 @@ if [[ -z $KERNEL_ONLY ]]; then options+=("yes" "U-boot and kernel packages") options+=("no" "Full OS image for flashing") KERNEL_ONLY=$(dialog --stdout --title "Choose an option" --backtitle "$backtitle" --no-tags --menu "Select what to build" \ - $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") + $TTY_Y $TTY_X $((TTY_Y - 8)) "${options[@]}") unset options [[ -z $KERNEL_ONLY ]] && exit_with_error "No option selected" @@ -92,7 +102,7 @@ if [[ -z $KERNEL_CONFIGURE ]]; then options+=("no" "Do not change the kernel configuration") options+=("yes" "Show a kernel configuration menu before compilation") KERNEL_CONFIGURE=$(dialog --stdout --title "Choose an option" --backtitle "$backtitle" --no-tags --menu "Select the kernel configuration" \ - $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") + $TTY_Y $TTY_X $((TTY_Y - 8)) "${options[@]}") unset options [[ -z $KERNEL_CONFIGURE ]] && exit_with_error "No option selected" @@ -106,25 +116,25 @@ if [[ -z $BOARD ]]; then while true; do options=() if [[ $WIP_STATE == supported ]]; then - for board in $SRC/config/boards/*.conf; do - options+=("$(basename $board | cut -d'.' -f1)" "$(head -1 $board | cut -d'#' -f2)") + for board in "${SRC}"/config/boards/*.conf; do + options+=("$(basename "${board}" | cut -d'.' -f1)" "$(head -1 "${board}" | cut -d'#' -f2)") done else - for board in $SRC/config/boards/*.wip; do - options+=("$(basename $board | cut -d'.' -f1)" "\Z1(WIP)\Zn $(head -1 $board | cut -d'#' -f2)") + for board in "${SRC}"/config/boards/*.wip; do + options+=("$(basename "${board}" | cut -d'.' -f1)" "\Z1(WIP)\Zn $(head -1 "${board}" | cut -d'#' -f2)") done - for board in $SRC/config/boards/*.csc; do - options+=("$(basename $board | cut -d'.' -f1)" "\Z1(CSC)\Zn $(head -1 $board | cut -d'#' -f2)") + for board in "${SRC}"/config/boards/*.csc; do + options+=("$(basename "${board}" | cut -d'.' -f1)" "\Z1(CSC)\Zn $(head -1 "${board}" | cut -d'#' -f2)") done - for board in $SRC/config/boards/*.eos; do - options+=("$(basename $board | cut -d'.' -f1)" "\Z1(EOS)\Zn $(head -1 $board | cut -d'#' -f2)") + for board in "${SRC}"/config/boards/*.eos; do + options+=("$(basename "${board}" | cut -d'.' -f1)" "\Z1(EOS)\Zn $(head -1 "${board}" | cut -d'#' -f2)") done - for board in $SRC/config/boards/*.tvb; do - options+=("$(basename $board | cut -d'.' -f1)" "\Z1(TVB)\Zn $(head -1 $board | cut -d'#' -f2)") + for board in "${SRC}"/config/boards/*.tvb; do + options+=("$(basename "${board}" | cut -d'.' -f1)" "\Z1(TVB)\Zn $(head -1 "${board}" | cut -d'#' -f2)") done fi if [[ $WIP_STATE != supported ]]; then - cat <<-'EOF' > $temp_rc + cat <<-'EOF' > "${temp_rc}" dialog_color = (RED,WHITE,OFF) screen_color = (WHITE,RED,ON) tag_color = (RED,WHITE,ON) @@ -133,11 +143,11 @@ if [[ -z $BOARD ]]; then tag_key_selected_color = (WHITE,RED,ON) EOF else - echo > $temp_rc + echo > "${temp_rc}" fi BOARD=$(DIALOGRC=$temp_rc dialog --stdout --title "Choose a board" --backtitle "$backtitle" --scrollbar --colors \ --extra-label "Show $WIP_BUTTON" --extra-button --menu "Select the target board. Displaying:\n$STATE_DESCRIPTION" \ - $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") + $TTY_Y $TTY_X $((TTY_Y - 8)) "${options[@]}") STATUS=$? if [[ $STATUS == 3 ]]; then if [[ $WIP_STATE == supported ]]; then @@ -173,7 +183,8 @@ elif [[ -f $SRC/config/boards/${BOARD}.tvb ]]; then BOARD_TYPE='tvb' fi -source $SRC/config/boards/${BOARD}.${BOARD_TYPE} +# shellcheck source=/dev/null +source "${SRC}/config/boards/${BOARD}.${BOARD_TYPE}" LINUXFAMILY="${BOARDFAMILY}" [[ -z $KERNEL_TARGET ]] && exit_with_error "Board configuration does not define valid kernel config" @@ -189,7 +200,7 @@ if [[ -z $BRANCH ]]; then else BRANCH=$(dialog --stdout --title "Choose a kernel" --backtitle "$backtitle" --colors \ --menu "Select the target kernel branch\nExact kernel versions depend on selected board" \ - $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") + $TTY_Y $TTY_X $((TTY_Y - 8)) "${options[@]}") fi unset options [[ -z $BRANCH ]] && exit_with_error "No kernel branch selected" @@ -208,7 +219,7 @@ if [[ $KERNEL_ONLY != yes && -z $RELEASE ]]; then [[ $EXPERT = yes ]] && options+=("disco" "Ubuntu Disco 19.04 / unsupported") RELEASE=$(dialog --stdout --title "Choose a release" --backtitle "$backtitle" --menu "Select the target OS release" \ - $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") + $TTY_Y $TTY_X $((TTY_Y - 8)) "${options[@]}") unset options [[ -z $RELEASE ]] && exit_with_error "No release selected" fi @@ -218,22 +229,23 @@ if [[ $KERNEL_ONLY != yes && -z $BUILD_DESKTOP ]]; then options+=("no" "Image with console interface (server)") options+=("yes" "Image with desktop environment") BUILD_DESKTOP=$(dialog --stdout --title "Choose image type" --backtitle "$backtitle" --no-tags --menu "Select the target image type" \ - $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") + $TTY_Y $TTY_X $((TTY_Y - 8)) "${options[@]}") unset options [[ -z $BUILD_DESKTOP ]] && exit_with_error "No option selected" fi -source $SRC/lib/configuration.sh +#shellcheck source=configuration.sh +source "${SRC}"/lib/configuration.sh # optimize build time with 100% CPU usage CPUS=$(grep -c 'processor' /proc/cpuinfo) if [[ $USEALLCORES != no ]]; then - CTHREADS="-j$(($CPUS + $CPUS/2))" + CTHREADS="-j$((CPUS + CPUS/2))" else CTHREADS="-j1" fi -start=`date +%s` +start=$(date +%s) [[ $CLEAN_LEVEL == *sources* ]] && cleaning "sources" @@ -286,7 +298,7 @@ for option in $(tr ',' ' ' <<< "$CLEAN_LEVEL"); do done # Compile u-boot if packed .deb does not exist -if [[ ! -f $DEST/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then +if [[ ! -f ${DEST}/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then if [[ -n $ATFSOURCE ]]; then compile_atf fi @@ -294,17 +306,17 @@ if [[ ! -f $DEST/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then fi # Compile kernel if packed .deb does not exist -if [[ ! -f $DEST/debs/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]]; then +if [[ ! -f ${DEST}/debs/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]]; then compile_kernel fi overlayfs_wrapper "cleanup" # extract kernel version from .deb package -VER=$(dpkg --info $DEST/debs/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb | grep Descr | awk '{print $(NF)}') +VER=$(dpkg --info "${DEST}/debs/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}') VER="${VER/-$LINUXFAMILY/}" -UBOOT_VER=$(dpkg --info $DEST/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb | grep Descr | awk '{print $(NF)}') +UBOOT_VER=$(dpkg --info "${DEST}/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}') # create board support package [[ -n $RELEASE && ! -f $DEST/debs/$RELEASE/${CHOSEN_ROOTFS}_${REVISION}_${ARCH}.deb ]] && create_board_package @@ -327,7 +339,7 @@ fi # NOTE: this will run only if there were no errors during build process [[ $(type -t run_after_build) == function ]] && run_after_build || true -end=`date +%s` +end=$(date +%s) runtime=$(((end-start)/60)) display_alert "Runtime" "$runtime min" "info" # Make it easy to repeat build by displaying build options used diff --git a/lib/makeboarddeb.sh b/lib/makeboarddeb.sh index 5b119ca819..d067e21dba 100644 --- a/lib/makeboarddeb.sh +++ b/lib/makeboarddeb.sh @@ -1,3 +1,4 @@ +#!/bin/bash # Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com # # This file is licensed under the terms of the GNU General Public @@ -17,31 +18,31 @@ create_board_package() display_alert "Creating board support package" "$BOARD $BRANCH" "info" local destination=$SRC/.tmp/${RELEASE}/${CHOSEN_ROOTFS}_${REVISION}_${ARCH} - rm -rf $destination - mkdir -p $destination/DEBIAN + rm -rf "${destination}" + mkdir -p "${destination}"/DEBIAN # install copy of boot script & environment file local bootscript_src=${BOOTSCRIPT%%:*} local bootscript_dst=${BOOTSCRIPT##*:} - mkdir -p $destination/usr/share/armbian/ - cp $SRC/config/bootscripts/$bootscript_src $destination/usr/share/armbian/$bootscript_dst + mkdir -p "${destination}"/usr/share/armbian/ + cp "${SRC}/config/bootscripts/${bootscript_src}" "${destination}/usr/share/armbian/${bootscript_dst}" [[ -n $BOOTENV_FILE && -f $SRC/config/bootenv/$BOOTENV_FILE ]] && \ - cp $SRC/config/bootenv/$BOOTENV_FILE $destination/usr/share/armbian/armbianEnv.txt + cp "${SRC}/config/bootenv/${BOOTENV_FILE}" "${destination}"/usr/share/armbian/armbianEnv.txt # add configuration for setting uboot environment from userspace with: fw_setenv fw_printenv if [[ -n $UBOOT_FW_ENV ]]; then UBOOT_FW_ENV=($(tr ',' ' ' <<< "$UBOOT_FW_ENV")) - mkdir -p $destination/etc - echo "# Device to access offset env size" > $destination/etc/fw_env.config - echo "/dev/mmcblk0 ${UBOOT_FW_ENV[0]} ${UBOOT_FW_ENV[1]}" >> $destination/etc/fw_env.config + mkdir -p "${destination}"/etc + echo "# Device to access offset env size" > "${destination}"/etc/fw_env.config + echo "/dev/mmcblk0 ${UBOOT_FW_ENV[0]} ${UBOOT_FW_ENV[1]}" >> "${destination}"/etc/fw_env.config fi # Replaces: base-files is needed to replace /etc/update-motd.d/ files on Xenial # Replaces: unattended-upgrades may be needed to replace /etc/apt/apt.conf.d/50unattended-upgrades # (distributions provide good defaults, so this is not needed currently) # Depends: linux-base is needed for "linux-version" command in initrd cleanup script - cat <<-EOF > $destination/DEBIAN/control + cat <<-EOF > "${destination}"/DEBIAN/control Package: linux-${RELEASE}-root-${DEB_BRANCH}${BOARD} Version: $REVISION Architecture: $ARCH @@ -59,7 +60,7 @@ create_board_package() EOF # set up pre install script - cat <<-EOF > $destination/DEBIAN/preinst + cat <<-EOF > "${destination}"/DEBIAN/preinst #!/bin/sh [ "\$1" = "upgrade" ] && touch /var/run/.reboot_required [ -d "/boot/bin.old" ] && rm -rf /boot/bin.old @@ -137,7 +138,7 @@ create_board_package() EOF if [[ $FORCE_BOOTSCRIPT_UPDATE == yes ]]; then - cat <<-EOF >> $destination/DEBIAN/preinst + cat <<-EOF >> "${destination}"/DEBIAN/preinst # create a bootscript backup if [ -f /etc/armbian-release ]; then @@ -150,16 +151,16 @@ create_board_package() exit 0 EOF else - cat <<-EOF >> $destination/DEBIAN/preinst + cat <<-EOF >> "${destination}"/DEBIAN/preinst exit 0 EOF fi - chmod 755 $destination/DEBIAN/preinst + chmod 755 "${destination}"/DEBIAN/preinst # postrm script - cat <<-EOF > $destination/DEBIAN/postrm + cat <<-EOF > "${destination}"/DEBIAN/postrm #!/bin/sh if [ remove = "\$1" ] || [ abort-install = "\$1" ]; then dpkg-divert --package linux-${RELEASE}-root-${DEB_BRANCH}${BOARD} --remove --rename \ @@ -169,10 +170,10 @@ create_board_package() exit 0 EOF - chmod 755 $destination/DEBIAN/postrm + chmod 755 "${destination}"/DEBIAN/postrm # set up post install script - cat <<-EOF > $destination/DEBIAN/postinst + cat <<-EOF > "${destination}"/DEBIAN/postinst #!/bin/sh # # ${BOARD} BSP post installation script @@ -206,7 +207,7 @@ create_board_package() [ -f /boot/boot.cmd ] && mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1 EOF if [[ $FORCE_BOOTSCRIPT_UPDATE == yes ]]; then - cat <<-EOF >> $destination/DEBIAN/postinst + cat <<-EOF >> "${destination}"/DEBIAN/postinst else echo "Updating bootscript" @@ -219,7 +220,7 @@ create_board_package() EOF fi - cat <<-EOF >> $destination/DEBIAN/postinst + cat <<-EOF >> "${destination}"/DEBIAN/postinst fi # now cleanup and remove old ramlog service systemctl disable log2ram.service >/dev/null 2>&1 @@ -252,24 +253,24 @@ create_board_package() exit 0 EOF - chmod 755 $destination/DEBIAN/postinst + chmod 755 "${destination}"/DEBIAN/postinst # won't recreate files if they were removed by user # TODO: Add proper handling for updated conffiles - #cat <<-EOF > $destination/DEBIAN/conffiles + #cat <<-EOF > "${destination}"/DEBIAN/conffiles #EOF # copy common files from a premade directory structure - rsync -a $SRC/packages/bsp/common/* $destination/ + rsync -a "${SRC}"/packages/bsp/common/* "${destination}"/ # trigger uInitrd creation after installation, to apply # /etc/initramfs/post-update.d/99-uboot - cat <<-EOF > $destination/DEBIAN/triggers + cat <<-EOF > "${destination}"/DEBIAN/triggers activate update-initramfs EOF # configure MIN / MAX speed for cpufrequtils - cat <<-EOF > $destination/etc/default/cpufrequtils + cat <<-EOF > "${destination}"/etc/default/cpufrequtils # WARNING: this file will be replaced on board support package (linux-root-...) upgrade ENABLE=true MIN_SPEED=$CPUMIN @@ -278,7 +279,7 @@ create_board_package() EOF # armhwinfo, firstrun, armbianmonitor, etc. config file - cat <<-EOF > $destination/etc/armbian-release + cat <<-EOF > "${destination}"/etc/armbian-release # PLEASE DO NOT EDIT THIS FILE BOARD=$BOARD BOARD_NAME="$BOARD_NAME" @@ -294,62 +295,62 @@ create_board_package() EOF # this is required for NFS boot to prevent deconfiguring the network on shutdown - [[ $RELEASE == xenial || $RELEASE == stretch || $RELEASE == bionic || $RELEASE == buster || $RELEASE == disco ]] && sed -i 's/#no-auto-down/no-auto-down/g' $destination/etc/network/interfaces.default + [[ $RELEASE == xenial || $RELEASE == stretch || $RELEASE == bionic || $RELEASE == buster || $RELEASE == disco ]] && sed -i 's/#no-auto-down/no-auto-down/g' "${destination}"/etc/network/interfaces.default if [[ ( $LINUXFAMILY == sun*i || $LINUXFAMILY == pine64 ) && $BRANCH == default ]]; then # add mpv config for vdpau_sunxi - mkdir -p $destination/etc/mpv/ - cp $SRC/packages/bsp/mpv/mpv_sunxi.conf $destination/etc/mpv/mpv.conf - echo "export VDPAU_OSD=1" > $destination/etc/profile.d/90-vdpau.sh - chmod 755 $destination/etc/profile.d/90-vdpau.sh + mkdir -p "${destination}"/etc/mpv/ + cp "${SRC}"/packages/bsp/mpv/mpv_sunxi.conf "${destination}"/etc/mpv/mpv.conf + echo "export VDPAU_OSD=1" > "${destination}"/etc/profile.d/90-vdpau.sh + chmod 755 "${destination}"/etc/profile.d/90-vdpau.sh fi if [[ $LINUXFAMILY == sunxi* && $BRANCH != default ]]; then # add mpv config for x11 output - slow, but it works compared to no config at all # TODO: Test which output driver is better with DRM - mkdir -p $destination/etc/mpv/ - cp $SRC/packages/bsp/mpv/mpv_mainline.conf $destination/etc/mpv/mpv.conf + mkdir -p "${destination}"/etc/mpv/ + cp "${SRC}"/packages/bsp/mpv/mpv_mainline.conf "${destination}"/etc/mpv/mpv.conf fi case $RELEASE in jessie) - mkdir -p $destination/etc/NetworkManager/dispatcher.d/ - install -m 755 $SRC/packages/bsp/99disable-power-management $destination/etc/NetworkManager/dispatcher.d/ + mkdir -p "${destination}"/etc/NetworkManager/dispatcher.d/ + install -m 755 "${SRC}"/packages/bsp/99disable-power-management "${destination}"/etc/NetworkManager/dispatcher.d/ ;; xenial) - mkdir -p $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/zz-override-wifi-powersave-off.conf $destination/usr/lib/NetworkManager/conf.d/ + mkdir -p "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/zz-override-wifi-powersave-off.conf "${destination}"/usr/lib/NetworkManager/conf.d/ if [[ $BRANCH == default ]]; then # this is required only for old kernels # not needed for Stretch since there will be no Stretch images with kernels < 4.4 - mkdir -p $destination/lib/systemd/system/haveged.service.d/ - cp $SRC/packages/bsp/10-no-new-privileges.conf $destination/lib/systemd/system/haveged.service.d/ + mkdir -p "${destination}"/lib/systemd/system/haveged.service.d/ + cp "${SRC}"/packages/bsp/10-no-new-privileges.conf "${destination}"/lib/systemd/system/haveged.service.d/ fi ;; stretch) - mkdir -p $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/zz-override-wifi-powersave-off.conf $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/10-override-random-mac.conf $destination/usr/lib/NetworkManager/conf.d/ + mkdir -p "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/zz-override-wifi-powersave-off.conf "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/10-override-random-mac.conf "${destination}"/usr/lib/NetworkManager/conf.d/ ;; bionic) - mkdir -p $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/zz-override-wifi-powersave-off.conf $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/10-override-random-mac.conf $destination/usr/lib/NetworkManager/conf.d/ + mkdir -p "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/zz-override-wifi-powersave-off.conf "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/10-override-random-mac.conf "${destination}"/usr/lib/NetworkManager/conf.d/ ;; buster) - mkdir -p $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/zz-override-wifi-powersave-off.conf $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/10-override-random-mac.conf $destination/usr/lib/NetworkManager/conf.d/ + mkdir -p "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/zz-override-wifi-powersave-off.conf "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/10-override-random-mac.conf "${destination}"/usr/lib/NetworkManager/conf.d/ ;; disco) - mkdir -p $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/zz-override-wifi-powersave-off.conf $destination/usr/lib/NetworkManager/conf.d/ - cp $SRC/packages/bsp/10-override-random-mac.conf $destination/usr/lib/NetworkManager/conf.d/ + mkdir -p "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/zz-override-wifi-powersave-off.conf "${destination}"/usr/lib/NetworkManager/conf.d/ + cp "${SRC}"/packages/bsp/10-override-random-mac.conf "${destination}"/usr/lib/NetworkManager/conf.d/ ;; esac @@ -358,17 +359,17 @@ create_board_package() [[ $(type -t family_tweaks_bsp) == function ]] && family_tweaks_bsp # add some summary to the image - fingerprint_image "$destination/etc/armbian.txt" + fingerprint_image "${destination}/etc/armbian.txt" # fixing permissions (basic), reference: dh_fixperms - find $destination -print0 2>/dev/null | xargs -0r chown --no-dereference 0:0 - find $destination ! -type l -print0 2>/dev/null | xargs -0r chmod 'go=rX,u+rw,a-s' + find "${destination}" -print0 2>/dev/null | xargs -0r chown --no-dereference 0:0 + find "${destination}" ! -type l -print0 2>/dev/null | xargs -0r chmod 'go=rX,u+rw,a-s' # create board DEB file display_alert "Building package" "$CHOSEN_ROOTFS" "info" - fakeroot dpkg-deb -b $destination ${destination}.deb >> $DEST/debug/install.log 2>&1 - mkdir -p $DEST/debs/$RELEASE/ - mv ${destination}.deb $DEST/debs/$RELEASE/ + fakeroot dpkg-deb -b "${destination}" "${destination}.deb" >> "${DEST}"/debug/install.log 2>&1 + mkdir -p "${DEST}/debs/${RELEASE}/" + mv "${destination}.deb" "${DEST}/debs/${RELEASE}/" # cleanup - rm -rf $destination + rm -rf "${destination}" } diff --git a/lib/upgrade.sh b/lib/upgrade.sh index 61dcc31707..a5f5d2aea6 100644 --- a/lib/upgrade.sh +++ b/lib/upgrade.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright (c) 2015-2017 Igor Pecovnik, igor.pecovnik@gma**.com # Copyright (c) 2015-2017 other Armbian contributors (https://github.com/armbian/build/graphs/contributors) # @@ -13,12 +15,12 @@ TTY_X=$(($(stty size | awk '{print $2}')-6)) # determine terminal width TTY_Y=$(($(stty size | awk '{print $1}')-6)) # determine terminal height -if [[ $(basename $0) == main.sh ]]; then +if [[ $(basename "$0") == main.sh ]]; then echo "Please use compile.sh to start the build process" - exit -1 + exit 255 fi -if [[ $(basename $0) == compile.sh ]]; then +if [[ $(basename "$0") == compile.sh ]]; then # assuming dialog was installed already since this is supposed to be shown only on upgrade from previous versions dialog --title "Directory structure change notice" --colors --msgbox "Build script directory structure was changed to simplify the build environment setup, \ simplify upgrading in the future and improve compatibility with containers like Docker and Vagrant @@ -28,5 +30,5 @@ if [[ $(basename $0) == compile.sh ]]; then Default build configuration is defined in \Z1config-default.conf\Zn (created on first build script run) Sorry for the inconvenience" $TTY_Y $TTY_X - exit -1 + exit 255 fi