Files
dotfiles/scripts/shell/job/gp/install-gp.sh
2025-01-07 14:33:06 -03:00

396 lines
13 KiB
Bash
Executable File

#!/bin/env 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 ""
echo " --no-download-gp | --no-dl-gp (Optional) Make the script not download the files from Artifactory"
echo " --no-download-msgs | --no-dl-msgs (Optional) Make the script not download the MSGS files from Artifactory"
echo " --no-server | --no-svr (Optional) Make the script not install GP server"
echo " --webmap | --wm (Optional) Make the script install the WebMap module"
echo " --apache (Optional) Make the script install the Apache dependency for WebMap module"
echo " --msgs4 (Optional) Make the script install the version 4 of the WebMap module"
}
version=''
should_download_packages_gp=true
should_download_packages_msgs=true
should_install_gp=true
should_install_geoserver=true
should_install_apache=false
should_install_msgs_4=false
while [ "$#" -gt 0 ]; do
case "$1" in
--help | -h)
show_help
exit
;;
--version | -v)
version="$2"
shift 2
;;
--no-download-gp | --no-dl-gp)
should_download_packages_gp=false
shift
;;
--no-download-msgs | --no-dl-msgs)
should_download_packages_msgs=false
shift
;;
--no-server | --no-svr)
should_install_gp=false
shift
;;
--no-server | --no-svr)
should_install_geoserver=false
shift
;;
--apache)
should_install_apache=true
shift
;;
--msgs4)
should_install_msgs_4=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
fi
root_dir=$(pwd)
if [ $(basename $root_dir) != "$version" ]; then
mkdir --parents $version
cd $version
# sudo rm -rf *
root_dir=$(pwd)
fi
scripts_folder=$HOME/documents/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
validate_repo_script() {
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
}
get_version_type() {
version=$1
if [[ $version == *"-"* ]]; then
echo 'snapshot'
else
echo 'release'
fi
}
get_maven_repo() {
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
}
get_artifactory_repo() {
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
}
chmod_sh_files_recursively() {
DIRPATH=$1
find $DIRPATH -type f -name '*.sh' -exec chmod +x {} \;
}
remove_empty_dir_after_extracting() {
DIRPATH=$1
EXTRACTED_ROOT_DIRNAME=$2
mv $DIRPATH/**/* $DIRPATH
find $DIRPATH -maxdepth 1 -type d -not -path $DIRPATH -name "$EXTRACTED_ROOT_DIRNAME*" -exec rm -r {} \;
}
script_explode_java_files_filename='explode-java-files.sh'
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
script_mise_exec='disable-dbversion-check-on-software-info-file.sh'
validate_repo_script $script_mise_exec
# download files
base_url='artifactory.cpqd.com.br/artifactory'
gp_maven_repo=$(get_maven_repo $version)
gp_artifactory_repo=$(get_artifactory_repo $version)
if $should_download_packages_gp; then
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
done
fi
# cpqd-msgs-map-*-bin.zip cpqd-msgs-package-*-bin.zip wildfly-*.Final.zip wildfly-*.zip
# TODO, deve haver pastas do wildfly aqui
cp $HOME/documents/ambients-gp/zips/* .
WILDFLY_WEB_FILENAME="wildfly-8*.zip"
WILDFLY_MSGS_FILENAME_WC="wildfly-21*.zip"
if ! $should_install_geoserver; then
rm $WILDFLY_MSGS_FILENAME
fi
if $should_install_gp; then
# 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
WILDFLY_WEB_DIRNAME='wildfly-server'
unzip -d $WILDFLY_WEB_DIRNAME -qq $WILDFLY_WEB_FILENAME
remove_empty_dir_after_extracting $WILDFLY_WEB_DIRNAME 'wildfly-'
chmod_sh_files_recursively $WILDFLY_WEB_DIRNAME
WILDFLY_WEB_CONFIGURATOR_DIRNAME=wildfly-configurator
unzip -qq -d $WILDFLY_WEB_CONFIGURATOR_DIRNAME cpqd-etics-configurator-appserver-wildfly-*
chmod_sh_files_recursively $WILDFLY_WEB_CONFIGURATOR_DIRNAME
wildfly_configurator_bin_file=$WILDFLY_WEB_CONFIGURATOR_DIRNAME/configurator/bin/setup.sh
$wildfly_configurator_bin_file
# doing this again to add permissions for newly created files by configurator
chmod_sh_files_recursively $WILDFLY_WEB_DIRNAME
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 $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)
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
# adding ignore database version
$scripts_folder/$script_disable_dbversion_check_filename --deployments-dir $deployments_folder
fi
fi
if ! $should_install_geoserver; then
echo "[INFO] Skipping GeoServer/WebMap installation..."
exit 0
fi
cd $root_dir
msgs_package_filename=''
msgs_map_filename=''
if $should_download_packages_msgs; then
if ! $should_install_msgs_4; then
gp_superparent_pom_filename_wc='cpqd-etics-super-parent-*.pom'
cpqd_etics_super_parent_version=$version
if [[ "$version" =~ ^.*-T[0-9]*$ ]]; then
cpqd_etics_super_parent_version="${version%-T[0-9]*}-SNAPSHOT"
fi
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 {} \;)
if [ -z "$cdk_superparent_pom_filename" ]; then
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)
rm $gp_superparent_pom_filename $cdk_superparent_pom_filename
else
msgs_version='4.0.0'
fi
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 {} \;)
if [ -z "$msgs_package_filename" ]; then
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")
if [ -z "$msgs_map_filename" ]; then
echo "[ERROR] Could not find the $msgs_map_filename filename"
exit 1
fi
else
msgs_package_filename_wc="cpqd-msgs-package-*.zip"
msgs_package_filename=$(find . -maxdepth 1 -type f -name "$msgs_package_filename_wc" -exec basename {} \;)
fi
msgs_package_dir=msgs-package
unzip -qq -d $msgs_package_dir $msgs_package_filename
remove_empty_dir_after_extracting $msgs_package_dir 'MSGS-'
chmod_sh_files_recursively $msgs_package_dir
# TODO, verificar se existe variável de ambiente "JBOSS_HOME" setada
# TODO, verificar se a porta 8080 está sendo usada
WILDFLY_GEOSERVER_FILENAME=$(find . -maxdepth 1 -type f -name "$WILDFLY_MSGS_FILENAME_WC")
WILDFLY_GEOSERVER_DIRNAME='wildfly-geoserver'
unzip -d $WILDFLY_GEOSERVER_DIRNAME -qq $WILDFLY_GEOSERVER_FILENAME
remove_empty_dir_after_extracting $WILDFLY_GEOSERVER_DIRNAME 'wildfly-'
chmod_sh_files_recursively $WILDFLY_GEOSERVER_DIRNAME
# TODO, a partir daqui, Java 11 se MSGS = 4?
# TODO, portas 8080 e 9990 não podem estar em uso
# APPSERVER_SETUP_CMD=("mise" "exec" "java@adoptopenjdk-11.0.24+8" "--" "$msgs_package_dir/appServerConfigurator/bin/setup.sh")
# eval "${APPSERVER_SETUP_CMD[@]}"
$msgs_package_dir/appServerConfigurator/bin/setup.sh
# $msgs_package_dir/bin/setup.sh
cp $root_dir/server/shared/config/map_info*.xml $root_dir/$msgs_package_dir/geoserverConfigurator/config
mkdir --parents $WILDFLY_GEOSERVER_DIRNAME/standalone/data_dir
$msgs_package_dir/geoserverConfigurator/bin/setup.sh
GEOSERVER_BIN_FILENAME=runstandalone.sh
unzip -qq -d $WILDFLY_GEOSERVER_DIRNAME/standalone server/installation/deployments/mapserver/mapserver-geoserver-data_dir.zip
if ! $should_install_msgs_4; then
unzip -qq -d $WILDFLY_GEOSERVER_DIRNAME/standalone/data_dir/www/map $msgs_map_filename
GEOSERVER_BIN_FILENAME=standalone.sh
fi
GEOSERVER_BIN=$WILDFLY_GEOSERVER_DIRNAME/bin/$GEOSERVER_BIN_FILENAME
# sed -i 's/8788/8789/g' $GEOSERVER_BIN
find $WILDFLY_GEOSERVER_DIRNAME -type f -name '*.sh' -exec chmod +x {} \;
if $should_install_apache; then
sudo apt install apache2
sudo a2enmod proxy
sudo a2enmod proxy_http
apache2conf_filepath='/etc/apache2/apache2.conf'
hostname_line="ServerName $(hostname):8808"
if [ ! $(grep -q "$hostname_line" "$apache2conf_filepath") ]; then # TODO, sempre da true
echo "" | sudo tee --append $apache2conf_filepath
echo "$hostname_line" | sudo tee --append $apache2conf_filepath
fi
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"
"ProxyPass /cpqd/ http://$hostname:8180/cpqd/"
"ProxyPassReverse /cpqd/ http://$hostname:8180/cpqd/"
"ProxyPass /geoserver/ http://$hostname:8080/geoserver/"
"ProxyPassReverse /geoserver/ http://$hostname:8080/geoserver/")
# TODO, nao funciona
for line in "${text_to_add[@]}"; do
sudo sed -i '/<\/IfModule>/i '"\\ \\ \\ \\ \\ \\ \\ \\ $line" $apache2proxyconf_filepath
done
sudo systemctl restart apache2
fi