From 5ef61d7203853ab4dab971729992e5ce941c13dd Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Nov 03 2017 21:33:26 +0000 Subject: Make release-candidate.sh script more durable - add value and error checking to release-candidate script - change backtick subshells to modern subshells - change script to use /bin/bash because several features in the old script are not actually POSIX SH compliant Signed-off-by: Robert Marshall --- diff --git a/release-candidate.sh b/release-candidate.sh index 133f826..ae99041 100755 --- a/release-candidate.sh +++ b/release-candidate.sh @@ -1,32 +1,127 @@ -#!/bin/sh +#!/bin/bash +############################################################################## +# release-candidate script +############################################################################## + export LC_ALL=C -LABEL=$1 -# Remove the label from arguments. It gets special treatment. Other arguments -# to the script are passed to pungi-koji directly. -shift -CONFIG="fedora-final.conf" -TARGET_DIR="/mnt/koji/compose/26" -#OLD_COMPOSES_DIR="--old-composes=/mnt/fedora_koji/compose/f23 --old-composes=$TARGET_DIR" -NIGHTLY="" -SKIP_PHASES="--skip-phase=productimg" -DEST=$(pwd) -DATE=$(date "+%Y%m%d") -COMPSFILE="comps-f26.xml" -TMPDIR=`mktemp -d /tmp/fedoraRC.$DATE.XXXX` -# uncomment and edit for resuming a failed compose -#COMPOSE_ID="Fedora-23-20150530.n.0" -pushd $TMPDIR -git clone https://pagure.io/fedora-comps.git && { - pushd fedora-comps - make "${COMPSFILE}" - cp "${COMPSFILE}" $DEST/ - popd +#------------------------------------------------------------------------------ +# Helper Functions +#------------------------------------------------------------------------------ +show_help() +{ + exit_code=0 + if [ "$1" = "ERR" ]; then + exit_code=1 + fi + echo "$0 release-label release-version" + echo " release-label: Alpha-1.#, Beta-1.#, RC-1.#" + echo " release-version: The release of Fedora being composed" + exit "${exit_code}" +} + +display_error() +{ + msg="$1" + echo "ERROR: ${msg}" + echo "" + show_help "ERR" } -popd -CMD="pungi-koji --notification-script=/usr/bin/pungi-fedmsg-notification --config=$CONFIG --old-composes=$TARGET_DIR $OLD_COMPOSES_DIR $NIGHTLY $SKIP_PHASES --label=$LABEL" -if [ -z "$COMPOSE_ID" ]; then - CMD="$CMD --target-dir=$TARGET_DIR" + + +#------------------------------------------------------------------------------ +# static defines +#------------------------------------------------------------------------------ +COMPOSES_HOME="/mnt/koji/compose/" + +[ -d "${COMPOSES_HOME}" ] || display_error "${COMPOSES_HOME} missing" + +#------------------------------------------------------------------------------ +# assign input +#------------------------------------------------------------------------------ +release_label="$1" +release_version="$2" +# pop the first two arguments off so the rest can be passed through to pungi +shift +shift + +[ -z "${release_label}" ] && display_error "Candidate name missing" +[ -z "${release_version}" ] && display_error "Fedora release missing" + +#------------------------------------------------------------------------------ +# sanitize input +#------------------------------------------------------------------------------ +if echo "${release_label}" | grep -qE "(Alpha|Beta|RC)-1.[0-9]{0,3}$"; then + display_error "Candidate name must follow convention" +fi + +sanitized_release="${release_version//[0-9]/}" + +if [ -n "${sanitized_release}" ]; then + display_error "Fedora release may only be a number" +fi + +#------------------------------------------------------------------------------ +# build and validate meta-variables +#------------------------------------------------------------------------------ +if echo "${release_label}" | grep -qi "alpha"; then + compose_config="alpha" +elif echo "${release_label}" | grep -qi "beta"; then + compose_config="beta" +elif echo "${release_label}" | grep -qi "rc"; then + compose_config="final" +fi + +compose_config="${PWD}/fedora-${compose_config}.conf" + +if [ ! -f "${compose_config}" ]; then + display_error "Could not locate config: ${compose_config}" +fi + +#------------------------------------------------------------------------------ +# create the directory path for the compose +#------------------------------------------------------------------------------ +release_path="${COMPOSES_HOME}${release_version}/" +mkdir -p "${release_path}" || display_error "Failed to create ${release_path}" +[ -d "${release_path}" ] || display_error "Does not exist: ${release_path}" + +script_path="${PWD}" +timestamp=$(date "+%Y%m%d") +checkout_path=$(mktemp -d "/tmp/fedoraRC.${timestamp}.XXXX") + +pushd "${checkout_path}" + +if git clone https://pagure.io/fedora-comps.git; then + pushd "fedora-comps" || display_error "Failed to move to fedora-comps" + + comps_file="comps-f${release_version}.xml" + + make "${comps_file}" + if ! cp "${comps_file}" "${script_path}"; then + display_error "Could not copy ${comps_file}" + fi + + popd || display_error "Failed to return to ${checkout_path}" + popd || display_error "Failed to return to ${script_path}" else - CMD="$CMD --debug-mode --compose-dir=$TARGET_DIR/$COMPOSE_ID" + display_error "Failed to clone fedora-comps repository" fi -time $CMD "$@" + + +#------------------------------------------------------------------------------ +# define pungi-koji arguments and build command +#------------------------------------------------------------------------------ +nightly="" +BIN="/usr/bin/pungi-koji" + +notifier="--notification-script=/usr/bin/pungi-fedmsg-notification" +config="--config=${compose_config}" +old_composes="--old-composes=${release_path} ${nightly}" +skip_phases="--skip-phase=productimg" +label="--label=${release_label}" +target_dir="--target-dir=${release_path}" + +args="${notifier} ${config} ${old_composes} ${skip_phases} ${label} ${target_dir}" + +run_compose="${BIN} ${args}" + +time ${run_compose} "$@" || display_error "Compose step failed"