From c5585f4edf58c152e04dfd223571c384d996e1b3 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Tue, 18 Feb 2025 16:45:32 +0100 Subject: [PATCH 1/3] add env_init script --- shellscripts/env_init.sh | 109 ++++++++++++++++++++++++++++++ shellscripts/env_init.sh.cfg.dist | 11 +++ 2 files changed, 120 insertions(+) create mode 100755 shellscripts/env_init.sh create mode 100644 shellscripts/env_init.sh.cfg.dist diff --git a/shellscripts/env_init.sh b/shellscripts/env_init.sh new file mode 100755 index 00000000..2449d990 --- /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 00000000..1e3a8de7 --- /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" + +# ----------------------------------------------------------------------------- -- GitLab From e25ea5e0169ada0bf18ad4eab8f6aa011513c8ee Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Tue, 18 Feb 2025 16:50:52 +0100 Subject: [PATCH 2/3] add variable $ENVINIT for onbuild tasks --- public_html/deployment/classes/project.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index 3b7e633a..1d5157c7 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']; -- GitLab From cca93ac68e27dba1f89f36902a1039694eeacfe8 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Tue, 18 Feb 2025 16:57:03 +0100 Subject: [PATCH 3/3] add template for environments --- hooks/templates/env_init.sh.cfg.erb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 hooks/templates/env_init.sh.cfg.erb diff --git a/hooks/templates/env_init.sh.cfg.erb b/hooks/templates/env_init.sh.cfg.erb new file mode 100644 index 00000000..f1527930 --- /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"] %> + +# ----------------------------------------------------------------------------- -- GitLab