From 93344a0cd5dfe15d4809e885f6e933f01eaf211b Mon Sep 17 00:00:00 2001 From: Bradley G Smith Date: Feb 09 2024 18:28:12 +0000 Subject: Improve Script Handing Of Arguments Add -c option to create draft configuration file. --- diff --git a/newrelease.sh b/newrelease.sh index 776bd15..3186a7f 100755 --- a/newrelease.sh +++ b/newrelease.sh @@ -20,10 +20,10 @@ CFG_NAME=./newrelease.conf ### ### newrelease - set up for a new version of kubernetes. Does the following: -### 1. Checks for configuration file and will generate draft -### configuration file if missing. +### 1. Checks for configuration file and creates if missing. Optionally, +### create a draft configuration file. ### 2. Use data from configuration file to generate kubernetes.spec -### from the ./template/kubernetes.yaml template file. +### from the ./template/kubernetes-template.spec template file. ### 3. Download source, if needed, based on configuration. ### ### Configuration file is named 'newrelease.conf'. @@ -31,10 +31,13 @@ CFG_NAME=./newrelease.conf ### Usage: ### newrelease.sh -- this help file ### newrelease.sh -h -- this help file +### newrelease.sh -c -- generate configuration file ### newrelease.sh -y -- execute using configuration file ### ### Options: -### -y Execute script. If missing configuration file, generate draft and exit +### -y Execute script using configuration file. If configuration +### does not exist then create draft +### -c Create draft configuration file ### -h Show this message ### @@ -43,25 +46,24 @@ help() { sed -rn 's/^### ?//;T;p' "$0" } -if [[ $# == 0 || $1 == -h || "$1" != "-y" ]]; then +# display help and exit if no arguements, -h or not either +# -y or -c +if [[ $# == 0 || $1 == "-h" || ! ($1 =~ (-y|-c)) ]]; then help exit 1 fi -# load config file from local directory using CFG_NAME -# format is standard bash source. +# if -c flag, create config file and exit +if [[ ($1 =~ (-c|-C)) || ($1 == "-y" && ! -f "$CFG_NAME") ]]; then -# variables are: -# SPEC_NAME - name of the spec file to process -# GIT_TAG - release tag of package -# GOLANG_VERSION - minimal golang version (version used in build) + if [ -f "$CFG_NAME" ] + then + echo "** Configuration file already exists. " + echo "** Remove to create a new configuration file or edit and reuse." + help + exit 1 + fi -if [ -f "$CFG_NAME" ] -then -# shellcheck disable=SC1090 - source "${CFG_NAME}" - echo "Sourcing ${CFG_NAME}" -else echo " Creating draft configuration file" echo " Edit ${CFG_NAME} with release information and rerun script" { @@ -73,6 +75,18 @@ else exit 1 fi +# load config file from local directory using CFG_NAME +# format is standard bash source. + +# variables are: +# SPEC_NAME - name of the spec file to process +# GIT_TAG - release tag of package +# GOLANG_VERSION - minimal golang version (version used in build) + +# shellcheck disable=SC1090 +source "${CFG_NAME}" +echo "Sourcing ${CFG_NAME}" + # generate needed values # do not edit warning export WARNING="# Do not edit this spec file. (Re-)Generate using newrelease.sh"