Skip to content

Commit

Permalink
polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
truib committed May 6, 2024
1 parent 29a3933 commit 6242919
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 45 deletions.
1 change: 0 additions & 1 deletion EESSI-determine-rebuilds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ else
app_dir=${EASYBUILD_INSTALLPATH}/software/${app}
app_module=${EASYBUILD_INSTALLPATH}/modules/all/${app}.lua
echo_yellow "Removing ${app_dir} and ${app_module}..."
# echo "REMOVE_SOFTWARE ${app_dir}"
find ${app_dir} -type d | sed -e 's/^/REMOVE_DIRECTORY /'
find ${app_dir} -type f | sed -e 's/^/REMOVE_FILE /'
echo "REMOVE_MODULE ${app_module}"
Expand Down
71 changes: 30 additions & 41 deletions EESSI-remove-software.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,35 @@ fi
# assume there's only one diff file that corresponds to the PR patch file
pr_diff=$(ls [0-9]*.diff | head -1)

# if this script is run as root, use PR patch file to determine if software needs to be removed first
# if [ $EUID -eq 0 ]; then
# working around lacking support for `--fakeroot` and/or user namespaces
# we only run as non-root
if [ $EUID -ne 0 ]; then
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/")
if [ -z ${changed_easystacks_rebuilds} ]; then
echo "No software needs to be removed."
else
for easystack_file in ${changed_easystacks_rebuilds}; do
# determine version of EasyBuild module to load based on EasyBuild version included in name of easystack file
eb_version=$(echo ${easystack_file} | sed 's/.*eb-\([0-9.]*\).*/\1/g')

# load EasyBuild module (will be installed if it's not available yet)
source ${TOPDIR}/load_easybuild_module.sh ${eb_version}

if [ -f ${easystack_file} ]; then
echo_green "Software rebuild(s) requested in ${easystack_file}, so determining which existing installation have to be removed..."
# we need to remove existing installation directories first,
# 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])
# * [R] $CFGS/s/someapp/someapp-someversion.eb (module: someapp/someversion)
# 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}')
# we cannot run as root so we removed `--allow-use-as-root...`
rebuild_apps=$(eb --dry-run-short --rebuild --easystack ${easystack_file} | grep "^ \* \[R\]" | grep -o "module: .*[^)]" | awk '{print $2}')
for app in ${rebuild_apps}; do
app_dir=${EASYBUILD_INSTALLPATH}/software/${app}
app_module=${EASYBUILD_INSTALLPATH}/modules/all/${app}.lua
echo_yellow "Removing ${app_dir} and ${app_module}..."
ls -lR ${app_dir}
rm -rdfv ${app_dir}
rm -rdfv ${app_module}
done
else
fatal_error "Easystack file ${easystack_file} not found!"
fi
done
fi
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/")
if [ -z ${changed_easystacks_rebuilds} ]; then
echo "No software needs to be removed."
else
fatal_error "This script can NOT be run by root! (lacking support for `--fakeroot` and/or user namespaces)"
for easystack_file in ${changed_easystacks_rebuilds}; do
# determine version of EasyBuild module to load based on EasyBuild version included in name of easystack file
eb_version=$(echo ${easystack_file} | sed 's/.*eb-\([0-9.]*\).*/\1/g')

# load EasyBuild module (will be installed if it's not available yet)
source ${TOPDIR}/load_easybuild_module.sh ${eb_version}

if [ -f ${easystack_file} ]; then
echo_green "Software rebuild(s) requested in ${easystack_file}, so"
echo_green " determining which existing installation have to be removed (assuming contents"
echo_green " have been made writable/deletable)..."
# we need to remove existing installation directories first,
# 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])
# * [R] $CFGS/s/someapp/someapp-someversion.eb (module: someapp/someversion)
# 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}')
rebuild_apps=$(eb --dry-run-short --rebuild --easystack ${easystack_file} | grep "^ \* \[R\]" | grep -o "module: .*[^)]" | awk '{print $2}')
for app in ${rebuild_apps}; do
app_dir=${EASYBUILD_INSTALLPATH}/software/${app}
app_module=${EASYBUILD_INSTALLPATH}/modules/all/${app}.lua
echo_yellow "Removing ${app_dir} and ${app_module}..."
rm -rdfv ${app_dir}
rm -rdfv ${app_module}
done
else
fatal_error "Easystack file ${easystack_file} not found!"
fi
done
fi
# else
# fatal_error "This script can only be run by root!"
# fi
10 changes: 7 additions & 3 deletions bot/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,25 @@ else
# create a new directory ${STORAGE}/lower_dirs/some_path_stripped
# where the prefix /cvmfs/repo_name is removed from some_path
# set permission of the directory to u+rwx
# add directory to LOWER_DIRS (':' separated list of directories)
# for each line containing 'REMOVE_FILE some_file_path'
# touch a new file ${STORAGE}/lower_dirs/some_file_path_stripped
# where the prefix /cvmfs/repo_name is removed from some_file_path
# set permission of the file to u+rw

LOWER_DIRS="${STORAGE}/lower_dirs"
mkdir -p "${LOWER_DIRS}"

grep ^REMOVE_DIRECTORY ${determine_outerr} | cut -f4- -d'/' > ${determine_outerr}.rm_dirs
cat ${determine_outerr}.rm_dirs | while read remove_dir; do
# echo "PROCESS directory: --${remove_dir}--"
mkdir -p ${STORAGE}/lower_dirs/${remove_dir}
chmod u+rwx ${STORAGE}/lower_dirs/${remove_dir}
done

grep ^REMOVE_FILE ${determine_outerr} | cut -f4- -d'/' > ${determine_outerr}.rm_files
cat ${determine_outerr}.rm_files | while read remove_file; do
touch ${STORAGE}/lower_dirs/${remove_file}
chmod u+rw ${STORAGE}/lower_dirs/${remove_file}
done
# ls -lR "${STORAGE}/lower_dirs"

# prepare directory to store tarball of tmp for removal and build steps
TARBALL_TMP_REMOVAL_STEP_DIR=${PREVIOUS_TMP_DIR}/removal_step
Expand Down

0 comments on commit 6242919

Please sign in to comment.