Shellcheck fixes (#2034)

* compile.sh: Apply shellcheck linting

* main.sh: Apply shellcheck linting

* fel-load.sh: Apply shellcheck linting
This commit is contained in:
Manuel Rüger 2020-06-18 16:06:21 +02:00 committed by GitHub
parent dc478af1cb
commit 9fa6069f9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 58 deletions

View file

@ -15,7 +15,7 @@
SRC="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# check for whitespace in $SRC and exit for safety reasons
# 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}" || exit
@ -29,32 +29,32 @@ else
exit 255
fi
if [[ $EUID == 0 ]] || [[ "$1" == vagrant ]]; then
if [[ "${EUID}" == "0" ]] || [[ "${1}" == "vagrant" ]]; then
:
elif [[ "$1" == docker || "$1" == dockerpurge || "$1" == docker-shell ]] && grep -q `whoami` <(getent group docker); then
elif [[ "${1}" == docker || "${1}" == dockerpurge || "${1}" == docker-shell ]] && grep -q "$(whoami)" <(getent group docker); then
:
else
display_alert "This script requires root privileges, trying to use sudo" "" "wrn"
sudo "$SRC/compile.sh" "$@"
sudo "${SRC}/compile.sh" "$@"
exit $?
fi
update_src() {
cd "${SRC}" || exit
if [[ ! -f $SRC/.ignore_changes ]]; then
if [[ ! -f "${SRC}"/.ignore_changes ]]; then
echo -e "[\e[0;32m o.k. \x1B[0m] This script will try to update"
git pull
CHANGED_FILES=$(git diff --name-only)
if [[ -n $CHANGED_FILES ]]; 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"
while true; do
echo -e "Press \e[0;33m<Ctrl-C>\x1B[0m or \e[0;33mexit\x1B[0m to abort compilation, \e[0;33m<Enter>\x1B[0m to ignore and continue, \e[0;33mdiff\x1B[0m to display changes"
read -r
if [[ "$REPLY" == "diff" ]]; then
if [[ "${REPLY}" == "diff" ]]; then
git diff
elif [[ "$REPLY" == "exit" ]]; then
elif [[ "${REPLY}" == "exit" ]]; then
exit 1
elif [[ "$REPLY" == "" ]]; then
elif [[ "${REPLY}" == "" ]]; then
break
else
echo "Unknown command!"
@ -66,42 +66,45 @@ update_src() {
fi
}
TMPFILE=`mktemp` && chmod 644 $TMPFILE
echo SRC=$SRC > $TMPFILE
echo LIB_TAG=$LIB_TAG >> $TMPFILE
declare -f update_src >> $TMPFILE
echo update_src >> $TMPFILE
TMPFILE=$(mktemp)
chmod 644 "${TMPFILE}"
cat <<EOF >> "${TMPFILE}"
SRC="${SRC}"
LIB_TAG="${LIB_TAG}"
declare -f update_src
update_src
EOF
#do not update/checkout git with root privileges to messup files onwership.
#due to in docker/VM, we can't su to a normal user, so do not update/checkout git.
if [[ `systemd-detect-virt` == 'none' ]]; then
if [[ $EUID == 0 ]]; then
su `stat --format=%U $SRC/.git` -c "bash $TMPFILE"
if [[ $(systemd-detect-virt) == 'none' ]]; then
if [[ "${EUID}" == "0" ]]; then
su "$(stat --format=%U "${SRC}"/.git)" -c "bash ${TMPFILE}"
else
bash $TMPFILE
bash "${TMPFILE}"
fi
fi
rm $TMPFILE
rm "${TMPFILE}"
# Check for required packages for compiling
if [[ -z "$(which dialog)" ]]; then
if [[ -z "$(command -v dialog)" ]]; then
sudo apt-get update
sudo apt-get install -y dialog
fi
if [[ -z "$(which getfacl)" ]]; then
if [[ -z "$(command -v getfacl)" ]]; then
sudo apt-get update
sudo apt-get install -y acl
fi
# Check for Vagrant
if [[ "$1" == vagrant && -z "$(which vagrant)" ]]; then
if [[ "${1}" == vagrant && -z "$(command -v vagrant)" ]]; then
display_alert "Vagrant not installed." "Installing"
sudo apt-get update
sudo apt-get install -y vagrant virtualbox
fi
if [[ "$1" == dockerpurge && -f /etc/debian_version ]]; then
if [[ "${1}" == dockerpurge && -f /etc/debian_version ]]; then
display_alert "Purging Armbian Docker containers" "" "wrn"
docker container ls -a | grep armbian | awk '{print $1}' | xargs docker container rm &> /dev/null
docker image ls | grep armbian | awk '{print $3}' | xargs docker image rm &> /dev/null
@ -109,20 +112,21 @@ if [[ "$1" == dockerpurge && -f /etc/debian_version ]]; then
set -- "docker" "$@"
fi
if [[ "$1" == docker-shell ]]; then
if [[ "${1}" == docker-shell ]]; then
shift
#shellcheck disable=SC2034
SHELL_ONLY=yes
set -- "docker" "$@"
fi
# Install Docker if not there but wanted. We cover only Debian based distro install. Else, manual Docker install is needed
if [[ "$1" == docker && -f /etc/debian_version && -z "$(which docker)" ]]; then
if [[ "${1}" == docker && -f /etc/debian_version && -z "$(command -v docker)" ]]; then
# add exception for Ubuntu Focal until Docker provides dedicated binary
codename=$(lsb_release -sc)
codeid=$(lsb_release -is | awk '{print tolower($0)}')
[[ $codeid == linuxmint && $codename == debbie ]] && codename="buster" && codeid="debian"
[[ $codename == focal ]] && codename="bionic"
[[ "${codeid}" == "linuxmint" && "${codename}" == "debbie" ]] && codename="buster" && codeid="debian"
[[ "${codename}" == "focal" ]] && codename="bionic"
display_alert "Docker not installed." "Installing" "Info"
echo "deb [arch=amd64] https://download.docker.com/linux/${codeid} ${codename} edge" > /etc/apt/sources.list.d/docker.list
@ -131,27 +135,27 @@ if [[ "$1" == docker && -f /etc/debian_version && -z "$(which docker)" ]]; then
packages=("curl" "gnupg" "apt-transport-https")
for i in "${packages[@]}"
do
[[ ! $(which $i) ]] && install_packages+=$i" "
[[ ! $(command -v "${i}") ]] && install_packages+=${i}" "
done
[[ -z $install_packages ]] && apt-get update;apt-get install -y -qq --no-install-recommends $install_packages
[[ -z "${install_packages}" ]] && apt-get update;apt-get install -y -qq --no-install-recommends "${install_packages}"
curl -fsSL "https://download.docker.com/linux/${codeid}/gpg" | apt-key add -qq - > /dev/null 2>&1
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y -qq --no-install-recommends docker-ce
display_alert "Add yourself to docker group to avoid root privileges" "" "wrn"
"$SRC/compile.sh" "$@"
"${SRC}/compile.sh" "$@"
exit $?
fi
# Create userpatches directory if not exists
mkdir -p $SRC/userpatches
mkdir -p "${SRC}"/userpatches
# Create example configs if none found in userpatches
if ! ls ${SRC}/userpatches/{config-example.conf,config-docker.conf,config-vagrant.conf} 1> /dev/null 2>&1; then
if ! ls "${SRC}"/userpatches/{config-example.conf,config-docker.conf,config-vagrant.conf} 1> /dev/null 2>&1; then
# Migrate old configs
if ls ${SRC}/*.conf 1> /dev/null 2>&1; then
if ls "${SRC}"/*.conf 1> /dev/null 2>&1; then
display_alert "Migrate config files to userpatches directory" "all *.conf" "info"
cp "${SRC}"/*.conf "${SRC}"/userpatches || exit 1
rm "${SRC}"/*.conf
@ -188,36 +192,36 @@ if ! ls ${SRC}/userpatches/{config-example.conf,config-docker.conf,config-vagran
fi
if [[ -z "$CONFIG" && -n "$1" && -f "${SRC}/userpatches/config-$1.conf" ]]; then
if [[ -z "${CONFIG}" && -n "$1" && -f "${SRC}/userpatches/config-$1.conf" ]]; then
CONFIG="userpatches/config-$1.conf"
shift
fi
# usind default if custom not found
if [[ -z "$CONFIG" && -f "${SRC}/userpatches/config-default.conf" ]]; then
if [[ -z "${CONFIG}" && -f "${SRC}/userpatches/config-default.conf" ]]; then
CONFIG="userpatches/config-default.conf"
fi
# source build configuration file
CONFIG_FILE="$(realpath "$CONFIG")"
CONFIG_FILE="$(realpath "${CONFIG}")"
if [[ ! -f $CONFIG_FILE ]]; then
display_alert "Config file does not exist" "$CONFIG" "error"
if [[ ! -f "${CONFIG_FILE}" ]]; then
display_alert "Config file does not exist" "${CONFIG}" "error"
exit 254
fi
CONFIG_PATH=$(dirname "$CONFIG_FILE")
CONFIG_PATH=$(dirname "${CONFIG_FILE}")
display_alert "Using config file" "$CONFIG_FILE" "info"
pushd $CONFIG_PATH > /dev/null
display_alert "Using config file" "${CONFIG_FILE}" "info"
pushd "${CONFIG_PATH}" > /dev/null || exit
# shellcheck source=/dev/null
source "$CONFIG_FILE"
popd > /dev/null
source "${CONFIG_FILE}"
popd > /dev/null || exit
[[ -z "${USERPATCHES_PATH}" ]] && USERPATCHES_PATH="$CONFIG_PATH"
[[ -z "${USERPATCHES_PATH}" ]] && USERPATCHES_PATH="${CONFIG_PATH}"
# Script parameters handling
while [[ $1 == *=* ]]; do
while [[ "${1}" == *=* ]]; do
parameter=${1%%=*}
value=${1##*=}
shift
@ -225,7 +229,7 @@ while [[ $1 == *=* ]]; do
eval "$parameter=\"$value\""
done
if [[ $BUILD_ALL == yes || $BUILD_ALL == demo ]]; then
if [[ "${BUILD_ALL}" == "yes" || "${BUILD_ALL}" == "demo" ]]; then
# shellcheck source=lib/build-all-ng.sh
source "${SRC}"/lib/build-all-ng.sh
else

View file

@ -16,14 +16,14 @@
fel_prepare_host()
{
# Start rpcbind for NFS if inside docker container
[ `systemd-detect-virt` == 'docker' ] && service rpcbind start
[ "$(systemd-detect-virt)" == 'docker' ] && service rpcbind start
# remove and re-add NFS share
rm -f /etc/exports.d/armbian.exports
mkdir -p /etc/exports.d
echo "$FEL_ROOTFS *(rw,async,no_subtree_check,no_root_squash,fsid=root)" > /etc/exports.d/armbian.exports
# Start NFS server if inside docker container
[ `systemd-detect-virt` == 'docker' ] && service nfs-kernel-server start
[ "$(systemd-detect-virt)" == 'docker' ] && service nfs-kernel-server start
exportfs -ra
}
@ -70,7 +70,7 @@ fel_load()
[[ $(type -t fel_pre_load) == function ]] && fel_pre_load
display_alert "Loading files via" "FEL USB" "info"
sunxi-fel ${FEL_EXTRA_ARGS} -p uboot "${FEL_ROOTFS}/usr/lib/${CHOSEN_UBOOT}_${REVISION}_armhf/u-boot-sunxi-with-spl.bin" \
sunxi-fel "${FEL_EXTRA_ARGS}" -p uboot "${FEL_ROOTFS}/usr/lib/${CHOSEN_UBOOT}_${REVISION}_armhf/u-boot-sunxi-with-spl.bin" \
write 0x42000000 "${FEL_ROOTFS}"/boot/zImage \
write 0x43000000 "${FEL_ROOTFS}/${dtb_file}" \
write 0x43300000 "${FEL_ROOTFS}"/boot/uInitrd \

View file

@ -24,7 +24,7 @@ fi
umask 002
# destination
DEST=$SRC/output
DEST="${SRC}"/output
if [[ $BUILD_ALL != "yes" ]]; then
# override stty size
@ -113,9 +113,9 @@ if [[ -n $REPOSITORY_UPDATE ]]; then
fi
# For user override
if [[ -f $USERPATCHES_PATH/lib.config ]]; then
if [[ -f "${USERPATCHES_PATH}"/lib.config ]]; then
display_alert "Using user configuration override" "userpatches/lib.config" "info"
source "$USERPATCHES_PATH"/lib.config
source "${USERPATCHES_PATH}"/lib.config
fi
repo-manipulate "$REPOSITORY_UPDATE"
@ -373,12 +373,12 @@ else
fi
branch2dir() {
[[ $1 == head ]] && echo HEAD || echo ${1##*:}
[[ "${1}" == "head" ]] && echo "HEAD" || echo "${1##*:}"
}
BOOTSOURCEDIR=$BOOTDIR/$(branch2dir ${BOOTBRANCH})
LINUXSOURCEDIR=$KERNELDIR/$(branch2dir ${KERNELBRANCH})
[[ -n $ATFSOURCE ]] && ATFSOURCEDIR=$ATFDIR/$(branch2dir ${ATFBRANCH})
BOOTSOURCEDIR="${BOOTDIR}/$(branch2dir "${BOOTBRANCH}")"
LINUXSOURCEDIR="${KERNELDIR}/$(branch2dir "${KERNELBRANCH}")"
[[ -n $ATFSOURCE ]] && ATFSOURCEDIR="${ATFDIR}/$(branch2dir "${ATFBRANCH}")"
# define package names
DEB_BRANCH=${BRANCH//default}
@ -450,7 +450,7 @@ if [[ ! -f ${DEB_STORAGE}/armbian-config_${REVISION}_all.deb ]]; then
fi
# Compile armbian-firmware if packed .deb does not exist or use the one from repository
if ! ls ${DEB_STORAGE}/armbian-firmware_${REVISION}_all.deb 1> /dev/null 2>&1 || ! ls ${DEB_STORAGE}/armbian-firmware-full_${REVISION}_all.deb 1> /dev/null 2>&1; then
if ! ls "${DEB_STORAGE}/armbian-firmware_${REVISION}_all.deb" 1> /dev/null 2>&1 || ! ls "${DEB_STORAGE}/armbian-firmware-full_${REVISION}_all.deb" 1> /dev/null 2>&1; then
if [[ "${REPOSITORY_INSTALL}" != *armbian-firmware* ]]; then
@ -493,7 +493,7 @@ runtime=$(((end-start)/60))
display_alert "Runtime" "$runtime min" "info"
# Make it easy to repeat build by displaying build options used
[ `systemd-detect-virt` == 'docker' ] && BUILD_CONFIG='docker'
[ "$(systemd-detect-virt)" == 'docker' ] && BUILD_CONFIG='docker'
display_alert "Repeat Build Options" "./compile.sh ${BUILD_CONFIG} BOARD=${BOARD} BRANCH=${BRANCH} \
$([[ -n $RELEASE ]] && echo "RELEASE=${RELEASE} ")\
$([[ -n $BUILD_MINIMAL ]] && echo "BUILD_MINIMAL=${BUILD_MINIMAL} ")\