diff --git a/scripts/cvmfs/setup.sh b/scripts/cvmfs/setup.sh new file mode 100644 index 00000000..3155431b --- /dev/null +++ b/scripts/cvmfs/setup.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash + +# This script sets up the Key4hep software stack from CVMFS depending on its +# location it either uses the nightlies or the releases + +SCRIPT_SOURCE=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd) +SCRIPT_BASE_DIR=$(dirname "${SCRIPT_SOURCE}") + +function _setup_script_usage() { + echo "_Setup_Script_Usage: source ${SCRIPT_SOURCE} [-r ] [--list-releases [distribution]] [--list-packages [distribution]]" + echo " -r , --release : setup a specific release, if not specified the latest release will be used (also used for --list-packages)" + echo " -h, --help : print this help message" + echo " --list-releases [distribution] : list available releases for the specified distribution (almalinux, centos, ubuntu). By default (no OS is specified) it will list the releases for the detected distribution" + echo " --list-packages [distribution] : list available packages and their versions for the specified distribution (almalinux, centos, ubuntu). By default (no OS is specified) it will list the packages for the detected distribution" +} + +function _k4_check_release() { + local release=${1} + local os=${2} + if [[ ! -d "/cvmfs/sw-nightlies.hsf.org/key4hep/releases/${release}" || -z "$(ls "/cvmfs/sw-nightlies.hsf.org/key4hep/releases/${release}" | grep ${os})" ]]; then + echo "Release ${release} not found, this is a list of the available releases:" + find /cvmfs/sw-nightlies.hsf.org/key4hep/releases/ -maxdepth 2 -type d -name "*${os}*" | awk -F/ '{print $(NF-1)}' | sort + echo "Aborting..." + return 1 + fi + return 0 +} + +function _k4_setup_list_releases() { + local os=$1 + if [ "$os" = "almalinux" ] || [ "$os" = "almalinux9" ]; then + name="almalinux9" + elif [ "$os" = "centos" ] || [ "$os" = "centos7" ]; then + name="centos7" + elif [ "$os" = "ubuntu" ] || [ "$os" = "ubuntu22" ]; then + name="ubuntu22" + else + echo "Unsupported OS, aborting..." + _setup_script_usage + return 1 + fi + find ${SCRIPT_BASE_DIR}/releases/ -maxdepth 2 -type d -name "*$name*" | + \awk -F/ '{print $(NF-1)}' | sort +} + +function _k4_setup_list_packages() { + local os=$1 + if [ "$os" = "almalinux" ] || [ "$os" = "almalinux9" ]; then + name="almalinux9" + elif [ "$os" = "centos" ] || [ "$os" = "centos7" ]; then + name="centos7" + elif [ "$os" = "ubuntu" ] || [ "$os" = "ubuntu22" ]; then + name="ubuntu22" + else + echo "Unsupported OS, aborting..." + _setup_script_usage + return 1 + fi + find ${SCRIPT_BASE_DIR}/releases/$rel/*$name*/ -maxdepth 2 -mindepth 2 -not -path '*/\.*' -type d | awk -F/ '{if ($NF ~ /develop/) printf "%s develop", $(NF-1); else {split($(NF),arr,"-"); printf "%s ", $(NF-1); printf "%s", arr[1]; for (i=2; i