|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Script to remove part of the EESSI software stack (version set through init/eessi_defaults) |
| 4 | + |
| 5 | +# see example parsing of command line arguments at |
| 6 | +# https://wiki.bash-hackers.org/scripting/posparams#using_a_while_loop |
| 7 | +# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash |
| 8 | + |
| 9 | +display_help() { |
| 10 | + echo "usage: $0 [OPTIONS]" |
| 11 | + echo " -g | --generic - instructs script to build for generic architecture target" |
| 12 | + echo " -h | --help - display this usage information" |
| 13 | +} |
| 14 | + |
| 15 | +POSITIONAL_ARGS=() |
| 16 | + |
| 17 | +while [[ $# -gt 0 ]]; do |
| 18 | + case $1 in |
| 19 | + -g|--generic) |
| 20 | + DETECTION_PARAMETERS="--generic" |
| 21 | + shift |
| 22 | + ;; |
| 23 | + -h|--help) |
| 24 | + display_help # Call your function |
| 25 | + # no shifting needed here, we're done. |
| 26 | + exit 0 |
| 27 | + ;; |
| 28 | + -*|--*) |
| 29 | + echo "Error: Unknown option: $1" >&2 |
| 30 | + exit 1 |
| 31 | + ;; |
| 32 | + *) # No more options |
| 33 | + POSITIONAL_ARGS+=("$1") # save positional arg |
| 34 | + shift |
| 35 | + ;; |
| 36 | + esac |
| 37 | +done |
| 38 | + |
| 39 | +set -- "${POSITIONAL_ARGS[@]}" |
| 40 | + |
| 41 | +TOPDIR=$(dirname $(realpath $0)) |
| 42 | + |
| 43 | +export TMPDIR=$(mktemp -d /tmp/eessi-remove.XXXXXXXX) |
| 44 | + |
| 45 | +source $TOPDIR/scripts/utils.sh |
| 46 | + |
| 47 | +echo ">> Determining software subdirectory to use for current build host..." |
| 48 | +if [ -z $EESSI_SOFTWARE_SUBDIR_OVERRIDE ]; then |
| 49 | + export EESSI_SOFTWARE_SUBDIR_OVERRIDE=$(python3 $TOPDIR/eessi_software_subdir.py $DETECTION_PARAMETERS) |
| 50 | + echo ">> Determined \$EESSI_SOFTWARE_SUBDIR_OVERRIDE via 'eessi_software_subdir.py $DETECTION_PARAMETERS' script" |
| 51 | +else |
| 52 | + echo ">> Picking up pre-defined \$EESSI_SOFTWARE_SUBDIR_OVERRIDE: ${EESSI_SOFTWARE_SUBDIR_OVERRIDE}" |
| 53 | +fi |
| 54 | + |
| 55 | +echo ">> Setting up environment..." |
| 56 | + |
| 57 | +source $TOPDIR/init/bash |
| 58 | + |
| 59 | +if [ -d $EESSI_CVMFS_REPO ]; then |
| 60 | + echo_green "$EESSI_CVMFS_REPO available, OK!" |
| 61 | +else |
| 62 | + fatal_error "$EESSI_CVMFS_REPO is not available!" |
| 63 | +fi |
| 64 | + |
| 65 | +if [[ -z ${EESSI_SOFTWARE_SUBDIR} ]]; then |
| 66 | + fatal_error "Failed to determine software subdirectory?!" |
| 67 | +elif [[ "${EESSI_SOFTWARE_SUBDIR}" != "${EESSI_SOFTWARE_SUBDIR_OVERRIDE}" ]]; then |
| 68 | + fatal_error "Values for EESSI_SOFTWARE_SUBDIR_OVERRIDE (${EESSI_SOFTWARE_SUBDIR_OVERRIDE}) and EESSI_SOFTWARE_SUBDIR (${EESSI_SOFTWARE_SUBDIR}) differ!" |
| 69 | +else |
| 70 | + echo_green ">> Using ${EESSI_SOFTWARE_SUBDIR} as software subdirectory!" |
| 71 | +fi |
| 72 | + |
| 73 | +echo ">> Configuring EasyBuild..." |
| 74 | +EB="eb" |
| 75 | +source $TOPDIR/configure_easybuild |
| 76 | + |
| 77 | +echo ">> Setting up \$MODULEPATH..." |
| 78 | +# make sure no modules are loaded |
| 79 | +module --force purge |
| 80 | +# ignore current $MODULEPATH entirely |
| 81 | +module unuse $MODULEPATH |
| 82 | +module use $EASYBUILD_INSTALLPATH/modules/all |
| 83 | +if [[ -z ${MODULEPATH} ]]; then |
| 84 | + fatal_error "Failed to set up \$MODULEPATH?!" |
| 85 | +else |
| 86 | + echo_green ">> MODULEPATH set up: ${MODULEPATH}" |
| 87 | +fi |
| 88 | + |
| 89 | +# assume there's only one diff file that corresponds to the PR patch file |
| 90 | +pr_diff=$(ls [0-9]*.diff | head -1) |
| 91 | + |
| 92 | +# if this script is run as root, use PR patch file to determine if software needs to be removed first |
| 93 | +if [ $EUID -eq 0 ]; then |
| 94 | + changed_easystacks_rebuilds=$(cat ${pr_diff} | grep '^+++' | cut -f2 -d' ' | sed 's@^[a-z]/@@g' | grep '^easystacks/.*yml$' | egrep -v 'known-issues|missing' | grep "/rebuilds/") |
| 95 | + if [ -z ${changed_easystacks_rebuilds} ]; then |
| 96 | + echo "No software needs to be removed." |
| 97 | + else |
| 98 | + for easystack_file in ${changed_easystacks_rebuilds}; do |
| 99 | + # determine version of EasyBuild module to load based on EasyBuild version included in name of easystack file |
| 100 | + eb_version=$(echo ${easystack_file} | sed 's/.*eb-\([0-9.]*\).*/\1/g') |
| 101 | + |
| 102 | + # load EasyBuild module (will be installed if it's not available yet) |
| 103 | + source ${TOPDIR}/load_easybuild_module.sh ${eb_version} |
| 104 | + |
| 105 | + if [ -f ${easystack_file} ]; then |
| 106 | + echo_green "Software rebuild(s) requested in ${easystack_file}, so determining which existing installation have to be removed..." |
| 107 | + # we need to remove existing installation directories first, |
| 108 | + # so let's figure out which modules have to be rebuilt by doing a dry-run and grepping "someapp/someversion" for the relevant lines (with [R]) |
| 109 | + # * [R] $CFGS/s/someapp/someapp-someversion.eb (module: someapp/someversion) |
| 110 | + rebuild_apps=$(eb --allow-use-as-root-and-accept-consequences --dry-run-short --rebuild --easystack ${easystack_file} | grep "^ \* \[R\]" | grep -o "module: .*[^)]" | awk '{print $2}') |
| 111 | + for app in ${rebuild_apps}; do |
| 112 | + app_dir=${EASYBUILD_INSTALLPATH}/software/${app} |
| 113 | + app_module=${EASYBUILD_INSTALLPATH}/modules/all/${app}.lua |
| 114 | + echo_yellow "Removing ${app_dir} and ${app_module}..." |
| 115 | + rm -rf ${app_dir} |
| 116 | + rm -rf ${app_module} |
| 117 | + done |
| 118 | + else |
| 119 | + fatal_error "Easystack file ${easystack_file} not found!" |
| 120 | + fi |
| 121 | + done |
| 122 | + fi |
| 123 | +else |
| 124 | + fatal_error "This script can only be run by root!" |
| 125 | +fi |
0 commit comments