diff --git a/bin/zopen b/bin/zopen index 44b732e86..014d7c950 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 )" + 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 [ -z "${subcmd}" ]; then + if ${help}; then printHelp exit 0 - elif $version; then + elif ${version}; then : # fall through else printSyntax @@ -134,13 +134,13 @@ 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 [ -z "${subcmd}" ]; then + subopts="${ME}" else subopts="${subcmd}" fi diff --git a/bin/zopen-alt b/bin/zopen-alt index 23b77ba01..f85fe27c1 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 << HELPDOC zopen alt is a utility for z/OS Open Tools to switch package versions for currently installed packages. @@ -47,29 +48,30 @@ Report bugs at https://github.com/ZOSOpenTools/meta/issues . HELPDOC } -mergeNewVersion(){ +mergeNewVersion() +{ package="$1" newver="$2" - [ -d "$ZOPEN_PKGINSTALL/$package/$newver" ] || printError "Version '$newver' was not available to set as current" - if [ -e "$ZOPEN_PKGINSTALL/$package/$package" ]; then + [ -d "${ZOPEN_PKGINSTALL}/${package}/${newver}" ] || printError "Version '${newver}' was not available to set as current" + if [ -e "${ZOPEN_PKGINSTALL}/${package}/${package}" ]; then printVerbose "Removing main link" - rm -rf "$ZOPEN_PKGINSTALL/$package/$package" + rm -rf "${ZOPEN_PKGINSTALL}/${package}/${package}" fi - mergeIntoSystem "$package" "$ZOPEN_PKGINSTALL/$package/$newver" "$ZOPEN_ROOTFS" + mergeIntoSystem "${package}" "${ZOPEN_PKGINSTALL}/${package}/${newver}" "${ZOPEN_ROOTFS}" printVerbose "New version merged; checking for orphaned files from previous version" # This will remove any old symlinks or dirs that might have changed in an up/downgrade # as the merge process overwrites existing files to point to different version. If there was # no other version, then $deref will be empty so nothing to uninstall - if [ -n "$deref" ]; then - unsymlinkFromSystem "$package" "$ZOPEN_ROOTFS" "${ZOPEN_PKGINSTALL}/$package/$deref/.links" + if [ -n "${deref}" ]; then + unsymlinkFromSystem "${package}" "${ZOPEN_ROOTFS}" "${ZOPEN_PKGINSTALL}/${package}/${deref}/.links" else printVerbose "No previous version found (no .links) - no unlinking performed" - fi - + fi + misrc=$? - printVerbose "The merge completed with: $misrc" - printVerbose "Generating main link from $package to version: $newver" - if ! ln -sf "$newver" "$ZOPEN_PKGINSTALL/$package/$package"; then + printVerbose "The merge completed with: ${misrc}" + printVerbose "Generating main link from ${package} to version: ${newver}" + if ! ln -sf "${newver}" "${ZOPEN_PKGINSTALL}/${package}/${package}"; then printError "Could not create symbolic link name" fi touch "${ZOPEN_PKGINSTALL}/${package}/${package}/.active" @@ -77,113 +79,115 @@ mergeNewVersion(){ if [ -e "${ZOPEN_PKGINSTALL}/${package}/${package}/.releaseinfo" ]; then version=$(cat "${ZOPEN_PKGINSTALL}/${package}/${package}/.releaseinfo") fi - syslog "$ZOPEN_LOG_PATH/audit.log" "$LOG_A" "$CAT_PACKAGE" "ALT" "setAlt" "Set '${package}' to version:$version;" + syslog "${ZOPEN_LOG_PATH}/audit.log" "${LOG_A}" "${CAT_PACKAGE}" "ALT" "setAlt" "Set '${package}' to version:${version};" } -setAlt(){ +setAlt() +{ package="$1" newver="$2" - if [ -e "$ZOPEN_PKGINSTALL/$package/" ]; then - printVerbose "$package is either installed or has been previously" - found=$(zosfind "$ZOPEN_PKGINSTALL/$package/" -type l -prune -o -type d -print | sed -e "s#$ZOPEN_PKGINSTALL/$package/\([^/]*\).*#\1#" | uniq) + if [ -e "${ZOPEN_PKGINSTALL}/${package}/" ]; then + printVerbose "${package} is either installed or has been previously" + found=$(zosfind "${ZOPEN_PKGINSTALL}/${package}/" -type l -prune -o -type d -print | sed -e "s#${ZOPEN_PKGINSTALL}/${package}/\([^/]*\).*#\1#" | uniq) else - printVerbose "$package has never been installed on the system" + printVerbose "${package} has never been installed on the system" fi - if [ -z "$found" ]; then + if [ -z "${found}" ]; then printInfo "No available versions of package '${package}'" exit 4 fi - if [ -e "$ZOPEN_PKGINSTALL/$package/$package" ]; then - deref=$(ls -l "$ZOPEN_PKGINSTALL/$package/$package" | awk '{ print $(NF) }') - printVerbose "Current version: ${deref#$ZOPEN_PKGINSTALL/}" + if [ -e "${ZOPEN_PKGINSTALL}/${package}/${package}" ]; then + deref=$(ls -l "${ZOPEN_PKGINSTALL}/${package}/${package}" | awk '{ print $(NF) }') + printVerbose "Current version: ${deref#"${ZOPEN_PKGINSTALL}"/}" fi - mergeNewVersion "$package" "$newver" + mergeNewVersion "${package}" "${newver}" } -selectAlt(){ +selectAlt() +{ i=$1 package=$2 printVerbose "Selecting alternative" - valid=false - while ! $valid; do - echo "Enter alternative version to use (1-$i): " - selection=$(getInput) - if [ ! -z "$(echo $selection | sed -e 's/[0-9]*//')" ]; then - echo "Invalid input, must be a number between 1 and $i" - elif [ "$selection" -ge 1 ] && [ "$selection" -le "$i" ]; then - valid=true - fi - done - if [ ! "$selection" -eq "$current" ]; then - newver="$(echo $found | awk -v selection="$selection" ' + valid=false + while ! ${valid}; do + echo "Enter alternative version to use (1-${i}): " + selection=$(getInput) + if [ ! -z "$(echo ${selection} | sed -e 's/[0-9]*//')" ]; then + echo "Invalid input, must be a number between 1 and ${i}" + elif [ "${selection}" -ge 1 ] && [ "${selection}" -le "${i}" ]; then + valid=true + fi + done + if [ ! "${selection}" -eq "${current}" ]; then + newver="$(echo ${found} | awk -v selection="${selection}" ' BEGIN {count=0} {count = count + 1; if (count=selection) { print $(selection)} } ')" - printInfo "selecting alternative: $selection: $newver" - mergeNewVersion "$package" "$newver" - else - printInfo "Selection is already current version." - exit 0 - fi + printInfo "selecting alternative: ${selection}: ${newver}" + mergeNewVersion "${package}" "${newver}" + else + printInfo "Selection is already current version." + exit 0 + fi } -listAlts(){ +listAlts() +{ select=$1 package="$2" - printVerbose "Checking for the existence of the '$package' package directory within PKGINSTALL" - package=$(echo "$package" | awk '{$1=$1};1') - if [ -e "$ZOPEN_PKGINSTALL/$package/" ]; then - printVerbose "$package is either installed or has been previously" - found=$(zosfind "$ZOPEN_PKGINSTALL/$package/" -type l -prune -o -type d -print | sed -e "s#$ZOPEN_PKGINSTALL/$package/\([^/]*\).*#\1#" | uniq) + printVerbose "Checking for the existence of the '${package}' package directory within PKGINSTALL" + package=$(echo "${package}" | awk '{$1=$1};1') + if [ -e "${ZOPEN_PKGINSTALL}/${package}/" ]; then + printVerbose "${package} is either installed or has been previously" + found=$(zosfind "${ZOPEN_PKGINSTALL}/${package}/" -type l -prune -o -type d -print | sed -e "s#${ZOPEN_PKGINSTALL}/${package}/\([^/]*\).*#\1#" | uniq) else - printVerbose "$package has never been installed on the system" + printVerbose "${package} has never been installed on the system" fi - if [ -z "$found" ]; then + if [ -z "${found}" ]; then printInfo "No currently available version of package '${package}'" exit 4 fi - if [ -e "$ZOPEN_PKGINSTALL/$package/$package" ]; then - deref=$(ls -l "$ZOPEN_PKGINSTALL/$package/$package" | awk '{ print $(NF) }') - printVerbose "Current version: ${deref#$ZOPEN_PKGINSTALL/}" + if [ -e "${ZOPEN_PKGINSTALL}/${package}/${package}" ]; then + deref=$(ls -l "${ZOPEN_PKGINSTALL}/${package}/${package}" | awk '{ print $(NF) }') + printVerbose "Current version: ${deref#"${ZOPEN_PKGINSTALL}"/}" fi i=0 current=0 -# 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" & + # 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..2567ec4e7 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 @@ -39,12 +39,12 @@ asciiecho() text="$1" file="$2" - if ! echo "${text}" >"${file}"; then + if ! echo "${text}" > "${file}"; then echo "Unable to echo text to ${file}" >&2 return 2 fi if [ "$(chtag -p "${file}" | cut -f2 -d' ')" = "IBM-1047" ]; then - if ! /bin/iconv -f IBM-1047 -t ISO8859-1 <"${file}" >"${file}_ascii" || ! chtag -tc ISO8859-1 "${file}_ascii" || ! mv "${file}_ascii" "${file}"; then + if ! /bin/iconv -f IBM-1047 -t ISO8859-1 < "${file}" > "${file}_ascii" || ! chtag -tc ISO8859-1 "${file}_ascii" || ! mv "${file}_ascii" "${file}"; then printError "Unable to convert EBCDIC text to ASCII for ${file}" >&2 fi fi @@ -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 [