Skip to content
110 changes: 55 additions & 55 deletions bin/zopen
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -67,58 +67,58 @@ 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}"
;;
"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

Expand Down
154 changes: 79 additions & 75 deletions bin/zopen-alt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -47,15 +48,16 @@ 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
printVerbose "Removing main link"
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
Expand All @@ -64,8 +66,8 @@ mergeNewVersion(){
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"
Expand All @@ -80,7 +82,8 @@ mergeNewVersion(){
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
Expand All @@ -100,34 +103,36 @@ setAlt(){
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"

Expand All @@ -150,12 +155,12 @@ listAlts(){

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
# 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" &
echo "$found" | xargs | tr ' ' '\n' >>"$TMP_FIFO_PIPE" &
while read repo; do
printVerbose "Parsing repo: '$repo' as '${repo#$ZOPEN_PKGINSTALL/}'"
i=$(expr $i + 1)
Expand All @@ -165,7 +170,7 @@ listAlts(){
else
printInfo "$i: ${repo#"$ZOPEN_PKGINSTALL"/}"
fi
done < "$TMP_FIFO_PIPE"
done <"$TMP_FIFO_PIPE"
[ ! -p $TMP_FIFO_PIPE ] || rm -rf "$TMP_FIFO_PIPE"

if $select; then
Expand All @@ -178,55 +183,54 @@ listAlts(){
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"
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
Expand Down
Loading