diff --git a/hooks/templates/env_init.sh.cfg.erb b/hooks/templates/env_init.sh.cfg.erb new file mode 100644 index 0000000000000000000000000000000000000000..f1527930376729e374ecc889da7e396f43293d3b --- /dev/null +++ b/hooks/templates/env_init.sh.cfg.erb @@ -0,0 +1,10 @@ +# for shellscripts/env_init.sh.cfg +# ----------------------------------------------------------------------------- +# known java versions +<%= @replace["java-versions"] %> + +# ----------------------------------------------------------------------------- +# known maven versions +<%= @replace["maven-versions"] %> + +# ----------------------------------------------------------------------------- diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index 3b7e633a01d3797f0b2aee8c3db0bc0015e3ee24..1d5157c7dc29c776eb58aafb55eb2cabb7ff42f4 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -1880,10 +1880,11 @@ class project extends base // -------------------------------------------------- // task#1726 - add environment $sSetEnv = '' - . 'export GIT_SSH="' . $this->_aConfig['appRootDir'] . '/shellscripts/gitsshwrapper.sh";' - . 'export DIR_SSH_KEYS="' . $this->_aConfig['dataDir'] . '/sshkeys";' - . 'export DIR_APPROOT="' . $sTempBuildDir . '";' - . 'export NVMINIT="' . $this->_aConfig['appRootDir'] . '/shellscripts/nvm_init.sh";' + . 'export GIT_SSH="' . $this->_aConfig['appRootDir'] . '/shellscripts/gitsshwrapper.sh"; ' + . 'export DIR_SSH_KEYS="' . $this->_aConfig['dataDir'] . '/sshkeys"; ' + . 'export DIR_APPROOT="' . $sTempBuildDir . '"; ' + . 'export NVMINIT="' . $this->_aConfig['appRootDir'] . '/shellscripts/nvm_init.sh"; ' + . 'export ENVINIT="' . $this->_aConfig['appRootDir'] . '/shellscripts/env_init.sh"; ' . (isset($this->_aConfig['build']['env']) ? $this->_aConfig['build']['env'] : ''); $sHookfile = $this->_aConfig['build']['hooks']['build-postclone']; diff --git a/shellscripts/env_init.sh b/shellscripts/env_init.sh new file mode 100755 index 0000000000000000000000000000000000000000..2449d9907a23a72bf9d3a9cfbd731e941bd69fe7 --- /dev/null +++ b/shellscripts/env_init.sh @@ -0,0 +1,109 @@ +#!/bin/bash +# ====================================================================== +# +# ENV INIT +# +# This is a helper tool for build processes with java and maven. +# It sets a custom java and maven version +# +# ---------------------------------------------------------------------- +# 2024-02-18 first lines <axel.hahn@unibe.ch> +# ====================================================================== + +cd "$( dirname "$0")" || exit 1 + +typeset -A aJava +typeset -A aMaven + +USAGE=" +This is a helper script to set the shell environment +for a wanted version of java and maven. + +SYNTAX: source $0 [options] + +OPTIONS: + -j|--java <version> Set Java version + -m|--maven <version> Set Maven version + -h|--help Show this help +" + + +if [ "$#" -eq 0 ]; then + echo "ERROR: parameter required. Use -h for help." + exit 2 +fi + +. "env_init.sh.cfg" || exit 3 + +# ---------------------------------------------------------------------- + +while [[ "$#" -gt 0 ]]; do case $1 in + + -h|--help) + echo "$USAGE"; + echo "Java versions:" + for v in "${!aJava[@]}" + do + echo " $v ... ${aJava[$v]}" + done + echo + echo "Maven versions:" + for v in "${!aMaven[@]}" + do + echo " $v ... ${aMaven[$v]}" + done + echo + exit 0 + ;; + + -j|--java) + if [ -z "${aJava[$2]}" ]; then + echo "ERROR: java version $2 is unknown on this system" + exit 4 + fi + if [ ! -x "${aJava[$2]}/bin/java" ]; then + echo "ERROR: Path for java version $2 is wrong - ${aJava[$2]}/bin/java not executable" + exit 5 + fi + echo ">>> Set JAVA version $2" + export JAVA_HOME="${aJava[$2]}" + export PATH="${aJava[$2]}/bin:${PATH}" + + echo "\$ java --version" + java --version + echo + shift; shift; + ;; + + -m|--maven) + if [ -z "${aMaven[$2]}" ]; then + echo "ERROR: maven version $2 is unknown on this system" + exit 6 + fi + if [ ! -x "${aMaven[$2]}/bin/mvn" ]; then + echo "ERROR: Path for mvn version $2 is wrong - ${aMaven[$2]}/bin/mvn not executable" + exit 7 + fi + echo ">>> Set maven version $2" + export PATH="${aMaven[$2]}/bin:${PATH}" + + echo "\$ mvn --version" + mvn --version + echo + shift; shift; + ;; + + *) if grep "^-" <<< "$1" >/dev/null ; then + echo; echo "ERROR: Unknown parameter: $1"; echo "Use -h for help."; exit 8 + fi + break; + ;; + +esac; done + +if [ -n "$*" ]; then + echo "ERROR: No parameter supported. Use -h for help." + exit 9 +fi + +# ---------------------------------------------------------------------- diff --git a/shellscripts/env_init.sh.cfg.dist b/shellscripts/env_init.sh.cfg.dist new file mode 100644 index 0000000000000000000000000000000000000000..1e3a8de77144936e025ad1fa865a84d5b9a69a91 --- /dev/null +++ b/shellscripts/env_init.sh.cfg.dist @@ -0,0 +1,11 @@ +# ----------------------------------------------------------------------------- +# known java versions +aJava[21]="/usr/lib/jvm/java-21-openjdk" +aJava[23]="/usr/lib/jvm/java-23-openjdk" + +# ----------------------------------------------------------------------------- +# known maven versions +aMaven["3.9.8"]="/opt/apache-maven-3.9.8" +aMaven["3.9.9"]="/opt/apache-maven-3.9.9" + +# -----------------------------------------------------------------------------