From 39ad0130e520f2f7dfe42bed8a9f1018974660b8 Mon Sep 17 00:00:00 2001 From: Igor Todorovski Date: Fri, 6 Oct 2023 13:45:54 -0400 Subject: [PATCH 01/10] Correct shell scripts issues, format shell scripts --- ansible/sbin/src/volinfo_build.sh | 4 +- bin/zopen | 130 ++-- bin/zopen-alt | 244 +++---- bin/zopen-build | 1051 +++++++++++++++-------------- bin/zopen-clean | 198 +++--- bin/zopen-compute-builddeps | 34 +- bin/zopen-generate | 117 ++-- bin/zopen-help2man | 53 +- bin/zopen-importenvs | 239 +++---- bin/zopen-init | 467 ++++++------- bin/zopen-install | 611 ++++++++--------- bin/zopen-md2man | 34 +- bin/zopen-migrate-buildenv | 16 +- bin/zopen-migrate-groovy | 19 +- bin/zopen-query | 383 +++++------ bin/zopen-remove | 107 +-- bin/zopen-split-patch | 36 +- bin/zopen-update-cacert | 130 ++-- bin/zopen-version | 26 +- bin/zopen-versions | 39 +- cicd/publish_oci.sh | 28 +- include/common.sh | 438 ++++++------ tools/create_stable_release.sh | 402 +++++------ tools/format_and_check_scripts.sh | 54 ++ tools/monitor_vpc.sh | 58 +- tools/update_stable_releases.sh | 6 +- 26 files changed, 2494 insertions(+), 2430 deletions(-) create mode 100755 tools/format_and_check_scripts.sh diff --git a/ansible/sbin/src/volinfo_build.sh b/ansible/sbin/src/volinfo_build.sh index 163140ce2..09be092f5 100755 --- a/ansible/sbin/src/volinfo_build.sh +++ b/ansible/sbin/src/volinfo_build.sh @@ -3,5 +3,5 @@ # Build the C code for volinfo # #set -x -MY_DIR=$(cd `dirname $0`; echo $PWD) -c89 -O2 -Wc,list\(${MY_DIR}\) -o ${MY_DIR}/../volinfo ${MY_DIR}/volinfo.c +MY_DIR=$(cd $(dirname "$0") || exit; echo "${PWD}") +c89 -O2 -Wc,list\("${MY_DIR}"\) -o "${MY_DIR}"/../volinfo "${MY_DIR}"/volinfo.c diff --git a/bin/zopen b/bin/zopen index 44b732e86..ebf06ad01 100755 --- a/bin/zopen +++ b/bin/zopen @@ -2,14 +2,14 @@ # # General purpose zopen script # -ZOPEN_DONT_PROCESS_CONFIG=1 +ZOPEN_DONT_PROCESS_CONFIG=1 # # All zopen-* scripts MUST start with this code to maintain consistency # setupMyself() { - ME=$(basename $0) - MYDIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P )" + ME=$(basename "$0") + MYDIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P)" INCDIR="${MYDIR}/../include" if ! [ -d "${INCDIR}" ] && ! [ -f "${INCDIR}/common.sh" ]; then echo "Internal Error. Unable to find common.sh file to source" >&2 @@ -43,7 +43,7 @@ printSyntax() echo "" >&2 } -printHelp() +printHelp() { echo "zopen is a general purpose script to be used with the z/OS Open Tools ports." >&2 printSyntax @@ -66,67 +66,67 @@ help=false version=false for arg in $*; do - case "$arg" in - "alt") - subcmd='zopen-alt' - ;; - "build") - subcmd='zopen-build' - ;; - "clean") - subcmd='zopen-clean' - ;; - "download") - subcmd='zopen-install' - ;; - "generate") - subcmd='zopen-generate' - ;; - "init") - subcmd='zopen-init' - ;; - "install") - subcmd='zopen-install' - ;; - "query") - subcmd='zopen-query' - ;; - "list") - subcmd='zopen-query' - subopts="${subopts} --list" - ;; - "search") - subcmd='zopen-query' - subopts="${subopts} --remote-search" - ;; - "remove") - subcmd='zopen-remove' - ;; - "update-cacert") - subcmd='zopen-update-cacert' - ;; - "upgrade") - subcmd='zopen-install' - subopts="${subopts} -u" - ;; - "--version") - version=true - ;; - "--help") - help=true - ;; - *) - # let unknown stuff through - subopts="${subopts} ${arg}" - ;; + case "${arg}" in + "alt") + subcmd='zopen-alt' + ;; + "build") + subcmd='zopen-build' + ;; + "clean") + subcmd='zopen-clean' + ;; + "download") + subcmd='zopen-install' + ;; + "generate") + subcmd='zopen-generate' + ;; + "init") + subcmd='zopen-init' + ;; + "install") + subcmd='zopen-install' + ;; + "query") + subcmd='zopen-query' + ;; + "list") + subcmd='zopen-query' + subopts="${subopts} --list" + ;; + "search") + subcmd='zopen-query' + subopts="${subopts} --remote-search" + ;; + "remove") + subcmd='zopen-remove' + ;; + "update-cacert") + subcmd='zopen-update-cacert' + ;; + "upgrade") + subcmd='zopen-install' + subopts="${subopts} -u" + ;; + "--version") + version=true + ;; + "--help") + help=true + ;; + *) + # let unknown stuff through + subopts="${subopts} ${arg}" + ;; esac done -if [ "x${subcmd}" = "x" ]; then - if $help; then +if [ "${subcmd}" = "" ]; then + if ${help}; then printHelp exit 0 - elif $version; then + elif ${version}; then : # fall through else printSyntax @@ -134,17 +134,17 @@ if [ "x${subcmd}" = "x" ]; then fi fi -if $help; then +if ${help}; then subopts="--help" fi -if $version; then - if [ "x${subcmd}" = "x" ]; then - subopts="$ME" +if ${version}; then + if [ "${subcmd}" = "" ]; then + subopts="${ME}" else subopts="${subcmd}" fi subcmd='zopen-version' fi -${subcmd} ${subopts} +${subcmd} "${subopts}" diff --git a/bin/zopen-alt b/bin/zopen-alt index 23b77ba01..c8d29be99 100755 --- a/bin/zopen-alt +++ b/bin/zopen-alt @@ -5,20 +5,21 @@ # setupMyself() { - ME=$(basename $0) - MYDIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P )" - INCDIR="${MYDIR}/../include" - if ! [ -d "${INCDIR}" ] && ! [ -f "${INCDIR}/common.sh" ]; then - echo "Internal Error. Unable to find common.sh file to source" >&2 - exit 8 - fi - . "${INCDIR}/common.sh" + ME=$(basename "$0") + MYDIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P)" + INCDIR="${MYDIR}/../include" + if ! [ -d "${INCDIR}" ] && ! [ -f "${INCDIR}/common.sh" ]; then + echo "Internal Error. Unable to find common.sh file to source" >&2 + exit 8 + fi + . "${INCDIR}/common.sh" } setupMyself checkWritable -printHelp(){ -cat << HELPDOC +printHelp() +{ + cat <> "$TMP_FIFO_PIPE" & + # just the below would be simpler, but creates a subshell so can't get the number of entries outside! + # echo "$found" | xargs | tr ' ' '\n' | while read repo; do + TMP_FIFO_PIPE="${HOME}/altselect.pipe" + [ ! -p "${TMP_FIFO_PIPE}" ] || rm -f "${TMP_FIFO_PIPE}" + mkfifo "${TMP_FIFO_PIPE}" + echo "${found}" | xargs | tr ' ' '\n' >>"${TMP_FIFO_PIPE}" & while read repo; do - printVerbose "Parsing repo: '$repo' as '${repo#$ZOPEN_PKGINSTALL/}'" - i=$(expr $i + 1) - if [ "${deref#$ZOPEN_PKGINSTALL/}" = "${repo#$ZOPEN_PKGINSTALL/}" ]; then - current=$i - printInfo "${NC}${GREEN}$i: ${repo#$ZOPEN_PKGINSTALL/} <- current${NC}" + printVerbose "Parsing repo: '${repo}' as '${repo#"${ZOPEN_PKGINSTALL}"/}'" + i=$(expr "${i}" + 1) + if [ "${deref#"${ZOPEN_PKGINSTALL}"/}" = "${repo#"${ZOPEN_PKGINSTALL}"/}" ]; then + current=${i} + printInfo "${NC}${GREEN}${i}: ${repo#"${ZOPEN_PKGINSTALL}"/} <- current${NC}" else - printInfo "$i: ${repo#"$ZOPEN_PKGINSTALL"/}" + printInfo "${i}: ${repo#"${ZOPEN_PKGINSTALL}"/}" fi - done < "$TMP_FIFO_PIPE" - [ ! -p $TMP_FIFO_PIPE ] || rm -rf "$TMP_FIFO_PIPE" + done <"${TMP_FIFO_PIPE}" + [ ! -p "${TMP_FIFO_PIPE}" ] || rm -rf "${TMP_FIFO_PIPE}" - if $select; then + if ${select}; then mutexReq "zopen" "zopen" - selectAlt "$i" "$package" "$deref" + selectAlt "${i}" "${package}" "${deref}" unset select mutexFree "zopen" - listAlts false "$package" + listAlts false "${package}" fi exit 0 } - # Main code start here args=$* verbose=false debug=false -sett=false #sett to distinguish from "set" command +sett=false #sett to distinguish from "set" command select=false if [ $# -eq 0 ]; then printError "Missing program argument" @@ -191,48 +195,48 @@ fi while [ $# -gt 0 ]; do printVerbose "Parsing option: $1" case "$1" in - "-s" | "--set") - shift - [ $# -lt 2 ] && printError "Missing argument(s) for set option. Check program arguments" - sett=true - select=false - package="$1" - newver="$2" - shift + "-s" | "--set") + shift + [ $# -lt 2 ] && printError "Missing argument(s) for set option. Check program arguments" + sett=true + select=false + package="$1" + newver="$2" + shift + ;; + "--select") + select=true + sett=false + shift + [ $# -lt 1 ] && printError "Missing argument for select option." + package="$1" + ;; + "-h" | "--help" | "-?") + printHelp "${args}" + exit 0 + ;; + "--version") + zopen --version "${ME}" + exit 0 + ;; + "-v" | "--verbose") + verbose=true + ;; + "--debug") + verbose=true + debug=true + ;; + *) + package="$1" # Multiple packages will result in the last package only ;; - "--select") - select=true - sett=false - shift - [ $# -lt 1 ] && printError "Missing argument for select option." - package="$1" - ;; - "-h" | "--help" | "-?") - printHelp "${args}" - exit 0 - ;; - "--version") - zopen --version $ME - exit 0 - ;; - "-v" | "--verbose") - verbose=true - ;; - "--debug") - verbose=true - debug=true - ;; - *) - package="$1"; # Multiple packages will result in the last package only - ;; esac - shift; + shift done -if $sett; then - setAlt "$package" "$newver" -elif [ -n "$package" ]; then - listAlts $select "$package" +if ${sett}; then + setAlt "${package}" "${newver}" +elif [ -n "${package}" ]; then + listAlts "${select}" "${package}" else printError "No action verb specified. Run zopen alt --help for command syntax" fi diff --git a/bin/zopen-build b/bin/zopen-build index ed77aceb9..648b860b0 100755 --- a/bin/zopen-build +++ b/bin/zopen-build @@ -12,14 +12,14 @@ # setupMyself() { - ME=$(basename $0) - MYDIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P )" - INCDIR="${MYDIR}/../include" - if ! [ -d "${INCDIR}" ] && ! [ -f "${INCDIR}/common.sh" ]; then - echo "Internal Error. Unable to find common.sh file to source" >&2 - exit 8 - fi - . "${INCDIR}/common.sh" + ME=$(basename "$0") + MYDIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P)" + INCDIR="${MYDIR}/../include" + if ! [ -d "${INCDIR}" ] && ! [ -f "${INCDIR}/common.sh" ]; then + echo "Internal Error. Unable to find common.sh file to source" >&2 + exit 8 + fi + . "${INCDIR}/common.sh" } setupMyself @@ -120,7 +120,7 @@ User-Provided environment variables: printFunctions() { -echo "User-Provided functions: + echo "User-Provided functions: zopen_init This function runs after code is downloaded and patched but before the code is built. zopen_post_buildenv This function runs after the 'buildenv' is processed. zopen_pre_patch This function runs before the 'patch' step of the build is run. @@ -137,51 +137,50 @@ echo "User-Provided functions: } # Temporary files -for tmp in "$TMPDIR" "$TMP" /tmp -do - if [ ! -z $tmp ] && [ -d $tmp ]; then +for tmp in "${TMPDIR}" "${TMP}" /tmp; do + if [ ! -z "${tmp}" ] && [ -d "${tmp}" ]; then break fi done -if [ ! -d "$tmp" ]; then +if [ ! -d "${tmp}" ]; then printError "Temporary directory not found. Please specify \$TMPDIR, \$TMP or have a valid /tmp directory" fi -TMP_FIFO_PIPE="$tmp/$LOGNAME.pipe" -ZOPEN_TEMP_C_FILE="$tmp/$LOGNAME.c" - +TMP_FIFO_PIPE="${tmp}/${LOGNAME}.pipe" +ZOPEN_TEMP_C_FILE="${tmp}/${LOGNAME}.c" # Capture start time before setting trap -fullBuildStartTime=$SECONDS +fullBuildStartTime=${SECONDS} # Remove temoraries on exit and report elapsed time -cleanupOnExit() { - rv=$? - [ -f $ZOPEN_TEMP_C_FILE ] && rm -rf $ZOPEN_TEMP_C_FILE - [ -p $TMP_FIFO_PIPE ] && rm -rf $TMP_FIFO_PIPE - if [ ! -z "$TEE_PID" ]; then - if kill -0 $TEE_PID 2>/dev/null; then - kill -9 $TEE_PID; - fi +cleanupOnExit() +{ + rv=$? + [ -f "${ZOPEN_TEMP_C_FILE}" ] && rm -rf "${ZOPEN_TEMP_C_FILE}" + [ -p "${TMP_FIFO_PIPE}" ] && rm -rf "${TMP_FIFO_PIPE}" + if [ ! -z "${TEE_PID}" ]; then + if kill -0 "${TEE_PID}" 2>/dev/null; then + kill -9 "${TEE_PID}" fi - printElapsedTime info "zopen-build" $fullBuildStartTime - trap - EXIT # clear the EXIT trap so that it's not double called - exit $rv + fi + printElapsedTime info "zopen-build" "${fullBuildStartTime}" + trap - EXIT # clear the EXIT trap so that it's not double called + exit "${rv}" } trap "cleanupOnExit" EXIT INT TERM QUIT HUP setDefaultBuild() { - if [ ! -z "$ZOPEN_BUILD_LINE_OPT" ]; then + if [ ! -z "${ZOPEN_BUILD_LINE_OPT}" ]; then ZOPEN_BUILD_LINE=$(echo "${ZOPEN_BUILD_LINE_OPT}" | tr '[a-z]' '[A-Z]') else ZOPEN_BUILD_LINE=$(echo "${ZOPEN_BUILD_LINE}" | tr '[a-z]' '[A-Z]') fi - if [ ! -z "$ZOPEN_BUILD_LINE" ]; then - printVerbose "Setting build to $ZOPEN_BUILD_LINE" + if [ ! -z "${ZOPEN_BUILD_LINE}" ]; then + printVerbose "Setting build to ${ZOPEN_BUILD_LINE}" fi } @@ -198,10 +197,10 @@ setDefaults() export ZOPEN_INSTALL_OPTSD="install" export ZOPEN_CLEAND="make" export ZOPEN_CLEAN_OPTSD="clean" - if [ -z "$ZOPEN_IMAGE_DOCKERFILE_NAME" ]; then + if [ -z "${ZOPEN_IMAGE_DOCKERFILE_NAME}" ]; then export ZOPEN_IMAGE_DOCKERFILE_NAME="Dockerfile" fi - if [ -z "$ZOPEN_IMAGE_DOCKER_NAME" ]; then + if [ -z "${ZOPEN_IMAGE_DOCKER_NAME}" ]; then export ZOPEN_IMAGE_DOCKER_NAME="podman" fi export ZOPEN_TEST_STATUS_ALL_PASSED=0 @@ -226,39 +225,41 @@ setDefaults() printSyntax() { args=$* - (echo "" - echo "zopen-build is a general purpose build script to be used with the ZOSOpenTools ports." - echo "The specifics of how the tool works can be controlled through environment variables." - echo "The only environment variables you _must_ specify are to tell zopen-build where the " - echo " source is, and in what format type the source is stored." - echo "By default, the environment variables are defined in a file named buildenv in the " - echo " root directory of the port github repository" - echo "To see a fully functioning z/OSOpenTools sample port" - echo " see: https://github.com/ZOSOpenTools/zotsampleport" - echo "" - echo "Syntax: zopen-build [