Armbian/build脚本分析
1. 脚本目录检测和代码健壮性保证 1.1 程序报错退出脚本 #set -o pipefail # trace ERR through pipes - will be enabled "soon" #set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled set -e set -o errtrace # trace ERR through - enabled set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled # Important, go read http://mywiki.wooledge.org/BashFAQ/105 NOW! 1.2. ./compile.sh脚本目录检测 SRC="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" cd "${SRC}" || exit # check for whitespace in ${SRC} and exit for safety reasons grep -q "[[:space:]]" <<< "${SRC}" && { echo "\"${SRC}\" contains whitespace. Not supported. Aborting." >&2 exit 1 } 2. single.sh 文件加载(位于./lib) 2.1 检查bash版本是否高于5.x # The Armbian functions require Bash 5.x. if [[ "${BASH_VERSINFO:-0}" -lt 5 ]]; then echo "Armbian build scripts require Bash 5.x. Go get it..." >&2 if [[ "${OSTYPE}" == "darwin"* ]]; then echo "Armbian build scripts require brew to be installed and working on macOS. (old Bash version)" >&2 echo "Please install brew, *restart your terminal*." >&2 echo "Then run 'brew install bash coreutils git', *restart your terminal* and then try again." >&2 exit 51 fi exit 50 fi 2.2 macOS系统检查 是否以root运行脚本 Homebrew 包管理器已安装并正常工作 通过 Homebrew 的 coreutils 安装的 realpath 命令是否可用 更新 PATH 环境变量以包含由 Homebrew 安装的 GNU coreutils 二进制文件。 确保 ${SRC} 变量(应指向构建脚本的源目录)位于用户的主目录中。这对于 macOS 上的 Docker 兼容性很重要。 ...