#!/bin/env bash show_help() { echo "Usage: $(basename $0) [--version|-v] [--help|h]" echo "Options:" echo " --help | -h (Optional) Display help information on how to use this script" echo " --version | -v (Required) GP's version" echo " --install-dir | -d (Required) Installation directory" echo " --customer | -c (Required) Customer name" echo " --no-download | -no-dl (Optional) Specify this if you already have the packages downloaded" } VERSION="" INSTALL_DIR="" CUSTOMER="" SHOULD_DOWNLOAD=true while [ "$#" -gt 0 ]; do case "$1" in --help | -h) show_help exit ;; --version | -v) VERSION="$2" shift 2 ;; --install-dir | -d) INSTALL_DIR="$2" shift 2 ;; --customer | -c) CUSTOMER="$2" shift 2 ;; --no-download | -no-dl) SHOULD_DOWNLOAD=false shift ;; *) shift ;; esac done if [ -z "$VERSION" ]; then echo 'Please inform a version with --version or -v' exit 1 fi if [ -z "$INSTALL_DIR" ]; then echo 'Please inform a installation directory with --install-dir or -d' exit 1 fi if [ -z "$CUSTOMER" ]; then echo 'Please inform a customer with --customer or -c' exit 1 fi if $SHOULD_DOWNLOAD; then commands_to_check=(wget) commands_not_found=() for command in ${commands_to_check[@]}; do if ! command -v "$command" &>/dev/null; then commands_not_found+=("$command") fi done if [ ${#commands_not_found[@]} -ne 0 ]; then echo 'The following commands are necessary in order to run the script, but were not found:' for command in ${commands_not_found[@]}; do echo " \"$command\"" done exit 1 fi fi ROOT_DIR=$(pwd) if [ $(basename $ROOT_DIR) != "$INSTALL_DIR" ]; then mkdir --parents $INSTALL_DIR cd $INSTALL_DIR ROOT_DIR=$(pwd) fi validate_dir() { DIR="$1" MESSAGE="$2" if [ -z "$DIR" ]; then echo "$MESSAGE" exit 0 fi if [ ! -d "$DIR" ]; then echo "The provided directory '$DIR' does not exist" exit 0 fi } get_version_type_from_version() { version=$1 if [[ $version == *"-"* ]]; then echo 'snapshot' else echo 'release' fi } get_artifactory_repo() { version=$1 case $(get_version_type_from_version $version) in 'snapshot') echo 'oss-package-dev' ;; 'release') echo 'oss-package-rel' ;; *) echo "[ERROR] Função \"$FUNCNAME\" recebeu um retorno inválido" ;; esac } chmod_sh_files_recursively() { DIRPATH=$1 find $DIRPATH -type f -name '*.sh' -exec chmod +x {} \; } ARTIFACTORY_REPOSITORY=$(get_artifactory_repo "$VERSION") DBMANAGER_PACKAGE_WILDCARD="$ARTIFACTORY_REPOSITORY/gp/$VERSION/package/cpqd-dbmanager-etics-package-*bin.zip" DBMANAGER_PACKAGE_ARTIFACTORY_PATH=$(jf rt search --fail-no-op=true --sort-by=path "${DBMANAGER_PACKAGE_WILDCARD}" | jq -r '.[].path') if [ -z "$DBMANAGER_PACKAGE_ARTIFACTORY_PATH" ]; then echo "Could not find DBManager's package file" exit 1 fi DBMANAGER_CUSTOMER_PACKAGE_WILDCARD="$ARTIFACTORY_REPOSITORY/gp/$VERSION/customer/$CUSTOMER/cpqd-dbmanager-customer-$CUSTOMER-*-bin.zip" DBMANAGER_CUSTOMER_PACKAGE_ARTIFACTORY_PATH=$(jf rt search --fail-no-op=true --sort-by=path "${DBMANAGER_CUSTOMER_PACKAGE_WILDCARD}" | jq -r '.[].path') if [ -z "$DBMANAGER_CUSTOMER_PACKAGE_ARTIFACTORY_PATH" ]; then echo "Could not find DBManager's customer package file" echo "Did you inform a valid customer?" exit 1 fi if $SHOULD_DOWNLOAD; then ARTIFACTORY_BASE_URL="https://artifactory.cpqd.com.br/artifactory" wget $ARTIFACTORY_BASE_URL/$DBMANAGER_PACKAGE_ARTIFACTORY_PATH wget $ARTIFACTORY_BASE_URL/$DBMANAGER_CUSTOMER_PACKAGE_ARTIFACTORY_PATH fi DBMANAGER_PACKAGE_FILENAME=$(basename $DBMANAGER_PACKAGE_ARTIFACTORY_PATH) DBMANAGER_CUSTOMER_PACKAGE_FILENAME=$(basename $DBMANAGER_CUSTOMER_PACKAGE_ARTIFACTORY_PATH) unzip -qq $DBMANAGER_PACKAGE_FILENAME unzip -qq -o $DBMANAGER_CUSTOMER_PACKAGE_FILENAME