From 38bd2452851438d3226ea42fa1e0d9ec2c5ea7b6 Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Thu, 25 Jul 2024 14:27:21 -0300 Subject: [PATCH] Refactor and identation fix for install gp script --- scripts/shell/job/gp/install-gp.sh | 320 ++++++++++++++++------------- 1 file changed, 180 insertions(+), 140 deletions(-) diff --git a/scripts/shell/job/gp/install-gp.sh b/scripts/shell/job/gp/install-gp.sh index 16d62d3..aff53fe 100755 --- a/scripts/shell/job/gp/install-gp.sh +++ b/scripts/shell/job/gp/install-gp.sh @@ -1,14 +1,15 @@ #!/bin/bash +set -e show_help() { - echo "Usage: `basename $0` [--files|-f files]" - echo "Options:" - echo " --help | -h (Optional) Display help information on how to use this script" - echo " --version | --version (Required) Specify the GP version to install" - echo " --no-download true | --no-dl true (Optional) Make the script not download the files from Artifactory" - echo " --no-webmap true | --no-wm true (Optional) Make the script not install the WebMap module" - echo " --no-gp true | --no-gp true (Optional) Make the script not install GP" - echo " --install-apache true (Optional) Make the script install the Apache dependency for WebMap module" + echo "Usage: `basename $0` [--files|-f files]" + echo "Options:" + echo " --help | -h (Optional) Display help information on how to use this script" + echo " --version | --version (Required) Specify the GP version to install" + echo " --no-download true | --no-dl (Optional) Make the script not download the files from Artifactory" + echo " --no-webmap true | --no-wm (Optional) Make the script not install the WebMap module" + echo " --no-gp true | --no-gp (Optional) Make the script not install GP" + echo " --install-apache true (Optional) Make the script install the Apache dependency for WebMap module" } version='' @@ -18,76 +19,94 @@ should_install_apache=false should_install_gp=true while [ "$#" -gt 0 ]; do - case "$1" in - --help|-h) show_help; exit ;; - --version|-v) version="$2"; shift 2;; - --no-download|--no-dl) should_download=false; shift 2;; - --no-webmap|--no-wm) should_install_webmap=false; shift 2;; - --no-gp|--no-gp) should_install_gp=false; shift 2;; - --install-apache) should_install_apache=true; shift 2;; - *) shift ;; - esac + case "$1" in + --help | -h) + show_help + exit + ;; + --version | -v) + version="$2" + shift 2 + ;; + --no-download | --no-dl) + should_download=false + shift + ;; + --no-webmap | --no-wm) + should_install_webmap=false + shift + ;; + --no-gp | --no-gp) + should_install_gp=false + shift + ;; + --install-apache) + should_install_apache=true + shift + ;; + *) shift ;; + esac done if [ -z "$version" ]; then - echo "You must specify the package version!" - echo "Example: `basename "$0"` --version 12.0.0.0.0-SNAPSHOT" - exit 1 + echo "You must specify the package version!" + echo "Example: $(basename "$0") --version 12.0.0.0.0-SNAPSHOT" + exit 1 fi -root_dir=`pwd` +root_dir=$(pwd) -if [ `basename $root_dir` != "$version" ]; then - mkdir --parents $version - cd $version - # sudo rm -rf * - root_dir=`pwd` +if [ $(basename $root_dir) != "$version" ]; then + mkdir --parents $version + cd $version + # sudo rm -rf * + root_dir=$(pwd) fi scripts_folder=$HOME/repos/personal/personal-devboot/scripts/shell/job/gp if [ ! -d "$scripts_folder" ]; then - echo "The git repository \"CloudAlb/personal-devboot\" must be in the \"~/repos\" folder!" - exit 1 -fi + echo "The git repository \"CloudAlb/personal-devboot\" must be in the \"~/repos\" folder!" + exit 1 +fi validate_repo_script() { - script_filename=$1 + script_filename=$1 - if [ ! -f "$scripts_folder/$script_filename" ];then - echo "The git repository \"CloudAlb/personal-devboot\" must have the script \"scripts/shell/job/gp/$script_filename\"!" - exit 1 - fi + if [ ! -f "$scripts_folder/$script_filename" ]; then + echo "The git repository \"CloudAlb/personal-devboot\" must have the script \"scripts/shell/job/gp/$script_filename\"!" + exit 1 + fi } get_version_type() { - version=$1 + version=$1 - if [[ $version == *"-SNAPSHOT" ]];then - echo 'snapshot' - else - echo 'release' - fi + if [[ $version == *"-"* ]]; then + echo 'snapshot' + else + echo 'release' + fi } get_maven_repo() { - version=$1 + version=$1 - case `get_version_type $version` in - 'snapshot') echo 'cpqd-snapshot' ;; - 'release') echo 'cpqd-release' ;; - *) echo "[ERROR] Função \"$FUNCNAME\" recebeu um retorno inválido" ;; - esac + case $(get_version_type $version) in + 'snapshot') echo 'cpqd-snapshot' ;; + 'release') echo 'cpqd-release' ;; + *) echo "[ERROR] Função \"$FUNCNAME\" recebeu um retorno inválido" ;; + esac } get_artifactory_repo() { - version=$1 + version=$1 - case `get_version_type $version` in - 'snapshot') echo 'oss-package-dev' ;; - 'release') echo 'oss-package-rel' ;; - *) echo "[ERROR] Função \"$FUNCNAME\" recebeu um retorno inválido" ;; - esac + case $(get_version_type $version) in + 'snapshot') echo 'oss-package-dev' ;; + 'release') echo 'oss-package-rel' ;; + *) echo "[ERROR] Função \"$FUNCNAME\" recebeu um retorno inválido" ;; + esac } script_explode_java_files_filename='explode-java-files.sh' @@ -96,139 +115,160 @@ validate_repo_script $script_explode_java_files_filename script_disable_dbversion_check_filename='disable-dbversion-check-on-software-info-file.sh' validate_repo_script $script_disable_dbversion_check_filename -root_dir=`pwd` - # download files base_url='artifactory.cpqd.com.br/artifactory' -gp_maven_repo=`get_maven_repo $version` -gp_artifactory_repo=`get_artifactory_repo $version` +gp_maven_repo=$(get_maven_repo $version) +gp_artifactory_repo=$(get_artifactory_repo $version) if $should_download; then - if [[ $root_dir != *$version ]]; then - mkdir $version - cd $version - root_dir=`pwd` + if [[ $root_dir != *$version ]]; then + mkdir $version + cd $version + root_dir=$(pwd) + fi + + all_files=($(jf rt search --fail-no-op=true --sort-by=path "${gp_artifactory_repo}/gp/${version}/*" | jq -r '.[].path')) + + if [ -z "$all_files" ]; then + echo '[ERROR] Could not find packages for the version informed.' + exit 1 + fi + + for pkg in "${all_files[@]}"; do + filename=$(basename $pkg) + + if [[ $filename == "cpqd-etics-configurator-appserver-wildfly"* ]] || + [[ $filename == "cpqd-dbmanager-etics-package"* ]] || + [[ $filename == "cpqd-dbmanager-customer"* ]] || + [[ $filename == "cpqd-etics-package-server"* ]] || + [[ $filename == "cpqd-etics-customer"* ]]; then + + wget $base_url/$pkg fi - - all_files=(`jf rt search --sort-by=path "${gp_artifactory_repo}/gp/${version}/*" | jq -r '.[].path'`) - - for pkg in "${all_files[@]}"; do - filename=`basename $pkg` - - if [[ $filename == "cpqd-etics-configurator-appserver-wildfly"* ]] || \ - [[ $filename == "cpqd-dbmanager-etics-package"* ]] || \ - [[ $filename == "cpqd-dbmanager-customer"* ]] || \ - [[ $filename == "cpqd-etics-package-server"* ]] || \ - [[ $filename == "cpqd-etics-customer"* ]]; then - - wget $base_url/$pkg - fi - done + done fi # cpqd-msgs-map-1.8.7-RC02-bin.zip cpqd-msgs-package-1.8.7-RC02-bin.zip wildfly-15.0.0.Final.zip wildfly-8.2.1.zip cp /l/disk0/mbrunhara/gp/zips/* . +if ! $should_install_webmap; then + rm wildfly-15*.zip +fi + if $should_install_gp; then - # creating folders - mkdir -p cpqd-folders/audit cpqd-folders/exportacoes cpqd-folders/updater cpqd-folders/dataloader cpqd-folders/virtualdisk + # find * -maxdepth 0 -type d -exec sudo rm -rf {} \; + # creating folders + mkdir -p cpqd-folders/audit cpqd-folders/exportacoes cpqd-folders/updater cpqd-folders/dataloader cpqd-folders/virtualdisk cpqd-folders/midmif - # unpacking files - unzip -qq wildfly-8.2.1.zip - find wildfly-8.2.1 -type f -name '*.sh' -exec chmod +x {} \; + # unpacking files + unzip -qq wildfly-8.2.1.zip + find wildfly-8.2.1 -type f -name '*.sh' -exec chmod +x {} \; - unzip -qq -d wildfly-configurator cpqd-etics-configurator-appserver-wildfly* - chmod +x wildfly-configurator/configurator/bin/setup.sh + unzip -qq -d wildfly-configurator cpqd-etics-configurator-appserver-wildfly* + chmod +x wildfly-configurator/configurator/bin/setup.sh - wildfly-configurator/configurator/bin/setup.sh + wildfly-configurator/configurator/bin/setup.sh - # doing this again to add permissions for newly created files by configurator - find wildfly-8.2.1 -type f -name '*.sh' -exec chmod +x {} \; + # doing this again to add permissions for newly created files by configurator + find wildfly-8.2.1 -type f -name '*.sh' -exec chmod +x {} \; - unzip -qq -d server cpqd-etics-package-server* - mv server/cpqd*/* server/ - rmdir server/cpqd* - unzip -qq -o -d server cpqd-dbmanager-etics-package* - unzip -qq -o -d server cpqd-dbmanager-customer* - unzip -qq -o -d server cpqd-etics-customer-*-package-server* + unzip -qq -d server cpqd-etics-package-server* + mv server/cpqd*/* server/ + rmdir server/cpqd* + unzip -qq -o -d server cpqd-dbmanager-etics-package* + unzip -qq -o -d server cpqd-dbmanager-customer* + unzip -qq -o -d server cpqd-etics-customer-*-package-server* - cd server/dbmanager - # removes '&' from the 'dbmanager.sh' script so this script can run things sequentially - # sed -i 's/org.eclipse.equinox.launcher.Main $ARGS &/org.eclipse.equinox.launcher.Main $ARGS/g' dbmanager.sh - ./dbmanager.sh + cd server/dbmanager + # removes '&' from the 'dbmanager.sh' script so this script can run things sequentially + # sed -i 's/org.eclipse.equinox.launcher.Main $ARGS &/org.eclipse.equinox.launcher.Main $ARGS/g' dbmanager.sh + ./dbmanager.sh - cd $root_dir/server/configurator/bin - chmod +x setup.sh - ./setup.sh + cd $root_dir/server/configurator/bin + chmod +x setup.sh + ./setup.sh + # TODO, parametrizar + if false; then deployments_folder=$root_dir/wildfly-8.2.1/ports-01/deployments # adding servergroupname cd $deployments_folder $scripts_folder/$script_explode_java_files_filename - hostname=`cat /etc/hostname` + hostname=$(cat /etc/hostname) cd $deployments_folder/../configuration cp standalone-full.xml standalone-full.xml.old xmlstarlet ed -L -N x="urn:jboss:domain:2.2" -s "//x:server/x:system-properties" -t elem -n property -v "" \ - -i "//x:server/x:system-properties/property[last()]" -t attr -n name -v "servergroupname" \ - -i "//x:server/x:system-properties/property[last()]" -t attr -n value -v "$hostname" standalone-full.xml + -i "//x:server/x:system-properties/property[last()]" -t attr -n name -v "servergroupname" \ + -i "//x:server/x:system-properties/property[last()]" -t attr -n value -v "$hostname" standalone-full.xml # adding ignore database version $scripts_folder/$script_disable_dbversion_check_filename --deployments-dir $deployments_folder + fi fi if ! $should_install_webmap; then - echo "[INFO] Skipping WebMap installation..." - exit 0 + echo "[INFO] Skipping WebMap installation..." + exit 0 fi +cd $root_dir + gp_superparent_pom_filename_wc='cpqd-etics-super-parent-*.pom' -gp_superparent_pom_dl="$gp_maven_repo/br/com/cpqd/etics/parent/cpqd-etics-super-parent/$version/$gp_superparent_pom_filename_wc" -jf rt dl --flat --fail-no-op "$gp_superparent_pom_dl" -gp_superparent_pom_filename=`find . -maxdepth 1 -type f -name "$gp_superparent_pom_filename_wc" -exec basename {} \;` -if [ -z "$gp_superparent_pom_filename" ]; then - echo "[ERROR] Could not find the $gp_superparent_pom_filename_wc filename" - exit 1 +cpqd_etics_super_parent_version=$version +if [[ $version = *?-T[0-9]* ]]; then + cpqd_etics_super_parent_version="${version%-T[0-9]*}-SNAPSHOT" fi -cdk_version=`xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -v '/pom:project/pom:parent/pom:version' $gp_superparent_pom_filename` -cdk_maven_repo=`get_maven_repo $cdk_version` +gp_superparent_pom_dl="$gp_maven_repo/br/com/cpqd/etics/parent/cpqd-etics-super-parent/$cpqd_etics_super_parent_version/$gp_superparent_pom_filename_wc" +jf rt dl --flat --fail-no-op "$gp_superparent_pom_dl" +gp_superparent_pom_filename=$(find . -maxdepth 1 -type f -name "$gp_superparent_pom_filename_wc" -exec basename {} \;) + +if [ -z "$gp_superparent_pom_filename" ]; then + echo "[ERROR] Could not find the $gp_superparent_pom_filename_wc filename" + echo "[ERROR] Attempted to download at URL \"$gp_superparent_pom_dl\"" + exit 1 +fi + +cdk_version=$(xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -v '/pom:project/pom:parent/pom:version' $gp_superparent_pom_filename) +cdk_maven_repo=$(get_maven_repo $cdk_version) cdk_superparent_pom_filename_wc='cpqd-super-parent-*.pom' cdk_superparent_pom_dl="$cdk_maven_repo/br/com/cpqd/parent/cpqd-super-parent/$cdk_version/$cdk_superparent_pom_filename_wc" jf rt dl --flat --fail-no-op "$cdk_superparent_pom_dl" -cdk_superparent_pom_filename=`find . -maxdepth 1 -type f -name "$cdk_superparent_pom_filename_wc" -exec basename {} \;` +cdk_superparent_pom_filename=$(find . -maxdepth 1 -type f -name "$cdk_superparent_pom_filename_wc" -exec basename {} \;) if [ -z "$cdk_superparent_pom_filename" ]; then - echo "[ERROR] Could not find the $cdk_superparent_pom_filename_wc filename" - exit 1 + echo "[ERROR] Could not find the $cdk_superparent_pom_filename_wc filename" + exit 1 fi -msgs_version=`xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -v '/pom:project/pom:properties/pom:cpqd.msgs.version' $cdk_superparent_pom_filename` +msgs_version=$(xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -v '/pom:project/pom:properties/pom:cpqd.msgs.version' $cdk_superparent_pom_filename) -msgs_maven_repo=`get_maven_repo $msgs_version` +msgs_maven_repo=$(get_maven_repo $msgs_version) msgs_package_filename_wc="cpqd-msgs-package-*.zip" jf rt dl --flat --fail-no-op "$msgs_maven_repo/br/com/cpqd/msgs/package/cpqd-msgs-package/$msgs_version/$msgs_package_filename_wc" -msgs_package_filename=`find . -maxdepth 1 -type f -name "$msgs_package_filename_wc" -exec basename {} \;` +msgs_package_filename=$(find . -maxdepth 1 -type f -name "$msgs_package_filename_wc" -exec basename {} \;) if [ -z "$msgs_package_filename" ]; then - echo "[ERROR] Could not find the $msgs_package_filename filename" - exit 1 + echo "[ERROR] Could not find the $msgs_package_filename filename" + exit 1 fi msgs_map_filename_wc="cpqd-msgs-map-*.zip" jf rt dl --flat --fail-no-op "$msgs_maven_repo/br/com/cpqd/msgs/map/cpqd-msgs-map/$msgs_version/$msgs_map_filename_wc" -msgs_map_filename=`find . -maxdepth 1 -type f -name "$msgs_map_filename_wc" -exec basename {} \;` +# msgs_map_filename=`find . -maxdepth 1 -type f -name "$msgs_map_filename_wc" -exec basename {} \;` +msgs_map_filename=$(find . -maxdepth 1 -type f -name "$msgs_map_filename_wc") if [ -z "$msgs_map_filename" ]; then - echo "[ERROR] Could not find the $msgs_map_filename filename" - exit 1 + echo "[ERROR] Could not find the $msgs_map_filename filename" + exit 1 fi rm $gp_superparent_pom_filename $cdk_superparent_pom_filename @@ -266,31 +306,31 @@ sed -i 's/8788/8789/g' $wildfly15_folder/bin/runstandalone.sh find $wildfly15_folder -type f -name '*.sh' -exec chmod +x {} \; if $should_install_apache; then - sudo apt install apache2 - sudo a2enmod proxy - sudo a2enmod proxy_http + sudo apt install apache2 + sudo a2enmod proxy + sudo a2enmod proxy_http - apache2conf_filepath='/etc/apache2/apache2.conf' - hostname_line="ServerName $hostname:8808" + apache2conf_filepath='/etc/apache2/apache2.conf' + hostname_line="ServerName $hostname:8808" - if ! grep -q "$hostname_line" "$apache2conf_filepath"; then - echo "" | sudo tee --append $apache2conf_filepath - echo "ServerName $hostname:8808" | sudo tee --append $apache2conf_filepath - fi + if ! grep -q "$hostname_line" "$apache2conf_filepath"; then + echo "" | sudo tee --append $apache2conf_filepath + echo "ServerName $hostname:8808" | sudo tee --append $apache2conf_filepath + fi - apache2portsconf_filepath='/etc/apache2/ports.conf' - sudo sed -i 's/Listen 80/Listen 8808/g' $apache2portsconf_filepath + apache2portsconf_filepath='/etc/apache2/ports.conf' + sudo sed -i 's/Listen 80/Listen 8808/g' $apache2portsconf_filepath - apache2proxyconf_filepath='/etc/apache2/mods-enabled/proxy.conf' - text_to_add=("ProxyPreserveHost On" + apache2proxyconf_filepath='/etc/apache2/mods-enabled/proxy.conf' + text_to_add=("ProxyPreserveHost On" "ProxyPass /cpqd/ http://$hostname:8180/cpqd/" "ProxyPassReverse /cpqd/ http://$hostname:8180/cpqd/" "ProxyPass /geoserver/ http://$hostname:8080/geoserver/" "ProxyPassReverse /geoserver/ http://$hostname:8080/geoserver/") - for line in "${text_to_add[@]}"; do - sudo sed -i '/<\/IfModule>/i '"\\ \\ \\ \\ \\ \\ \\ \\ $line" $apache2proxyconf_filepath - done - - sudo systemctl restart apache2 + for line in "${text_to_add[@]}"; do + sudo sed -i '/<\/IfModule>/i '"\\ \\ \\ \\ \\ \\ \\ \\ $line" $apache2proxyconf_filepath + done + + sudo systemctl restart apache2 fi