Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zwe install typescript version [DO NOT MERGE] #3635

Open
wants to merge 19 commits into
base: v2.x/staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/commands/install/.examples
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
zwe install -v -c /path/to/zowe.yaml
zwe install --dataset-prefix USER.ZOWE
9 changes: 8 additions & 1 deletion bin/commands/install/.help
Original file line number Diff line number Diff line change
Expand Up @@ -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.
26 changes: 26 additions & 0 deletions bin/commands/install/cli.js
Original file line number Diff line number Diff line change
@@ -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();
23 changes: 23 additions & 0 deletions bin/commands/install/clix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
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 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.toUpperCase())) {
common.printLevel1Message("Install Zowe MVS data sets");
common.printErrorAndExit(`Error ZWEL0102E: Invalid parameter --dataset-prefix="${prefix}".`, undefined, 102);
}

index.execute(prefix);
74 changes: 51 additions & 23 deletions bin/commands/install/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
# Copyright Contributors to the Zowe Project.
#######################################################################

USE_CONFIGMGR=$(check_configmgr_enabled)
if [ "${USE_CONFIGMGR}" = "true" ]; 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
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

print_level0_message "Install Zowe MVS data sets"

###############################
Expand All @@ -23,11 +43,14 @@ ${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
print_error_and_exit "Error ZWEL0102E: Invalid parameter --dataset-prefix=\"${prefix}\"." "" 102
fi
else
require_zowe_yaml

# read prefix and validate
prefix=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.prefix")
if [ -z "${prefix}" ]; then
Expand All @@ -38,21 +61,19 @@ 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}')

# 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 ))
fi
else
print_message "Creating ${name} - ${prefix}.${ds}"
Expand All @@ -64,39 +85,43 @@ while read -r line; do
done <<EOF
$(echo "${cust_ds_list}")
EOF

print_message

if [ "${ds_existence}" = "true" ] && [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" != "true" ]; then
print_level1_message "Zowe MVS data sets installation skipped."
if [ "${ds_count}" = "4" ]; then
print_level1_message "Zowe MVS data sets installation skipped. For upgrades, you must use --allow-overwrite."
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}" "" "${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
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}" "" "${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
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}" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
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
Expand All @@ -105,15 +130,15 @@ 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}" "" "${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
done

# FIXME: move these parts to zss commands.install?
# FIXME: ZWESIPRG is in zowe-install-packaging
cd "${ZWE_zowe_runtimeDirectory}/components/zss"
zss_samplib="ZWESAUX=ZWESASTC ZWESIP00 ZWESIS01=ZWESISTC ZWESISCH"
for mb in ${zss_samplib}; do
Expand All @@ -128,25 +153,28 @@ else
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}" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
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
fi
done

print_message

###############################
# exit message
print_level1_message "Zowe MVS data sets are installed successfully."
fi


print_message "Zowe installation completed. In order to use Zowe, you need to run \"zwe init\" command to initialize Zowe instance."
print_message "- Type \"zwe init --help\" to get more information."
print_message
print_message "You can also run individual init sub-commands: mvs, certificate, security, vsam, apfauth, and stc."
print_message "- Type \"zwe init <sub-command> --help\" (for example, \"zwe init stc --help\") to get more information."
print_message

fi
136 changes: 136 additions & 0 deletions bin/commands/install/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
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, overWrite: boolean) {
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}/(${module})`);
const rc = zosdataset.copyToDataset(`${pathFrom}/${module}`, `${datasetTo}(${module})`, copyOptions, overWrite);
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, overWrite);
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 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"
},
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"
},
loadLib: {
ds: `${loadLib}`,
name: "Zowe load library",
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"
}
}

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.`);
dsSkipped++;
}
} 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('');

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');

copyFromDirectory(`${runtime}/files/${sampLib}`, `${prefix}.${sampLib}`, "", allowOverwrite);

copyFromDirectory(`${runtime}/files/${execLib}`, `${prefix}.${execLib}`, "", allowOverwrite);

copyFromDirectory(`${runtime}/components/launcher/samplib/ZWESLSTC`, `${prefix}.${sampLib}(ZWESLSTC)`, "", allowOverwrite);

copyFromDirectory(`${runtime}/components/launcher/bin/zowe_launcher`, `${prefix}.${authLib}(ZWELNCH)`, "-X", allowOverwrite);

copyFromDirectory(`${runtime}/files/${loadLib}`, `${prefix}.${loadLib}`, "-X", allowOverwrite);

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];
copyFromDirectory(`${runtime}/components/zss/SAMPLIB/${zss_from}`, `${prefix}.${sampLib}(${zss_to})`, "", allowOverwrite);
})
copyFromDirectory(`${runtime}/components/zss/LOADLIB`, `${prefix}.${authLib}`, "-X", allowOverwrite);

}

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 <sub-command> --help\" (for example, \"zwe init stc --help\") to get more information.\n\n");
}
Loading
Loading