From 5b4ddf64362f25a3c76115e77d483cd11fcdec0a Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Wed, 25 Oct 2023 16:09:37 +0200 Subject: [PATCH 01/17] Zwe install typescript version Signed-off-by: Martin Zeithaml --- bin/commands/install/.examples | 1 + bin/commands/install/.help | 9 +- bin/commands/install/cli.js | 26 ++++++ bin/commands/install/clix.js | 22 +++++ bin/commands/install/index.sh | 150 +++++++++++++++++++-------------- bin/commands/install/index.ts | 150 +++++++++++++++++++++++++++++++++ bin/libs/zos-dataset.sh | 4 +- bin/libs/zos-dataset.ts | 25 ++++++ 8 files changed, 322 insertions(+), 65 deletions(-) create mode 100644 bin/commands/install/cli.js create mode 100644 bin/commands/install/clix.js create mode 100644 bin/commands/install/index.ts diff --git a/bin/commands/install/.examples b/bin/commands/install/.examples index 3a8e5e88fb..9f791e1fe6 100644 --- a/bin/commands/install/.examples +++ b/bin/commands/install/.examples @@ -1 +1,2 @@ zwe install -v -c /path/to/zowe.yaml +zwe install --dataset-prefix USER.ZOWE diff --git a/bin/commands/install/.help b/bin/commands/install/.help index 3e21d52635..816ccb7a7a 100644 --- a/bin/commands/install/.help +++ b/bin/commands/install/.help @@ -13,9 +13,16 @@ zowe: prefix: IBMUSER.ZWE ``` +The command does not require Zowe YAML configuration and can be used +with parameter `--dataset-prefix`. + +Note: if `--dataset-prefix` is used, `zowe.setup.dataset.prefix` is ignored. + Expected outputs: -- Will create these data sets under `zowe.setup.dataset.prefix` definition: +- Will create these data sets under `zowe.setup.dataset.prefix` +or `--dataset-prefix` definition: * `SZWEAUTH` contains few Zowe load modules (++PROGRAM). * `SZWESAMP` contains several sample configurations. * `SZWEEXEC` contains few utilities used by Zowe. + * `SZWELOAD` contains config manager for rexx. diff --git a/bin/commands/install/cli.js b/bin/commands/install/cli.js new file mode 100644 index 0000000000..2c5d138da2 --- /dev/null +++ b/bin/commands/install/cli.js @@ -0,0 +1,26 @@ +/* + This program and the accompanying materials are made available + under the terms of the Eclipse Public License v2.0 which + accompanies this distribution, and is available at + https://www.eclipse.org/legal/epl-v20.html + + SPDX-License-Identifier: EPL-2.0 + + Copyright Contributors to the Zowe Project. +*/ + +import * as index from './index'; +import * as common from '../../libs/common'; +import * as config from '../../libs/config'; +import * as configmgr from '../../libs/configmgr'; + +common.requireZoweYaml(); +const zoweConfig = config.getZoweConfig(); +const prefix = zoweConfig.zowe?.setup?.dataset?.prefix; +if (!prefix){ + common.printLevel1Message("Install Zowe MVS data sets"); + common.printErrorAndExit(`Error ZWEL0157E: Zowe dataset prefix (zowe.setup.dataset.prefix) is not defined in Zowe YAML configuration file.`, undefined, 157); +} + +index.execute(prefix); +configmgr.cleanupTempDir(); diff --git a/bin/commands/install/clix.js b/bin/commands/install/clix.js new file mode 100644 index 0000000000..8fad02d2cd --- /dev/null +++ b/bin/commands/install/clix.js @@ -0,0 +1,22 @@ +/* + This program and the accompanying materials are made available + under the terms of the Eclipse Public License v2.0 which + accompanies this distribution, and is available at + https://www.eclipse.org/legal/epl-v20.html + + SPDX-License-Identifier: EPL-2.0 + + Copyright Contributors to the Zowe Project. +*/ + +import * as index from './index'; +import * as std from 'cm_std'; +import * as zosdataset from '../../libs/zos-dataset'; + +const prefix = std.getenv("ZWE_CLI_PARAMETER_DATASET_PREFIX"); +if (!prefix || !zosdataset.validDatasetName(prefix)){ + common.printLevel1Message("Install Zowe MVS data sets"); + common.printErrorAndExit(`Error ZWEL0102E: Invalid parameter --dataset-prefix="${prefix}".`, undefined, 102); +} + +index.execute(prefix); diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index 0fc9e7fad6..1f4e39155b 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -11,6 +11,19 @@ # Copyright Contributors to the Zowe Project. ####################################################################### +USE_CONFIGMGR=$(check_configmgr_enabled) +if [ "${USE_CONFIGMGR}" = "true" ]; then + if [ -z "${ZWE_CLI_PARAMETER_CONFIG}" ]; then + _CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/clix.js" + else + if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then + # user-facing command, use tmpdir to not mess up workspace permissions + export ZWE_PRIVATE_TMP_MERGED_YAML_DIR=1 + fi + _CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/cli.js" + fi +else + print_level0_message "Install Zowe MVS data sets" ############################### @@ -27,7 +40,6 @@ if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then prefix="${ZWE_CLI_PARAMETER_DATASET_PREFIX}" else require_zowe_yaml - # read prefix and validate prefix=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.prefix") if [ -z "${prefix}" ]; then @@ -38,21 +50,21 @@ fi ############################### # create data sets if they do not exist print_message "Create MVS data sets if they do not exist" +ds_count=0 while read -r line; do ds=$(echo "${line}" | awk -F"|" '{print $1}') name=$(echo "${line}" | awk -F"|" '{print $2}') spec=$(echo "${line}" | awk -F"|" '{print $3}') - + typeset "$ds=true" # check existence ds_existence=$(is_data_set_exists "${prefix}.${ds}") if [ "${ds_existence}" = "true" ]; then if [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" = "true" ]; then - # warning print_message "Warning ZWEL0300W: ${prefix}.${ds} already exists. Members in this data set will be overwritten." else - # print_error_and_exit "Error ZWEL0158E: ${prefix}.${ds} already exists." "" 158 - # warning print_message "Warning ZWEL0301W: ${prefix}.${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite." + ds_count=$(( $ds_count + 1 )) + typeset "$ds=false" fi else print_message "Creating ${name} - ${prefix}.${ds}" @@ -64,78 +76,91 @@ while read -r line; do done < --help\" (for example, \"zwe init stc --help\") to get more information." print_message + +fi diff --git a/bin/commands/install/index.ts b/bin/commands/install/index.ts new file mode 100644 index 0000000000..537e44f9a1 --- /dev/null +++ b/bin/commands/install/index.ts @@ -0,0 +1,150 @@ +/* + This program and the accompanying materials are made available + under the terms of the Eclipse Public License v2.0 which + accompanies this distribution, and is available at + https://www.eclipse.org/legal/epl-v20.html + + SPDX-License-Identifier: EPL-2.0 + + Copyright Contributors to the Zowe Project. +*/ + +import * as std from 'cm_std'; +import * as os from 'cm_os' +import * as common from '../../libs/common'; +import * as fs from '../../libs/fs'; +import * as zosdataset from '../../libs/zos-dataset'; + +function copyFromDirectory(pathFrom: string, datasetTo: string, copyOptions: string) { + const stats = os.stat(pathFrom); + if (stats[1]) + common.printErrorAndExit("Error ZWEL0104E: Invalid command 'os.stat'", undefined, 104); + // Copy all files from directory + if (stats[1] == 0 && ((stats[0].mode & os.S_IFMT) == os.S_IFDIR)){ + const modules = fs.getFilesInDirectory(pathFrom) || []; + for (let i = 0; i < modules.length; i++) { + const module = modules[i]; + common.printMessage(`Copy ${pathFrom}/${module} to ${datasetTo}`); + const rc = zosdataset.copyToDataset(`${pathFrom}/${module}`, datasetTo, copyOptions, true); + if (rc != 0) { + common.printErrorAndExit("Error ZWEL0111E: Command aborts with error.", undefined, 111); + } + } + return; + } + // Copy specified file from directory + if (stats[1] == 0 && ((stats[0].mode & os.S_IFMT) == os.S_IFREG)) { + common.printMessage(`Copy ${pathFrom} to ${datasetTo}`); + const rc = zosdataset.copyToDataset(pathFrom, datasetTo, copyOptions, true); + if (rc != 0) { + common.printErrorAndExit("Error ZWEL0111E: Command aborts with error.", undefined, 111); + } + } +} + +export function execute(prefix: string) { + common.printLevel1Message("Install Zowe MVS data sets"); + + const allowOverwrite = std.getenv("ZWE_CLI_PARAMETER_ALLOW_OVERWRITE") == 'true' ? true : false; + const sampLib = std.getenv("ZWE_PRIVATE_DS_SZWESAMP"); + const authLib = std.getenv("ZWE_PRIVATE_DS_SZWEAUTH"); + const loadLib = std.getenv("ZWE_PRIVATE_DS_SZWELOAD"); + const execLib = std.getenv("ZWE_PRIVATE_DS_SZWEEXEC"); + + let customDSList = { + sampLib: { + ds: `${sampLib}`, + name: "Zowe sample library", + spec: "dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks", + overWrite: true + }, + authLib: { + ds: `${authLib}`, + name: "Zowe authorized load library", + spec: "dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks", + overWrite: true + }, + loadLib: { + ds: `${loadLib}`, + name: "Zowe load library", + spec: "dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks", + overWrite: true + }, + execLib: { + ds: `${execLib}`, + name: "Zowe executable utilities library", + spec: "dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks", + overWrite: true + }, + } + + common.printMessage( "Create MVS data sets if they do not exist"); + for (const lib in customDSList){ + const dsExists = zosdataset.isDatasetExists(`${prefix}.${customDSList[lib].ds}`); + if (dsExists){ + if (allowOverwrite) { + common.printMessage(`Warning ZWEL0300W: ${prefix}.${customDSList[lib].ds} already exists. Members in this data set will be overwritten.`); + } else { + common.printMessage(`Warning ZWEL0301W: ${prefix}.${customDSList[lib].ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite.`); + customDSList[lib].overWrite = false; + } + } else { + common.printMessage(`Creating ${customDSList[lib].name} - ${prefix}.${customDSList[lib].ds}"`); + const rc = zosdataset.createDataSet(`${prefix}.${customDSList[lib].ds}`, customDSList[lib].spec); + if (rc){ + common.printErrorAndExit("Error ZWEL0111E: Command aborts with error.", undefined, 111); + } + } + }; + + common.printMessage(""); + + let continueWithCopy = false; + for (const lib in customDSList){ + if (customDSList[lib].overWrite == true) + continueWithCopy = true; + } + + if (!continueWithCopy){ + common.printLevel1Message("Zowe MVS data sets installation skipped."); + } else { + const runtime = std.getenv('ZWE_zowe_runtimeDirectory'); + if (customDSList.sampLib.overWrite) + copyFromDirectory(`${runtime}/files/${sampLib}`, `${prefix}.${sampLib}`, ""); + + if (customDSList.execLib.overWrite) + copyFromDirectory(`${runtime}/files/${execLib}`, `${prefix}.${execLib}`, ""); + + if (customDSList.sampLib.overWrite) + copyFromDirectory(`${runtime}/components/launcher/samplib/ZWESLSTC`, `${prefix}.${sampLib}`, ""); + + if (customDSList.authLib.overWrite) + copyFromDirectory(`${runtime}/components/launcher/bin/zowe_launcher`, `${prefix}.${authLib}(ZWELNCH)`, "-X"); + + if (customDSList.loadLib.overWrite) + copyFromDirectory(`${runtime}/files/${loadLib}`, `${prefix}.${loadLib}`, "-X"); + + const ZSS_SAMPLIB = [ + ['ZWESAUX','ZWESASTC'], + ['ZWESIP00'], + ['ZWESIS01', 'ZWESISTC'], + ['ZWESISCH'] + ]; + ZSS_SAMPLIB.forEach(member => { + const zss_from = member[0]; + const zss_to = member[1] || member[0]; + if (customDSList.sampLib.overWrite) + copyFromDirectory(`${runtime}/components/zss/SAMPLIB/${zss_from}`, `${prefix}.${sampLib}(${zss_to})`, ""); + }) + + if (customDSList.authLib.overWrite) + copyFromDirectory(`${runtime}/components/zss/LOADLIB`, `${prefix}.${authLib}`, "-X"); + } + + common.printLevel1Message("Zowe MVS data sets are installed successfully."); + + common.printMessage("Zowe installation completed. In order to use Zowe, you need to run \"zwe init\" command to initialize Zowe instance."); + common.printMessage("- Type \"zwe init --help\" to get more information.\n\n"); + common.printMessage("You can also run individual init sub-commands: mvs, certificate, security, vsam, apfauth, and stc."); + common.printMessage("- Type \"zwe init --help\" (for example, \"zwe init stc --help\") to get more information.\n\n"); +} diff --git a/bin/libs/zos-dataset.sh b/bin/libs/zos-dataset.sh index 16154681f5..001e7ae722 100644 --- a/bin/libs/zos-dataset.sh +++ b/bin/libs/zos-dataset.sh @@ -75,7 +75,7 @@ copy_to_data_set() { allow_overwrite="${4}" if [ "${allow_overwrite}" != "true" ]; then - if [ "$(is_data_set_exists "//'${ds_name}'")" = "true" ]; then + if [ "$(is_data_set_exists "${ds_name}'")" = "true" ]; then print_error_and_exit "Error ZWEL0133E: Data set ${ds_name} already exists" "" 133 fi fi @@ -105,7 +105,7 @@ data_set_copy_to_data_set() { allow_overwrite="${4}" if [ "${allow_overwrite}" != "true" ]; then - if [ "$(is_data_set_exists "//'${ds_to}'")" = "true" ]; then + if [ "$(is_data_set_exists "${ds_to}'")" = "true" ]; then print_error_and_exit "Error ZWEL0133E: Data set ${ds_to} already exists" "" 133 fi fi diff --git a/bin/libs/zos-dataset.ts b/bin/libs/zos-dataset.ts index c1960ec929..e8a2e4f571 100644 --- a/bin/libs/zos-dataset.ts +++ b/bin/libs/zos-dataset.ts @@ -292,3 +292,28 @@ export function createDatasetTmpMember(dataset: string, prefix: string='ZW'): st } return null; } + +// schema/server-common.json: zoweDataset +// note: the min lenght is 1 +export function validDatasetName(dsn: string): boolean { + common.printTrace(`- validDatasetName for "${dsn}"`); + if (!dsn || dsn.length < 2 || dsn.length > 44) { + common.printTrace(' * dataset null, empty or > 44 chars'); + return false; + } + const result = !!dsn.match(/^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}(\.([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}){0,11}$/g); + common.printTrace(` * regex match: ${result}`); + return result; +} + +// schema/server-common.json: zoweDatasetMember +export function validDatasetMemberName(memberName:string): boolean { + common.printTrace(`- validDatasetMemberName for "${memberName}"`); + if (!memberName){ + common.printTrace(' * no member name'); + return false; + } + const result = !!memberName.match(/^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@]){0,7}$/g); + common.printTrace(` * regex match: ${result}`); + return result; +} From db05562c0df4de81cb3ffa6e0b0d4d22867f7fa9 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 26 Oct 2023 13:49:09 +0200 Subject: [PATCH 02/17] Zwe install typescript Signed-off-by: Martin Zeithaml --- bin/commands/install/index.sh | 128 +++++++++++++++------------------- bin/commands/install/index.ts | 62 +++++++--------- 2 files changed, 82 insertions(+), 108 deletions(-) diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index 1f4e39155b..b730034d1f 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -55,7 +55,6 @@ while read -r line; do ds=$(echo "${line}" | awk -F"|" '{print $1}') name=$(echo "${line}" | awk -F"|" '{print $2}') spec=$(echo "${line}" | awk -F"|" '{print $3}') - typeset "$ds=true" # check existence ds_existence=$(is_data_set_exists "${prefix}.${ds}") if [ "${ds_existence}" = "true" ]; then @@ -64,7 +63,6 @@ while read -r line; do else print_message "Warning ZWEL0301W: ${prefix}.${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite." ds_count=$(( $ds_count + 1 )) - typeset "$ds=false" fi else print_message "Creating ${name} - ${prefix}.${ds}" @@ -80,87 +78,77 @@ EOF print_message if [ "${ds_count}" = "4" ]; then - print_level1_message "Zowe MVS data sets installation skipped." + print_level1_message "Zowe MVS data sets installation skipped. For upgrades, you must use --allow-overwrite." else ############################### # copy members - if [ "${SZWESAMP}" = "true" ]; then - cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWESAMP}" - for mb in $(find . -type f); do - print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" - copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" "" "true" - if [ $? -ne 0 ]; then - print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 - fi - done - fi - - if [ "${SZWEEXEC}" = "true" ]; then - cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWEEXEC}" - for mb in $(find . -type f); do - print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}" - copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}" "" "true" - if [ $? -ne 0 ]; then - print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 - fi - done - fi - - # prepare MVS for launcher - if [ "${SZWESAMP}" = "true" ]; then - cd "${ZWE_zowe_runtimeDirectory}/components/launcher" - print_message "Copy components/launcher/samplib/ZWESLSTC to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" - copy_to_data_set "samplib/ZWESLSTC" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" "" "true" + cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWESAMP}" + for mb in $(find . -type f); do + print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" + copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi - fi - if [ "${SZWEAUTH}" = "true" ]; then - print_message "Copy components/launcher/bin/zowe_launcher to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" - copy_to_data_set "bin/zowe_launcher" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(ZWELNCH)" "-X" "true" + done + + cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWEEXEC}" + for mb in $(find . -type f); do + print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}" + copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}(${mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi + done + + # prepare MVS for launcher + cd "${ZWE_zowe_runtimeDirectory}/components/launcher" + print_message "Copy components/launcher/samplib/ZWESLSTC to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" + copy_to_data_set "samplib/ZWESLSTC" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(ZWESLSTC)" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + if [ $? -ne 0 ]; then + print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 + fi + + print_message "Copy components/launcher/bin/zowe_launcher to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" + copy_to_data_set "bin/zowe_launcher" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(ZWELNCH)" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + if [ $? -ne 0 ]; then + print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi # copy in configmgr rexx edition - if [ "${SZWELOAD}" = "true" ]; then - cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWELOAD}" - for mb in $(find . -type f); do - print_message "Copy files/${ZWE_PRIVATE_DS_SZWELOAD}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}" - copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}" "-X" "true" - if [ $? -ne 0 ]; then - print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 - fi - done - fi + cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWELOAD}" + for mb in $(find . -type f); do + print_message "Copy files/${ZWE_PRIVATE_DS_SZWELOAD}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}" + copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}(${mb})" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + if [ $? -ne 0 ]; then + print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 + fi + done + # FIXME: move these parts to zss commands.install? - if [ "${SZWESAMP}" = "true" ]; then - cd "${ZWE_zowe_runtimeDirectory}/components/zss" - zss_samplib="ZWESAUX=ZWESASTC ZWESIP00 ZWESIS01=ZWESISTC ZWESISCH" - for mb in ${zss_samplib}; do - mb_from=$(echo "${mb}" | awk -F= '{print $1}') - mb_to=$(echo "${mb}" | awk -F= '{print $2}') - if [ -z "${mb_to}" ]; then - mb_to="${mb_from}" - fi - print_message "Copy components/zss/SAMPLIB/${mb_from} to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb_to})" - copy_to_data_set "SAMPLIB/${mb_from}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb_to})" "" "true" - if [ $? -ne 0 ]; then - print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 - fi - done - fi - if [ "${SZWEAUTH}" = "true" ]; then - zss_loadlib="ZWESIS01 ZWESAUX ZWESISDL" - for mb in ${zss_loadlib}; do - print_message "Copy components/zss/LOADLIB/${mb} to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" - copy_to_data_set "LOADLIB/${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" "-X" "true" - if [ $? -ne 0 ]; then - print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 - fi - done - fi + cd "${ZWE_zowe_runtimeDirectory}/components/zss" + zss_samplib="ZWESAUX=ZWESASTC ZWESIP00 ZWESIS01=ZWESISTC ZWESISCH" + for mb in ${zss_samplib}; do + mb_from=$(echo "${mb}" | awk -F= '{print $1}') + mb_to=$(echo "${mb}" | awk -F= '{print $2}') + if [ -z "${mb_to}" ]; then + mb_to="${mb_from}" + fi + print_message "Copy components/zss/SAMPLIB/${mb_from} to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb_to})" + copy_to_data_set "SAMPLIB/${mb_from}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb_to})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + if [ $? -ne 0 ]; then + print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 + fi + done + + zss_loadlib="ZWESIS01 ZWESAUX ZWESISDL" + for mb in ${zss_loadlib}; do + print_message "Copy components/zss/LOADLIB/${mb} to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" + copy_to_data_set "LOADLIB/${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(${mb})" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + if [ $? -ne 0 ]; then + print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 + fi + done + print_message ############################### diff --git a/bin/commands/install/index.ts b/bin/commands/install/index.ts index 537e44f9a1..a467510cbf 100644 --- a/bin/commands/install/index.ts +++ b/bin/commands/install/index.ts @@ -15,7 +15,7 @@ import * as common from '../../libs/common'; import * as fs from '../../libs/fs'; import * as zosdataset from '../../libs/zos-dataset'; -function copyFromDirectory(pathFrom: string, datasetTo: string, copyOptions: string) { +function copyFromDirectory(pathFrom: string, datasetTo: string, copyOptions: string, overWrite: boolean) { const stats = os.stat(pathFrom); if (stats[1]) common.printErrorAndExit("Error ZWEL0104E: Invalid command 'os.stat'", undefined, 104); @@ -24,8 +24,8 @@ function copyFromDirectory(pathFrom: string, datasetTo: string, copyOptions: str const modules = fs.getFilesInDirectory(pathFrom) || []; for (let i = 0; i < modules.length; i++) { const module = modules[i]; - common.printMessage(`Copy ${pathFrom}/${module} to ${datasetTo}`); - const rc = zosdataset.copyToDataset(`${pathFrom}/${module}`, datasetTo, copyOptions, true); + common.printMessage(`Copy ${pathFrom}/${module} to ${datasetTo}/(${module})`); + const rc = zosdataset.copyToDataset(`${pathFrom}/${module}`, `${datasetTo}(${module})`, copyOptions, overWrite); if (rc != 0) { common.printErrorAndExit("Error ZWEL0111E: Command aborts with error.", undefined, 111); } @@ -35,7 +35,7 @@ function copyFromDirectory(pathFrom: string, datasetTo: string, copyOptions: str // Copy specified file from directory if (stats[1] == 0 && ((stats[0].mode & os.S_IFMT) == os.S_IFREG)) { common.printMessage(`Copy ${pathFrom} to ${datasetTo}`); - const rc = zosdataset.copyToDataset(pathFrom, datasetTo, copyOptions, true); + const rc = zosdataset.copyToDataset(pathFrom, datasetTo, copyOptions, overWrite); if (rc != 0) { common.printErrorAndExit("Error ZWEL0111E: Command aborts with error.", undefined, 111); } @@ -50,32 +50,29 @@ export function execute(prefix: string) { const authLib = std.getenv("ZWE_PRIVATE_DS_SZWEAUTH"); const loadLib = std.getenv("ZWE_PRIVATE_DS_SZWELOAD"); const execLib = std.getenv("ZWE_PRIVATE_DS_SZWEEXEC"); - + + let dsSkipped = 0; let customDSList = { sampLib: { ds: `${sampLib}`, name: "Zowe sample library", - spec: "dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks", - overWrite: true + spec: "dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks" }, authLib: { ds: `${authLib}`, name: "Zowe authorized load library", - spec: "dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks", - overWrite: true + spec: "dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks" }, loadLib: { ds: `${loadLib}`, name: "Zowe load library", - spec: "dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks", - overWrite: true + spec: "dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks" }, execLib: { ds: `${execLib}`, name: "Zowe executable utilities library", - spec: "dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks", - overWrite: true - }, + spec: "dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks" + } } common.printMessage( "Create MVS data sets if they do not exist"); @@ -86,7 +83,7 @@ export function execute(prefix: string) { common.printMessage(`Warning ZWEL0300W: ${prefix}.${customDSList[lib].ds} already exists. Members in this data set will be overwritten.`); } else { common.printMessage(`Warning ZWEL0301W: ${prefix}.${customDSList[lib].ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite.`); - customDSList[lib].overWrite = false; + dsSkipped++; } } else { common.printMessage(`Creating ${customDSList[lib].name} - ${prefix}.${customDSList[lib].ds}"`); @@ -97,32 +94,23 @@ export function execute(prefix: string) { } }; - common.printMessage(""); - - let continueWithCopy = false; - for (const lib in customDSList){ - if (customDSList[lib].overWrite == true) - continueWithCopy = true; - } + common.printMessage(''); - if (!continueWithCopy){ - common.printLevel1Message("Zowe MVS data sets installation skipped."); + if (dsSkipped == Object.keys(customDSList).length) { + common.printLevel1Message("Zowe MVS data sets installation skipped. For upgrades, you must use --allow-overwrite."); } else { + const runtime = std.getenv('ZWE_zowe_runtimeDirectory'); - if (customDSList.sampLib.overWrite) - copyFromDirectory(`${runtime}/files/${sampLib}`, `${prefix}.${sampLib}`, ""); + + copyFromDirectory(`${runtime}/files/${sampLib}`, `${prefix}.${sampLib}`, "", allowOverwrite); - if (customDSList.execLib.overWrite) - copyFromDirectory(`${runtime}/files/${execLib}`, `${prefix}.${execLib}`, ""); + copyFromDirectory(`${runtime}/files/${execLib}`, `${prefix}.${execLib}`, "", allowOverwrite); - if (customDSList.sampLib.overWrite) - copyFromDirectory(`${runtime}/components/launcher/samplib/ZWESLSTC`, `${prefix}.${sampLib}`, ""); + copyFromDirectory(`${runtime}/components/launcher/samplib/ZWESLSTC`, `${prefix}.${sampLib}(ZWESLSTC)`, "", allowOverwrite); - if (customDSList.authLib.overWrite) - copyFromDirectory(`${runtime}/components/launcher/bin/zowe_launcher`, `${prefix}.${authLib}(ZWELNCH)`, "-X"); + copyFromDirectory(`${runtime}/components/launcher/bin/zowe_launcher`, `${prefix}.${authLib}(ZWELNCH)`, "-X", allowOverwrite); - if (customDSList.loadLib.overWrite) - copyFromDirectory(`${runtime}/files/${loadLib}`, `${prefix}.${loadLib}`, "-X"); + copyFromDirectory(`${runtime}/files/${loadLib}`, `${prefix}.${loadLib}`, "-X", allowOverwrite); const ZSS_SAMPLIB = [ ['ZWESAUX','ZWESASTC'], @@ -133,12 +121,10 @@ export function execute(prefix: string) { ZSS_SAMPLIB.forEach(member => { const zss_from = member[0]; const zss_to = member[1] || member[0]; - if (customDSList.sampLib.overWrite) - copyFromDirectory(`${runtime}/components/zss/SAMPLIB/${zss_from}`, `${prefix}.${sampLib}(${zss_to})`, ""); + copyFromDirectory(`${runtime}/components/zss/SAMPLIB/${zss_from}`, `${prefix}.${sampLib}(${zss_to})`, "", allowOverwrite); }) + copyFromDirectory(`${runtime}/components/zss/LOADLIB`, `${prefix}.${authLib}`, "-X", allowOverwrite); - if (customDSList.authLib.overWrite) - copyFromDirectory(`${runtime}/components/zss/LOADLIB`, `${prefix}.${authLib}`, "-X"); } common.printLevel1Message("Zowe MVS data sets are installed successfully."); From 3562347cbb416cccf06eb85bf8fa0dd3540c48a1 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 26 Oct 2023 14:30:48 +0200 Subject: [PATCH 03/17] Removing forgotten apostrophe Signed-off-by: Martin Zeithaml --- bin/libs/zos-dataset.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/libs/zos-dataset.sh b/bin/libs/zos-dataset.sh index 001e7ae722..18ebc5fade 100644 --- a/bin/libs/zos-dataset.sh +++ b/bin/libs/zos-dataset.sh @@ -75,7 +75,7 @@ copy_to_data_set() { allow_overwrite="${4}" if [ "${allow_overwrite}" != "true" ]; then - if [ "$(is_data_set_exists "${ds_name}'")" = "true" ]; then + if [ "$(is_data_set_exists "${ds_name}")" = "true" ]; then print_error_and_exit "Error ZWEL0133E: Data set ${ds_name} already exists" "" 133 fi fi @@ -105,7 +105,7 @@ data_set_copy_to_data_set() { allow_overwrite="${4}" if [ "${allow_overwrite}" != "true" ]; then - if [ "$(is_data_set_exists "${ds_to}'")" = "true" ]; then + if [ "$(is_data_set_exists "${ds_to}")" = "true" ]; then print_error_and_exit "Error ZWEL0133E: Data set ${ds_to} already exists" "" 133 fi fi From 0b3d98f4cb9c6f2a01a8c4cae2ee5489a99b0d04 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 27 Oct 2023 14:48:51 +0200 Subject: [PATCH 04/17] Check if ds-prefix is valid Signed-off-by: Martin Zeithaml --- bin/commands/install/index.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index b730034d1f..53d8178b12 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -38,6 +38,10 @@ ${ZWE_PRIVATE_DS_SZWEEXEC}|Zowe executable utilities library|dsntype(library) ds # validation if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then prefix="${ZWE_CLI_PARAMETER_DATASET_PREFIX}" + prefix_validate=$(echo "${prefix}" | grep -E '^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}(\.([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}){0,11}$') + if [ -z "${prefix_validate}" ]; then + print_error_and_exit "Error ZWEL0102E: Invalid parameter --dataset-prefix=\"${prefix}\"." "" 102 + fi else require_zowe_yaml # read prefix and validate From 937354adc187235af8db9b3f112223e6c3b4ed71 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 27 Oct 2023 15:02:25 +0200 Subject: [PATCH 05/17] Missing common lib Signed-off-by: Martin Zeithaml --- bin/commands/install/clix.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/commands/install/clix.js b/bin/commands/install/clix.js index 8fad02d2cd..12af8d3a16 100644 --- a/bin/commands/install/clix.js +++ b/bin/commands/install/clix.js @@ -11,6 +11,7 @@ import * as index from './index'; import * as std from 'cm_std'; +import * as common from '../../libs/common'; import * as zosdataset from '../../libs/zos-dataset'; const prefix = std.getenv("ZWE_CLI_PARAMETER_DATASET_PREFIX"); From 0b0673c3cea851dd201b2482e1f4938b009da007 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 30 Oct 2023 10:09:03 +0100 Subject: [PATCH 06/17] Add member name to target dataset name Signed-off-by: Martin Zeithaml --- bin/commands/install/index.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index 53d8178b12..c3f8f6be72 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -88,8 +88,9 @@ else # copy members cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWESAMP}" for mb in $(find . -type f); do - print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" - copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + base_mb=$(basename ${mb}) + print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP(${base_mb})}" + copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${base_mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi @@ -97,8 +98,9 @@ else cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWEEXEC}" for mb in $(find . -type f); do - print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}" - copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}(${mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + base_mb=$(basename ${mb}) + print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC(${base_mb})}" + copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}(${base_mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi @@ -106,13 +108,13 @@ else # prepare MVS for launcher cd "${ZWE_zowe_runtimeDirectory}/components/launcher" - print_message "Copy components/launcher/samplib/ZWESLSTC to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" + print_message "Copy components/launcher/samplib/ZWESLSTC to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(ZWESLSTC)" copy_to_data_set "samplib/ZWESLSTC" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(ZWESLSTC)" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi - print_message "Copy components/launcher/bin/zowe_launcher to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" + print_message "Copy components/launcher/bin/zowe_launcher to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(ZWELNCH)" copy_to_data_set "bin/zowe_launcher" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(ZWELNCH)" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 @@ -121,8 +123,9 @@ else # copy in configmgr rexx edition cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWELOAD}" for mb in $(find . -type f); do - print_message "Copy files/${ZWE_PRIVATE_DS_SZWELOAD}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}" - copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}(${mb})" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" + base_mb=$(basename ${mb}) + print_message "Copy files/${ZWE_PRIVATE_DS_SZWELOAD}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}(${base_mb})" + copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}(${base_mb})" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 fi @@ -146,7 +149,7 @@ else zss_loadlib="ZWESIS01 ZWESAUX ZWESISDL" for mb in ${zss_loadlib}; do - print_message "Copy components/zss/LOADLIB/${mb} to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" + print_message "Copy components/zss/LOADLIB/${mb} to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(${mb})" copy_to_data_set "LOADLIB/${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(${mb})" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 From 3b01df1e8cd0347bb3c64f14903651b4695183d1 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 30 Oct 2023 10:44:35 +0100 Subject: [PATCH 07/17] Unbalanced curly brackets Signed-off-by: Martin Zeithaml --- bin/commands/install/index.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index c3f8f6be72..d40ccf0ba5 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -89,7 +89,7 @@ else cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWESAMP}" for mb in $(find . -type f); do base_mb=$(basename ${mb}) - print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP(${base_mb})}" + print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${base_mb})" copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${base_mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 @@ -99,7 +99,7 @@ else cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWEEXEC}" for mb in $(find . -type f); do base_mb=$(basename ${mb}) - print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC(${base_mb})}" + print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/(${base_mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}(${base_mb})" copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}(${base_mb})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" if [ $? -ne 0 ]; then print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111 From efbffc0d21548c2c257d36c5d0ed5e5392a4dc52 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 30 Oct 2023 13:33:42 +0100 Subject: [PATCH 08/17] Missing semicolon Signed-off-by: Martin Zeithaml --- bin/commands/install/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/commands/install/index.ts b/bin/commands/install/index.ts index a467510cbf..f05d127ad5 100644 --- a/bin/commands/install/index.ts +++ b/bin/commands/install/index.ts @@ -10,7 +10,7 @@ */ import * as std from 'cm_std'; -import * as os from 'cm_os' +import * as os from 'cm_os'; import * as common from '../../libs/common'; import * as fs from '../../libs/fs'; import * as zosdataset from '../../libs/zos-dataset'; @@ -92,7 +92,7 @@ export function execute(prefix: string) { common.printErrorAndExit("Error ZWEL0111E: Command aborts with error.", undefined, 111); } } - }; + } common.printMessage(''); From 109b54e2c037a098f32edbc98a65958197677a94 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Wed, 1 Nov 2023 15:01:02 +0100 Subject: [PATCH 09/17] Bypass playbook run_zwe Signed-off-by: Martin Zeithaml --- example-zowe.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example-zowe.yaml b/example-zowe.yaml index e82479c0dd..0a9d720781 100644 --- a/example-zowe.yaml +++ b/example-zowe.yaml @@ -273,7 +273,7 @@ zowe: # runtime where the "zwe" command is located. # # This value is required by ZWESLSTC to know where is Zowe runtime. - runtimeDirectory: "" + runtimeDirectory: " " # **COMMONLY_CUSTOMIZED** # Where to store runtime logs @@ -437,7 +437,7 @@ zowe: java: # **COMMONLY_CUSTOMIZED** # Path to your Java home directory - home: "" + home: " " #------------------------------------------------------------------------------- @@ -452,7 +452,7 @@ java: node: # **COMMONLY_CUSTOMIZED** # Path to your node.js home directory - home: "" + home: " " #------------------------------------------------------------------------------- From 48be3540b0fefb6ab415d6c36c08e8ff5d518de8 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 3 Nov 2023 08:18:10 +0100 Subject: [PATCH 10/17] Upper case --ds-prefix Signed-off-by: Martin Zeithaml --- bin/commands/install/clix.js | 2 +- bin/commands/install/index.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/commands/install/clix.js b/bin/commands/install/clix.js index 12af8d3a16..2fe4f573bb 100644 --- a/bin/commands/install/clix.js +++ b/bin/commands/install/clix.js @@ -15,7 +15,7 @@ import * as common from '../../libs/common'; import * as zosdataset from '../../libs/zos-dataset'; const prefix = std.getenv("ZWE_CLI_PARAMETER_DATASET_PREFIX"); -if (!prefix || !zosdataset.validDatasetName(prefix)){ +if (!prefix || !zosdataset.validDatasetName(prefix.toUpperCase())) { common.printLevel1Message("Install Zowe MVS data sets"); common.printErrorAndExit(`Error ZWEL0102E: Invalid parameter --dataset-prefix="${prefix}".`, undefined, 102); } diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index d40ccf0ba5..22183869fe 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -13,7 +13,7 @@ USE_CONFIGMGR=$(check_configmgr_enabled) if [ "${USE_CONFIGMGR}" = "true" ]; then - if [ -z "${ZWE_CLI_PARAMETER_CONFIG}" ]; then + if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then _CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/clix.js" else if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then @@ -38,7 +38,7 @@ ${ZWE_PRIVATE_DS_SZWEEXEC}|Zowe executable utilities library|dsntype(library) ds # validation if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then prefix="${ZWE_CLI_PARAMETER_DATASET_PREFIX}" - prefix_validate=$(echo "${prefix}" | grep -E '^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}(\.([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}){0,11}$') + prefix_validate=$(echo "${prefix}" | tr '[:lower:]' '[:upper:]' | grep -E '^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}(\.([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}){0,11}$') if [ -z "${prefix_validate}" ]; then print_error_and_exit "Error ZWEL0102E: Invalid parameter --dataset-prefix=\"${prefix}\"." "" 102 fi From a508217a771f5b241d4e7493335fad6081cc2e12 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 3 Nov 2023 12:25:54 +0100 Subject: [PATCH 11/17] tsocmd parm with apostrophes Signed-off-by: Martin Zeithaml --- bin/libs/zos-dataset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/libs/zos-dataset.ts b/bin/libs/zos-dataset.ts index e8a2e4f571..a950564ccc 100644 --- a/bin/libs/zos-dataset.ts +++ b/bin/libs/zos-dataset.ts @@ -44,7 +44,7 @@ export function tsoIsDatasetExists(datasetName: string): number { } export function createDataSet(dsName: string, dsOptions: string): number { - const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${dsName}') ${dsOptions}`); + const result=zoslib.tsoCommand(`"ALLOCATE NEW DA('${dsName}') ${dsOptions}"`); return result.rc; } From 9ccaba759a015d338c1e970b25a47f3333f88a0d Mon Sep 17 00:00:00 2001 From: Martin Zeithaml <66114686+Martin-Zeithaml@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:27:44 +0100 Subject: [PATCH 12/17] Update zos-dataset.ts Min length for dataset is 1. Signed-off-by: Martin Zeithaml <66114686+Martin-Zeithaml@users.noreply.github.com> --- bin/libs/zos-dataset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/libs/zos-dataset.ts b/bin/libs/zos-dataset.ts index a950564ccc..447330f589 100644 --- a/bin/libs/zos-dataset.ts +++ b/bin/libs/zos-dataset.ts @@ -297,7 +297,7 @@ export function createDatasetTmpMember(dataset: string, prefix: string='ZW'): st // note: the min lenght is 1 export function validDatasetName(dsn: string): boolean { common.printTrace(`- validDatasetName for "${dsn}"`); - if (!dsn || dsn.length < 2 || dsn.length > 44) { + if (!dsn || dsn.length < 1 || dsn.length > 44) { common.printTrace(' * dataset null, empty or > 44 chars'); return false; } From be11ee20d9c5d465f9bf10b0bcb44632ecdfd106 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 6 Nov 2023 12:18:18 +0100 Subject: [PATCH 13/17] zwe parms processing update Signed-off-by: Martin Zeithaml --- bin/zwe | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/zwe b/bin/zwe index baaf43bb9d..31f3dcb4b2 100755 --- a/bin/zwe +++ b/bin/zwe @@ -63,6 +63,9 @@ while [ $# -gt 0 ]; do zwecli_set_parameter_value "${param_id}" "true" elif [ "${param_type}" = "s" -o "${param_type}" = "str" -o "${param_type}" = "string" ]; then shift + if [ -z "${1}" ]; then + print_error_and_exit "Error ZWEL0106E: Value for '${arg}' parameter is required." "" 106 + fi ZWE_CLI_PARAMETERS_LIST="$(trim "${ZWE_CLI_PARAMETERS_LIST} ${param_id}")" zwecli_set_parameter_value "${param_id}" "${1}" else From cde40d7eeb5b9814a793fd405b40d938ce1ec33d Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 6 Nov 2023 13:37:10 +0100 Subject: [PATCH 14/17] Entire tso command enclosed in double apostrophes Signed-off-by: Martin Zeithaml --- bin/libs/zos-dataset.ts | 2 +- bin/libs/zos.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/libs/zos-dataset.ts b/bin/libs/zos-dataset.ts index 447330f589..d2728efba2 100644 --- a/bin/libs/zos-dataset.ts +++ b/bin/libs/zos-dataset.ts @@ -44,7 +44,7 @@ export function tsoIsDatasetExists(datasetName: string): number { } export function createDataSet(dsName: string, dsOptions: string): number { - const result=zoslib.tsoCommand(`"ALLOCATE NEW DA('${dsName}') ${dsOptions}"`); + const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${dsName}') ${dsOptions}`); return result.rc; } diff --git a/bin/libs/zos.ts b/bin/libs/zos.ts index b49e81451b..8cc5dea000 100644 --- a/bin/libs/zos.ts +++ b/bin/libs/zos.ts @@ -16,7 +16,7 @@ import * as shell from './shell'; import * as stringlib from './string'; export function tsoCommand(...args:string[]): { rc: number, out: string } { - let message="tsocmd "+args.join(' '); + let message = "tsocmd " + '"' + args.join(' ') + '"'; common.printDebug('- '+message); //we echo at the end to avoid a configmgr quirk where trying to read stdout when empty can hang waiting for bytes const result = shell.execOutSync('sh', '-c', `${message} 2>&1 && echo '.'`); From 1cc069f6a0f6cc7f77b218fb5610d61e07ec5847 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Wed, 8 Nov 2023 13:31:10 +0100 Subject: [PATCH 15/17] Dollar sign care Signed-off-by: Martin Zeithaml --- bin/libs/configmgr.ts | 4 +++- bin/libs/string.ts | 12 ++++++++++++ bin/libs/zos-dataset.ts | 16 ++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/bin/libs/configmgr.ts b/bin/libs/configmgr.ts index 03863f3d7a..d440c1ebdb 100644 --- a/bin/libs/configmgr.ts +++ b/bin/libs/configmgr.ts @@ -14,6 +14,7 @@ import * as os from 'cm_os'; import * as xplatform from 'xplatform'; import { ConfigManager } from 'Configuration'; import * as fs from './fs'; +import * as stringlib from './string'; import * as objUtils from '../utils/ObjUtils'; @@ -413,7 +414,8 @@ function getMemberNameFromConfigPath(configPath: string): string|undefined { function stripMemberName(configPath: string, memberName: string): string { //Turn PARMLIB(my.zowe(yaml)):PARMLIB(my.other.zowe(yaml)) //Into PARMLIB(my.zowe):FILE(/some/path.yaml):PARMLIB(my.other.zowe) - const replacer = new RegExp('\\('+memberName+'\\)\\)', 'gi'); + //$ is valid char for member name, escape it for RegExp + const replacer = new RegExp('\\('+stringlib.escapeRegExp(memberName)+'\\)\\)', 'gi'); return configPath.replace(replacer, ")"); } diff --git a/bin/libs/string.ts b/bin/libs/string.ts index 7fa5c6020f..e67d9b8f0a 100644 --- a/bin/libs/string.ts +++ b/bin/libs/string.ts @@ -208,6 +208,18 @@ export function trim(input: string): string { return input.trim(); } +export function escapeDollar(str: string): string | undefined { + if (str === null || str === undefined) + return undefined; + return str.replace(/[$]/g, '\\$&'); +} + +export function escapeRegExp(str: string): string | undefined { + if (str === null || str === undefined) + return undefined; + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} + // Replace all occurrences of a string with another export function replace(sourceString: string, searchTerm: string, replaceTerm: string): string { const all = new RegExp(searchTerm, 'g') diff --git a/bin/libs/zos-dataset.ts b/bin/libs/zos-dataset.ts index d2728efba2..46728a37ac 100644 --- a/bin/libs/zos-dataset.ts +++ b/bin/libs/zos-dataset.ts @@ -18,7 +18,7 @@ import * as shell from './shell'; import * as zoslib from './zos'; export function isDatasetExists(datasetName: string): boolean { - const result = shell.execSync('sh', '-c', `cat "//'${datasetName}'" 1>/dev/null 2>&1`); + const result = shell.execSync('sh', '-c', `cat "//'${stringlib.escapeDollar(datasetName)}'" 1>/dev/null 2>&1`); return result.rc === 0; } @@ -27,7 +27,7 @@ export function isDatasetExists(datasetName: string): boolean { // 1: data set is not in catalog // 2: data set member doesn't exist export function tsoIsDatasetExists(datasetName: string): number { - const result = zoslib.tsoCommand(`listds '${datasetName}' label`); + const result = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(datasetName)}' label`); if (result.rc != 0) { if (result.out.includes('NOT IN CATALOG')) { return 1; @@ -44,7 +44,7 @@ export function tsoIsDatasetExists(datasetName: string): number { } export function createDataSet(dsName: string, dsOptions: string): number { - const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${dsName}') ${dsOptions}`); + const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${stringlib.escapeDollar(dsName)}') ${dsOptions}`); return result.rc; } @@ -55,7 +55,7 @@ export function copyToDataset(filePath: string, dsName: string, cpOptions: strin } } - const cpCommand=`cp ${cpOptions} -v "${filePath}" "//'${dsName}'"`; + const cpCommand=`cp ${cpOptions} -v "${filePath}" "//'${stringlib.escapeDollar(dsName)}'"`; common.printDebug('- '+cpCommand); const result=shell.execOutSync('sh', '-c', `${cpCommand} 2>&1`); if (result.rc == 0) { @@ -79,7 +79,7 @@ export function datasetCopyToDataset(prefix: string, datasetFrom: string, datase } } - const cmd=`exec '${prefix}.${std.getenv('ZWE_PRIVATE_DS_SZWEEXEC')}(ZWEMCOPY)' '${datasetFrom} ${datasetTo}'`; + const cmd=`exec '${prefix}.${std.getenv('ZWE_PRIVATE_DS_SZWEEXEC')}(ZWEMCOPY)' '${stringlib.escapeDollar(datasetFrom)} ${stringlib.escapeDollar(datasetTo)}'`; const result = zoslib.tsoCommand(cmd); return result.rc; } @@ -128,7 +128,7 @@ export function listDatasetUser(datasetName: string): number { // 3: data set is in use // @output tso listds label output export function deleteDataset(dataset: string): number { - const cmd=`delete '${dataset}'`; + const cmd=`delete '${stringlib.escapeDollar(dataset)}'`; const result=zoslib.tsoCommand(cmd); if (result.rc != 0) { if (result.out.includes('NOT IN CATALOG')) { @@ -170,7 +170,7 @@ export function isDatasetSmsManaged(dataset: string): { rc: number, smsManaged?: // SMS flag is in `FORMAT 1 DSCB` section second line, after 780037 common.printTrace(`- Check if ${dataset} is SMS managed`); - const labelResult = zoslib.tsoCommand(`listds '${dataset}' label`); + const labelResult = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(dataset)}' label`); const datasetLabel=labelResult.out; if (labelResult.rc == 0) { let formatIndex = datasetLabel.indexOf('--FORMAT 1 DSCB--'); @@ -212,7 +212,7 @@ export function isDatasetSmsManaged(dataset: string): { rc: number, smsManaged?: export function getDatasetVolume(dataset: string): { rc: number, volume?: string } { common.printTrace(`- Find volume of data set ${dataset}`); - const result = zoslib.tsoCommand(`listds '${dataset}'`); + const result = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(dataset)}'`); if (result.rc == 0) { let volumesIndex = result.out.indexOf('--VOLUMES--'); let volume: string; From 82f3011cbcee98ac273731de637456a32e9084bc Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 9 Nov 2023 15:21:20 +0100 Subject: [PATCH 16/17] Use shift only if there is arg Signed-off-by: Martin Zeithaml --- bin/zwe | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/zwe b/bin/zwe index 31f3dcb4b2..80e6247115 100755 --- a/bin/zwe +++ b/bin/zwe @@ -63,16 +63,15 @@ while [ $# -gt 0 ]; do zwecli_set_parameter_value "${param_id}" "true" elif [ "${param_type}" = "s" -o "${param_type}" = "str" -o "${param_type}" = "string" ]; then shift - if [ -z "${1}" ]; then - print_error_and_exit "Error ZWEL0106E: Value for '${arg}' parameter is required." "" 106 - fi ZWE_CLI_PARAMETERS_LIST="$(trim "${ZWE_CLI_PARAMETERS_LIST} ${param_id}")" zwecli_set_parameter_value "${param_id}" "${1}" else print_error_and_exit "Error ZWEL0103E: Invalid type of parameter ${arg}" "" 103 fi fi - shift + if [ $# -gt 0 ]; then + shift + fi done # debug results From 3a75e3a1f82a5ba74a6699af6d22d8710ca29f1b Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Tue, 14 Nov 2023 16:47:25 +0100 Subject: [PATCH 17/17] Test zowe variables for set/unset Signed-off-by: Martin Zeithaml --- bin/commands/install/index.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/commands/install/index.sh b/bin/commands/install/index.sh index 22183869fe..84dad5ecb2 100644 --- a/bin/commands/install/index.sh +++ b/bin/commands/install/index.sh @@ -13,14 +13,21 @@ USE_CONFIGMGR=$(check_configmgr_enabled) if [ "${USE_CONFIGMGR}" = "true" ]; then - if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then + # zwe command allows to use parameter without value: + # zwe install --ds-prefix ---> ZWE_CLI_PARAMETER_DATASET_PREFIX="" + # To go thru "DS Prefix" code, we have to use test -n ${var+foo} + if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX+foo}" ]; then _CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/clix.js" else if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then # user-facing command, use tmpdir to not mess up workspace permissions export ZWE_PRIVATE_TMP_MERGED_YAML_DIR=1 fi - _CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/cli.js" + if [ -n "${ZWE_CLI_PARAMETER_CONFIG}" ]; then + _CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/cli.js" + else + print_error_and_exit "Error ZWEL0108E: Zowe YAML config file is required." "" 108 + fi fi else @@ -36,7 +43,7 @@ ${ZWE_PRIVATE_DS_SZWEEXEC}|Zowe executable utilities library|dsntype(library) ds ############################### # validation -if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then +if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX+foo}" ]; then prefix="${ZWE_CLI_PARAMETER_DATASET_PREFIX}" prefix_validate=$(echo "${prefix}" | tr '[:lower:]' '[:upper:]' | grep -E '^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}(\.([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}){0,11}$') if [ -z "${prefix_validate}" ]; then