-
-
Save davidmsantos90/bbc34b664e57ddbbb481ed5eeb5822e4 to your computer and use it in GitHub Desktop.
Download, unzip and run the latest pentaho-server or pdi-client build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place where builds will be downloaded and unzipped | |
root_directory=$(echo ~/Pentaho) | |
# build repo url | |
# build_repository=https://build.orl.eng.hitachivantara.com | |
# new build hosted (wip) | |
build_repository=http://172.16.11.57 | |
# other configs | |
launch_server=true | |
# feature branch: master or scheduler-plugin or WCAG-branch or... | |
#feature=master | |
version=10.3.0.0 | |
mode=server | |
build=snapshot | |
plugins=paz-plugin-ee,pdd-plugin-ee,pir-plugin-ee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# TODO | |
# - list builds | |
# - better error handling | |
# - better detection of installed build and plugins | |
# - canceling script before download finished, should delete files | |
BIFS="$IFS" | |
### Setup modes (-m / mode) ### | |
MODE_SERVER="server" | |
MODE_PDI="pdi" | |
### Server Plugins (-p / plugins) ### | |
PLUGIN_PAZ="paz-plugin-ee" | |
PLUGIN_PDD="pdd-plugin-ee" | |
PLUGIN_PIR="pir-plugin-ee" | |
### Buils (-b / build) ### | |
SNAPSHOT="snapshot" | |
QAT="qat" | |
RELEASE="release" | |
### Features (-f / feature) ### | |
FEAT_MASTER="master" | |
FEAT_WCAG="WCAG-branch" | |
FEAT_SCHEDULER="schedule-plugin" | |
### log colors ### | |
INFO="\033[1;34m" | |
SUCCESS="\033[1;32m" | |
WARN="\033[1;33m" | |
ERROR="\033[1;31m" | |
CLEAR="\033[0;39m" | |
### Artifacts ### | |
PDI=pdi-ee-client | |
SERVER=pentaho-server-ee | |
### Check script dependencies | |
has_dependencies_installed=true | |
date_path=$(which date) | |
if [ -z $date_path ]; then | |
has_dependencies_installed=false | |
[[ $OSTYPE != 'darwin'* ]] && echo -e "$ERROR! this script needs 'date' to be installed !$CLEAR" | |
fi | |
if [ $has_dependencies_installed = false ] || ([[ $OSTYPE == 'darwin'* ]] && [[ $date_path != *'coreutils'* ]]); then | |
has_dependencies_installed=false | |
echo -e "$ERROR! this script needs 'date' from 'coreutils' to be installed !$CLEAR" | |
echo -e " - $ 'brew install coreutils'" | |
echo -e " - and add it to your $INFO\$PATH$CLEAR" | |
echo -e " - PATH=\"/opt/homebrew/opt/coreutils/libexec/gnubin:\$PATH\"" | |
fi | |
if [ -z $(which jq) ]; then | |
has_dependencies_installed=false | |
echo -e "$ERROR! this script needs 'jq' to be installed !$CLEAR" | |
fi | |
if [ -z $(which wget) ]; then | |
has_dependencies_installed=false | |
echo -e "$ERROR! this script needs 'wget' to be installed !$CLEAR" | |
fi | |
if [ $has_dependencies_installed = false ]; then | |
exit 0 | |
fi | |
### load env values ### | |
CURRENT_SCRIPT_DIR=$(dirname "$(realpath "$0")") | |
env_path="$CURRENT_SCRIPT_DIR/.env" | |
if test -f $env_path; then | |
set -a | |
. $env_path | |
set +a | |
fi | |
get_date() { | |
local date_str=$1 | |
local output_format="%Y-%m-%d" | |
echo $(date -d "$date_str" "+$output_format") | |
} | |
### load script arguments ### | |
while getopts hs:l:m:p:b:f:v:d: flag | |
do | |
case "${flag}" in | |
h) help=true;; | |
s) secure=${OPTARG};; | |
l) launch_server=${OPTARG};; | |
m) mode=${OPTARG};; | |
p) plugins=${OPTARG};; | |
b) build=${OPTARG};; | |
f) feature=${OPTARG};; | |
v) version=${OPTARG};; | |
d) date_setup="$(get_date ${OPTARG})";; | |
*) echo -e "$WARN- flag '${flag}' is not supported";; | |
esac | |
done | |
### set default values after load ### | |
date_today="$(get_date)" | |
root_directory="${root_directory:-$(echo ~/Pentaho)}" | |
secure="${secure:-true}" | |
help="${help:-false}" | |
launch_server="${launch_server:-false}" | |
version="${version:-10.3.0.0}" | |
mode="${mode:-$MODE_SERVER}" | |
build="${build:-$SNAPSHOT}" | |
feature="${feature:-$FEAT_MASTER}" | |
date_setup="${date_setup:-$date_today}" | |
if [ "$help" = true ]; then | |
echo -e "$INFO\c" | |
echo -e "$INFO### Help ###\n" | |
echo -e "$INFO (-s) [true] Download build in secure / unsecure mode" | |
echo -e "$INFO (-l) [false] Launch after build is ready" | |
echo -e "$INFO (-m) [server] Setup mode" | |
echo -e "$CLEAR - 'server'" | |
echo -e "$CLEAR - 'pdi'" | |
echo -e "$INFO (-p) [null] Pentaho Server plugins" | |
echo -e "$CLEAR - 'paz-plugin-ee'" | |
echo -e "$CLEAR - 'paz-plugin-ee,pdd-plugin-ee,pir-plugin-ee'" | |
echo -e "$CLEAR - '...'" | |
echo -e "$INFO (-b) [snapshot] Pentaho build type" | |
echo -e "$CLEAR - 'snapshot'" | |
echo -e "$CLEAR - 'qat'" | |
echo -e "$CLEAR - 'release'" | |
echo -e "$INFO (-f) [master] Download build from a feature branch" | |
echo -e "$CLEAR - 'master'" | |
echo -e "$CLEAR - 'WCAG-branch'" | |
echo -e "$CLEAR - 'schedule-plugin'" | |
echo -e "$CLEAR - '...'" | |
echo -e "$INFO (-v) [$version] Pentaho build version" | |
echo -e "$INFO (-d) [$date_today] Specify the build date you want to setup" | |
echo -e "$CLEAR - need to have build already downloaded" | |
echo -e "$CLEAR - format: YYYY-MM-DD (other formats may be valid)" | |
echo -e "$CLEAR" | |
exit 0 | |
fi | |
### Misc Utils ### | |
get_temp_directory() { | |
echo "$root_directory/builds/.temp" | |
} | |
get_download_directory() { | |
echo "$root_directory/builds/$build/$feature/$version/$date_setup" | |
} | |
get_unzip_directory() { | |
echo "$root_directory/$build/$feature/$version/$date_setup" | |
} | |
get_pdi_unzip_directory() { | |
echo "$(get_unzip_directory)/$PDI" | |
} | |
get_server_unzip_directory() { | |
echo "$(get_unzip_directory)/$SERVER" | |
} | |
get_plugin_unzip_directory() { | |
echo "$(get_server_unzip_directory)/pentaho-server/pentaho-solutions/system" | |
} | |
get_insecure_flag() { | |
local flag="" | |
if [ "$secure" = false ]; then | |
flag="--no-check-certificate" | |
fi | |
echo "$flag" | |
} | |
is_server_mode() { | |
local flag=false | |
if [ "$mode" = "$MODE_SERVER" ]; then | |
flag=true | |
fi | |
echo "$flag" | |
} | |
# When date_setup is different from date_today, a custom date was provided | |
# and the script assumes that you already download that build in the past | |
is_unzip_only() { | |
local flag=false | |
if [ "$date_setup" != "$date_today" ]; then | |
flag=true | |
fi | |
echo "$flag" | |
} | |
is_unzip_only_possible() { | |
local flag=true | |
if [ "$(is_server_mode)" = true ]; then | |
if [ ! -d "$(get_server_unzip_directory)" ] && [ ! -d "$(get_download_directory)" ]; then | |
flag=false | |
fi | |
else | |
if [ ! -d "$(get_pdi_unzip_directory)" ] && [ ! -d "$(get_download_directory)" ]; then | |
flag=false | |
fi | |
fi | |
echo "$flag" | |
} | |
is_build_unzipped() { | |
local flag=false | |
if [ "$(is_server_mode)" = true ]; then | |
if [ -d "$(get_server_unzip_directory)" ]; then | |
flag=true | |
fi | |
else | |
if [ -d "$(get_pdi_unzip_directory)" ]; then | |
flag=true | |
fi | |
fi | |
echo "$flag" | |
} | |
print_setup_info() { | |
local date_extra="${1:-latest}" | |
echo -e "$INFO\n### Setup Pentaho Build ###" | |
echo -e "- mode: '$mode'" | |
if [ "$(is_server_mode)" = true ]; then | |
echo -e "- plugins: '$plugins'" | |
fi | |
echo -e "- build: '$build'" | |
echo -e "- feature: '$feature'" | |
echo -e "- version: '$version'" | |
echo -e "- date: '$date_setup' ($date_extra) \n$CLEAR" | |
} | |
### JSON Utils | |
get_json_folder_id() { | |
local build_uppercase=$(echo "$build" | tr '[:lower:]' '[:upper:]') | |
local id="" | |
case "$build" in | |
"$RELEASE") id="$version";; | |
"$QAT") | |
major=$(echo $version | cut -d'.' -f 1) | |
minor=$(echo $version | cut -d'.' -f 2) | |
id="$major.$minor-$build_uppercase" | |
;; | |
*) # SNAPSHOT and others | |
id="$version-$build_uppercase"; [ "$feature" != "master" ] && id="$feature" | |
;; | |
esac | |
echo $id | |
} | |
get_json_build_file_id() { | |
local id=$1 | |
local sufix="" | |
if [ -z $id ]; then | |
case "$mode" in | |
"$MODE_SERVER") id=$SERVER;; | |
"$MODE_PDI") | |
id=$PDI | |
sufix="-osgi" | |
;; | |
# ?handle feature branch ids? | |
# *) ;; | |
esac | |
fi | |
if [ $build = $SNAPSHOT ]; then | |
local build_uppercase=$(echo "$build" | tr '[:lower:]' '[:upper:]') | |
id="$id-$version-$build_uppercase" | |
fi | |
echo "$id$sufix.zip" | |
} | |
get_json_file_mapping() { | |
mkdir -p $(get_temp_directory) | |
local filename="fileMapping.json" | |
cd "$(get_temp_directory)" || exit | |
local mapping_url="$build_repository/hosted/$filename" | |
wget -nv -q -nc "$mapping_url" | |
echo $(jq -c '.' $filename) | |
} | |
get_json_build_folder() { | |
local jq_filter="folders.\"$(get_json_folder_id)\"" | |
case "$build" in | |
# release and qat | |
# has multiple builds in ".groups" but we only want the latest | |
"$RELEASE" | "$QAT") jq_filter="$jq_filter.latest[0]";; | |
# snapshot and others | |
# always have just one build in groups (the latest) | |
*) jq_filter="$jq_filter.groups[0]";; | |
esac | |
# echo $jq_filter | |
echo $(get_json_file_mapping) | jq -c -r ".$jq_filter" | |
} | |
get_date_from_json() { | |
local folder=$1 | |
if [ "$build" != "$SNAPSHOT" ]; then | |
local label=$(echo "$folder" | jq -r ".label") | |
echo $label | cut -d'|' -f 2 | cut -d'_' -f 1 | tr -d ' ' | |
else | |
local request_url=$(echo "$folder" | jq -r ".files.\"$(get_json_build_file_id)\".url") | |
local request_info=$(wget -S --spider "$request_url" 2>&1) | |
local content_disposition=$(echo "$request_info" | grep "Content-Disposition") | |
local regex="filename=\".+-$version-([0-9]+)\..+\";" | |
if [[ $content_disposition =~ $regex ]]; then | |
echo $(get_date "${BASH_REMATCH[1]}") | |
fi | |
fi | |
} | |
get_artifact_url_from_json() { | |
local folder=$1 | |
local id_override=$2 | |
local url=$(echo "$folder" | jq -r ".files.\"$(get_json_build_file_id $id_override)\".url") | |
echo $url | |
} | |
### Download Utils ### | |
download_artifact() { | |
local artifact="$1" | |
local filename="$artifact.zip" | |
local url=$2 | |
cd "$(get_download_directory)" || exit | |
if test -f "./$filename"; then | |
echo -e "$SUCCESS- '$filename' already downloaded!$CLEAR" | |
return | |
fi | |
echo -e "$INFO\c" | |
wget -nv -q --show-progress -nc $(get_insecure_flag) -O "$filename" "$url" | |
echo -e "$CLEAR\c" | |
} | |
download_pdi() { | |
local data=$1 | |
local url=$(get_artifact_url_from_json "$data") | |
download_artifact "$PDI" "$url" | |
} | |
download_server() { | |
local data=$1 | |
local url=$(get_artifact_url_from_json "$data") | |
download_artifact "$SERVER" "$url" | |
} | |
download_plugin() { | |
local data=$1 | |
local name=$2 | |
local url=$(get_artifact_url_from_json "$data" "$name") | |
download_artifact "$name" "$url" | |
} | |
### Unzip utils ### | |
unzip_artifact() { | |
cd "$(get_download_directory)" || exit | |
local filename="$1.zip" | |
local destination="$2" | |
echo -e "$INFO- unzipping $filename to $destination'" | |
unzip -q "$filename" -d "$destination" | |
echo -e "$CLEAR\c" | |
} | |
unzip_pdi() { | |
local destination="$(get_pdi_unzip_directory)" | |
unzip_artifact "$PDI" "$destination" | |
# enable debug on pdi | |
sed -i "" "s/#OPT/OPT/" $destination/data-integration/spoon.sh | |
} | |
unzip_server() { | |
local destination="$(get_server_unzip_directory)" | |
unzip_artifact "$SERVER" "$destination" | |
# will not prompt user to press enter on server first run | |
rm -f "$destination/pentaho-server/promptuser.sh" | |
} | |
unzip_plugin() { | |
local name="$1" | |
unzip_artifact "$name" "$(get_plugin_unzip_directory)" | |
} | |
if [ "$(is_unzip_only)" = true ]; then | |
echo "$(print_setup_info 'selected build from the past')" | |
if [ "$(is_unzip_only_possible)" = false ]; then | |
echo -e "\n$WARN- artifacts from past build don't exist. setup won't continue$CLEAR" | |
exit 0 | |
fi | |
else | |
###### | |
### 1. check if can access build site (if not exit with warning) | |
###### | |
if [ -z "$build_repository" ]; then | |
echo -e "\n$WARN### 'build_repository' must be defined in the '.env' file ###" | |
exit 0 | |
fi | |
json_build_folder=$(get_json_build_folder) | |
date_latest=$(get_date_from_json "$json_build_folder") | |
if [ -z "$date_latest" ]; then | |
echo -e "\n$WARN### Repo site didn't return any data. this is most likely a vpn or a certificate issue! ###" | |
echo -e "- first check if you are connected to the VPN." | |
echo -e "- if yes, try running with '-s false' to run script in unsecure mode$CLEAR" | |
exit 0 | |
fi | |
###### | |
### 2. check if latest is today | |
###### | |
if [ "$date_latest" != "$date_today" ]; then | |
date_setup="$date_latest" | |
fi | |
echo "$(print_setup_info)" | |
###### | |
### 3. Download phase. check if latest build was downloaded already, if not it will download server and analyzer | |
###### | |
echo -e "$INFO\n### Download phase started ###\n$CLEAR" | |
if [ ! -d "$(get_download_directory)" ]; then | |
echo -e "$INFO- Creating download directory: $(get_download_directory)$CLEAR" | |
mkdir -p "$(get_download_directory)" | |
fi | |
if [ "$(is_server_mode)" = true ]; then | |
download_server "$json_build_folder" | |
IFS="," | |
for plugin in $plugins; do | |
download_plugin "$json_build_folder" "$plugin" | |
done | |
else | |
download_pdi "$json_build_folder" | |
fi | |
echo -e "$SUCCESS\n### Download phase finished ###\n$CLEAR" | |
fi | |
###### | |
### 4. Unzip phase. check if server was unzip already, if not it will unzip server and analyzer | |
###### | |
echo -e "$INFO\n### Unzip phase started ###\n$CLEAR" | |
if [ "$(is_build_unzipped)" = true ]; then | |
echo -e "$SUCCESS- build already unzipped $CLEAR" | |
else | |
echo -e "$INFO- Creating unzip directory: $(get_unzip_directory)$CLEAR" | |
mkdir -p "$(get_unzip_directory)" | |
if [ "$(is_server_mode)" = true ]; then | |
unzip_server | |
IFS="," | |
for plugin in $plugins; do | |
unzip_plugin "$plugin" | |
done | |
else | |
unzip_pdi | |
fi | |
fi | |
echo -e "$SUCCESS\n### Unzip phase finished ###\n$CLEAR" | |
###### | |
### 5. launch server | |
###### | |
if [ "$launch_server" = true ]; then | |
if [ "$(is_server_mode)" = true ]; then | |
trap ctrl_c INT | |
ctrl_c() { | |
# echo -e "$SUCCESS\n\n### Stopping the server (wait a moment before starting the server again) ###\n\n$CLEAR" | |
# $(get_server_unzip_directory)/pentaho-server/stop-pentaho.sh | |
pkill -9 -f tomcat | |
} | |
sleep 1 | |
$(get_server_unzip_directory)/pentaho-server/start-pentaho-debug.sh && tail -f $(get_server_unzip_directory)/pentaho-server/tomcat/logs/catalina.out | sed \ | |
-e 's/\(.*INFO.*\)/\x1B[1;34m\1\x1B[39m/' \ | |
-e 's/\(.*DEBUG.*\)/\x1B[1;35m\1\x1B[39m/' \ | |
-e 's/\(.*ERROR.*\)/\x1B[31m\1\x1B[39m/' \ | |
-e 's/\(.*Exception in.*\)/\x1B[31m\1\x1B[39m/' \ | |
-e 's/\(.*Caused by:.*\)/\x1B[31m\1\x1B[39m/' \ | |
-e 's/\(.*WARNING.*\)/\x1B[33m\1\x1B[39m/' | |
else | |
$(get_pdi_unzip_directory)/data-integration/spoon.sh | sed \ | |
-e 's/\(.*INFO.*\)/\x1B[1;34m\1\x1B[39m/' \ | |
-e 's/\(.*DEBUG.*\)/\x1B[1;35m\1\x1B[39m/' \ | |
-e 's/\(.*ERROR.*\)/\x1B[31m\1\x1B[39m/' \ | |
-e 's/\(.*Exception in.*\)/\x1B[31m\1\x1B[39m/' \ | |
-e 's/\(.*Caused by:.*\)/\x1B[31m\1\x1B[39m/' \ | |
-e 's/\(.*WARNING.*\)/\x1B[33m\1\x1B[39m/' | |
fi | |
else | |
if [ "$(is_server_mode)" = true ]; then | |
echo -e "$INFO" | |
echo "To launch and log the server, run:" | |
echo " $ cd $(get_server_unzip_directory)/pentaho-server" | |
echo " $ ./start-pentaho-debug.sh && tail -f ./tomcat/logs/catalina.out | sed \\" | |
echo " -e 's/\(.*INFO.*\)/\\\x1B[1;34m\1\\\x1B[39m/' \\" | |
echo " -e 's/\(.*DEBUG.*\)/\\\x1B[1;35m\1\\\x1B[39m/' \\" | |
echo " -e 's/\(.*ERROR.*\)/\\\x1B[31m\1\\\x1B[39m/' \\" | |
echo " -e 's/\(.*Exception in.*\)/\\\x1B[31m\1\\\x1B[39m/' \\" | |
echo " -e 's/\(.*Caused by:.*\)/\\\x1B[31m\1\\\x1B[39m/' \\" | |
echo " -e 's/\(.*WARNING.*\)/\\\x1B[33m\1\\\x1B[39m/'\n" | |
echo -e "$CLEAR" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment