From 9f1bc6a67df9abb32cfd8877fbe7da550320c474 Mon Sep 17 00:00:00 2001 From: Julian Labus Date: Mon, 19 Jul 2021 14:47:54 +0200 Subject: [PATCH] build: move scripts to contrib --- autobuild.sh | 145 ----------------------------------- build.sh => contrib/build.sh | 126 +++++++++++++++--------------- sign.sh => contrib/sign.sh | 6 +- 3 files changed, 68 insertions(+), 209 deletions(-) delete mode 100755 autobuild.sh rename build.sh => contrib/build.sh (75%) rename sign.sh => contrib/sign.sh (94%) diff --git a/autobuild.sh b/autobuild.sh deleted file mode 100755 index c16c8db..0000000 --- a/autobuild.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/bin/bash -# ===================================================================== -# Wrapper script for build.sh script -# ===================================================================== - -# Exit on failed commands -set -e -o pipefail - -# Get full path to script directory -SCRIPTPATH="$(dirname "$(readlink -e "$0")" )" - -# Gluon directory -GLUON_DIR="${SCRIPTPATH}/gluon" - -DATE=$(date +%Y%m%d) - -# Overwrite Git Tag for experimental releases -GLUON_EXP_TAG="2021.2" - -# Error codes -E_ILLEGAL_ARGS=126 -E_ILLEGAL_TAG=127 -E_DIR_NOT_EMPTY=128 - -LOGFILE="${SCRIPTPATH}/build.log" -LOG_CMD="tee -a ${LOGFILE}" - -CLEAN=0 - -mkdir -p "$(dirname ${LOGFILE})" - -log() { - echo "${1}" | ${LOG_CMD} -} - -# Help function used in error messages and -h option -usage() { - echo "" - echo "Autobuild script for Freifunk MWU Gluon firmware." - echo "Use the seperater -- to pass options directly to build.sh" - echo "" - echo "-b: Firmware branch name: stable | testing | experimental" - echo "-c: Run clean (-cc for dirclean)" - echo "-d: Enable bash debug output" - echo "-g: Get remote sources before build" - echo "-h: Show this help" - echo "-r: Release suffix number (default: 1)" - echo "-u: Update Gluon to latest origin/master (optional)" - echo " Default: \"${SITES}\"" - echo "" -} - -# Evaluate arguments for build script. -while getopts b:cdghr:s:u flag; do - case ${flag} in - d) - set -x - DEBUG="-d" - ;; - h) - usage - exit - ;; - b) - if [[ " stable testing experimental " =~ " ${OPTARG} " ]] ; then - BRANCH="${OPTARG}" - else - echo "Error: Invalid branch set." - usage - exit ${E_ILLEGAL_ARGS} - fi - ;; - c) - CLEAN=$((CLEAN+1)) - ;; - g) - DOWNLOAD="true" - ;; - r) - SUFFIX="${OPTARG}" - ;; - u) - UPDATE="true" - ;; - esac -done - -# Strip of used arguments -shift $((OPTIND - 1)); - -# Set release number if not set -if [[ -z "${SUFFIX}" ]]; then - SUFFIX="1" -fi - -echo "--- Start: $(date +"%Y-%m-%d %H:%M:%S%:z") ---" | tee ${LOGFILE} - -# Generate suffix and checkout latest gluon master -if [[ "${BRANCH}" == "experimental" && "${UPDATE}" == "true" ]]; then - log "--- Init & Checkout Latest Gluon Master ---" - git submodule init 2>&1 | ${LOG_CMD} - git submodule update --remote --init --force 2>&1 | ${LOG_CMD} -fi - -if [[ "${BRANCH}" == "experimental" ]]; then - GLUON_TAG="${GLUON_EXP_TAG}" - SUFFIX="~exp${DATE}$(printf %02d ${SUFFIX})" -else - if ! GLUON_TAG=$(git --git-dir="${GLUON_DIR}/.git" describe --tags --exact-match) ; then - log 'Error: The gluon tree is not checked out at a tag.' - log 'Please use `git checkout ` to use an official gluon release' - log 'or build it as experimental.' - exit ${E_ILLEGAL_TAG} - fi - GLUON_TAG="${GLUON_TAG#v}" -fi - -# Set release name -RELEASE="${GLUON_TAG}+mwu${SUFFIX}" - -# Build the firmware, sign and deploy -log "--- Building Firmware / ${RELEASE} (${BRANCH}) ---" - -log "--- Building Firmware / update ---" -${SCRIPTPATH}/build.sh -r ${RELEASE} -b ${BRANCH} ${DEBUG} "${@}" -c update 2>&1 | ${LOG_CMD} - -if [[ ${CLEAN} -eq 1 ]] ; then - log "--- Building Firmware / clean ---" - ${SCRIPTPATH}/build.sh -r ${RELEASE} -b ${BRANCH} ${DEBUG} "${@}" -c clean 2>&1 | ${LOG_CMD} -elif [[ ${CLEAN} -gt 1 ]] ; then - log "--- Building Firmware / dirclean ---" - ${SCRIPTPATH}/build.sh -r ${RELEASE} -b ${BRANCH} ${DEBUG} "${@}" -c dirclean 2>&1 | ${LOG_CMD} -fi - -if [[ "${DOWNLOAD}" == "true" ]]; then - log "--- Building Firmware / download ---" - ${SCRIPTPATH}/build.sh -r ${RELEASE} -b ${BRANCH} ${DEBUG} "${@}" -c download 2>&1 | ${LOG_CMD} -fi - -for COMMAND in build sign deploy ; do - log "--- Building Firmware / ${COMMAND} ---" - ${SCRIPTPATH}/build.sh -r ${RELEASE} -b ${BRANCH} ${DEBUG} "${@}" -c ${COMMAND} 2>&1 | ${LOG_CMD} -done - -log "--- End: $(date +"%Y-%m-%d %H:%M:%S%:z") ---" diff --git a/build.sh b/contrib/build.sh similarity index 75% rename from build.sh rename to contrib/build.sh index 4816d30..9bda649 100755 --- a/build.sh +++ b/contrib/build.sh @@ -10,22 +10,17 @@ # Exit on failed commands set -e -o pipefail -# Get full path to script directory -SCRIPTPATH="$(dirname "$(readlink -e "$0")" )" - # Default make options CORES=$(nproc) MAKEOPTS="-j$((CORES+1)) BUILD_LOG=1 V=s" -# Default to build all Gluon targets if parameter -t is not set - -# Gluon directory -GLUON_DIR="gluon" +# Overwrite Git Tag for experimental releases +EXP_TAG="2021.2" -# Gluon output base directory -OUTPUT_DIR="output" +# Release suffix for experimental releases +SUFFIX=1 -# LEDE cache directory +# OpenWrt cache directory CACHE_DIR="${HOME}/.cache/openwrt" # Deployment directory @@ -37,8 +32,8 @@ SIGN_KEY="${HOME}/.ecdsakey" # Build targets marked broken BROKEN=0 -# Error codes -E_ILLEGAL_ARGS=126 +LOGFILE="build.log" +LOG_CMD="tee ${LOGFILE}" # Help function used in error messages and -h option usage() { @@ -47,20 +42,23 @@ usage() { echo "" echo "-a: Build targets marked as broken (optional)" echo " Applied: ${BROKEN}" - echo "-b: Firmware branch name (required: sign deploy)" + echo "-b: Firmware branch name (required sign deploy)" echo " Availible: stable testing experimental" echo "-c: Build command (required)" - echo " Availible: build clean deploy dirclean" + echo " Available: build clean deploy dirclean" echo " download link sign update" + echo " auto autoc autocc" echo "-d: Enable bash debug output (optional)" echo "-h: Show this help" - echo "-i: Build identifier (optional)" echo " Will be applied to the deployment directory" echo "-m: Setting for make options (optional)" echo " Applied: \"${MAKEOPTS}\"" echo "-p: Priority used for autoupdater (optional)" echo " Default: see site.mk" - echo "-r: Release version (required: build sign deploy)" + echo "-r: Release version (optional)" + echo " Default: Git tag" + echo "-s: Release suffix (optional: only experimental)" + echo " Default: 1" echo "-t: Gluon target architectures to build (optional)" echo " Default: all" } @@ -68,11 +66,11 @@ usage() { # Evaluate arguments for build script. if [[ "${#}" == 0 ]]; then usage - exit ${E_ILLEGAL_ARGS} + exit 1 fi # Evaluate arguments for build script. -while getopts ab:c:dhm:p:i:t:r:s: flag; do +while getopts ab:c:dhm:p:r:s:t: flag; do case ${flag} in d) set -x @@ -87,7 +85,7 @@ while getopts ab:c:dhm:p:i:t:r:s: flag; do else echo "Error: Invalid branch set." usage - exit ${E_ILLEGAL_ARGS} + exit 1 fi ;; c) @@ -100,13 +98,16 @@ while getopts ab:c:dhm:p:i:t:r:s: flag; do deploy| \ clean| \ dirclean| \ - targets) + targets| \ + auto| \ + autoc| \ + autocc) COMMAND="${OPTARG}" ;; *) echo "Error: Invalid build command set." usage - exit ${E_ILLEGAL_ARGS} + exit 1 ;; esac ;; @@ -130,12 +131,16 @@ while getopts ab:c:dhm:p:i:t:r:s: flag; do r) RELEASE="${OPTARG}" ;; + + r) + SUFFIX="${OPTARG}" + ;; a) BROKEN=1 ;; *) usage - exit ${E_ILLEGAL_ARGS} + exit 1 ;; esac done @@ -147,7 +152,7 @@ shift $((OPTIND - 1)); if [[ "${#}" > 0 ]]; then echo "Error: To many arguments: ${*}" usage - exit ${E_ILLEGAL_ARGS} + exit 1 fi # Set priority @@ -164,21 +169,14 @@ fi if [[ -z "${COMMAND}" ]]; then echo "Error: Build command missing." usage - exit ${E_ILLEGAL_ARGS} -fi - -# Check if $RELEASE is set for commands that need it -if [[ -z "${RELEASE}" && " update clean dirclean build sign deploy " =~ " ${COMMAND} " ]]; then - echo "Error: Release suffix missing." - usage - exit ${E_ILLEGAL_ARGS} + exit 1 fi # Check if $BRANCH is set for commands that need it -if [[ -z "${BRANCH}" && " sign deploy " =~ " ${COMMAND} " ]]; then +if [[ -z "${BRANCH}" && " sign deploy auto autoc autocc " =~ " ${COMMAND} " ]]; then echo "Error: Branch missing." usage - exit ${E_ILLEGAL_ARGS} + exit 1 fi # Set branch used for building (autoupdater!) @@ -188,6 +186,19 @@ else BUILDBRANCH="stable" fi +# Set release name +if [[ -z "${RELEASE}" ]]; then + if [[ "${BRANCH}" == "experimental" ]]; then + RELEASE="${EXP_TAG}+mwu~exp$(date +%Y%m%d)$(printf %02d ${SUFFIX})" + else + if ! RELEASE="$(git -C site describe --tags --exact-match)" ; then + echo 'Error: site is not checked out at a tag.' + echo 'Use `git checkout ` or build as experimental.' + exit 1 + fi + fi +fi + update() { echo "--- Updating dependencies ---" make ${MAKEOPTS} \ @@ -196,14 +207,7 @@ update() { } link() { - echo "--- Linking directories ---" - - rm -rf "output" || true - mkdir -p "${SCRIPTPATH}/${OUTPUT_DIR}/${SITE}" - ln --relative --symbolic "${SCRIPTPATH}/${OUTPUT_DIR}" "output" - - rm -rf "site" || true - ln --relative --symbolic "${SCRIPTPATH}" "site" + echo "--- Linking OpenWrt cache directory ---" rm -rf "openwrt/dl" || true mkdir -p "${CACHE_DIR}" "openwrt" @@ -216,12 +220,6 @@ download() { EFFECTIVE_MAKEOPTS="${MAKEOPTS}" echo "--- Downloading dependencies for target: ${TARGET} ---" - - # Enable aes128-ctr+umac for fastd in x86 images - if [[ " x86-generic x86-geode x86-64 " =~ " ${TARGET} " ]] ; then - EFFECTIVE_MAKEOPTS="${EFFECTIVE_MAKEOPTS} CONFIG_FASTD_ENABLE_CIPHER_AES128_CTR=y" - fi - make ${EFFECTIVE_MAKEOPTS} \ GLUON_RELEASE="${RELEASE}" \ GLUON_TARGET="${TARGET}" \ @@ -238,12 +236,6 @@ build() { EFFECTIVE_MAKEOPTS="${MAKEOPTS}" echo "--- Building Gluon Images for target: ${TARGET} ---" - - # Enable aes128-ctr+umac for fastd in x86 images - if [[ " x86-generic x86-geode x86-64 " =~ " ${TARGET} " ]] ; then - EFFECTIVE_MAKEOPTS="${EFFECTIVE_MAKEOPTS} CONFIG_FASTD_ENABLE_CIPHER_AES128_CTR=y" - fi - make ${EFFECTIVE_MAKEOPTS} \ GLUON_RELEASE="${RELEASE}" \ GLUON_AUTOUPDATER_ENABLED=1 \ @@ -288,11 +280,11 @@ deploy() { # Copy images and modules to DEPLOYMENT_DIR CP_CMD="cp --verbose --recursive --no-dereference" - $CP_CMD "output/debug" "${TARGET}/debug" - $CP_CMD "output/images/factory" "${TARGET}/factory" - $CP_CMD "output/images/sysupgrade" "${TARGET}/sysupgrade" - $CP_CMD "output/images/other" "${TARGET}/other" - $CP_CMD "output/packages/"*"${RELEASE}" "${TARGET}/packages" + $CP_CMD "output/debug" "${TARGET}/debug" + $CP_CMD "output/images/factory" "${TARGET}/factory" + $CP_CMD "output/images/sysupgrade" "${TARGET}/sysupgrade" + $CP_CMD "output/images/other" "${TARGET}/other" + $CP_CMD "output/packages/gluon-ffmwu-${RELEASE}" "${TARGET}/packages" # Set branch link to new release echo "--- Linking branch ${BRANCH} to $(basename ${TARGET}) ---" @@ -336,9 +328,21 @@ targets(){ fi } +auto(){ + update ; download ; build ; sign ; deploy +} + +autoc(){ + clean ; auto +} + +autocc(){ + dirclean ; auto +} + ( - # Change working directory to gluon tree - cd "${GLUON_DIR}" + echo "--- Start: $(date +"%Y-%m-%d %H:%M:%S%:z") ---" + echo "--- Building Firmware / ${RELEASE} (${BRANCH}) ---" # Always link directories except link() is called explicitly if [[ "${COMMAND}" != "link" ]]; then @@ -352,4 +356,4 @@ targets(){ # Execute the selected command ${COMMAND} -) +) 2>&1 | ${LOG_CMD} diff --git a/sign.sh b/contrib/sign.sh similarity index 94% rename from sign.sh rename to contrib/sign.sh index 6f2f90c..14a16b3 100755 --- a/sign.sh +++ b/contrib/sign.sh @@ -13,13 +13,13 @@ SRV_USER="admin" SRV_HOST="griesbrei.freifunk-mwu.de" SRV_PORT="23" -SRV_PATH="/var/www/html/firmware" +SRV_PATH="/home/admin/firmware" # Help function used in error messages and -h option usage() { echo "" echo "Downloads, signs and uploads a gluon manifest file." - echo "Usage ./sign.sh KEYPATH BRANCH [VERSION]" + echo "Usage ./site/contrib/sign.sh KEYPATH BRANCH [VERSION]" echo " KEYPATH the path to the developers private key" echo " BRANCH the branch to sign" echo " VERSION the version to sign (optional)" @@ -67,7 +67,7 @@ scp \ echo "--- signing manifest ---" # Sign the local file -./gluon/contrib/sign.sh \ +./contrib/sign.sh \ "${KEYPATH}" \ "${TMP}"