From a8dee04e72163665636a34b1b86c4d4c7120ab35 Mon Sep 17 00:00:00 2001 From: Dimitris Papagiannis Date: Wed, 19 Jun 2024 14:25:12 +0200 Subject: [PATCH] Add the capability to specify and apply multiple dmwm/deployment PRs via DMWM_PRS --- deploy_dqmgui.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/deploy_dqmgui.sh b/deploy_dqmgui.sh index 905ee0c..195704c 100755 --- a/deploy_dqmgui.sh +++ b/deploy_dqmgui.sh @@ -46,6 +46,10 @@ source $SCRIPT_DIR/config.sh TMP_BASE_PATH=/tmp +DMWM_PRS_URL_BASE="https://github.com/dmwm/deployment/pull" +# Comma-separated DMWM PRs to apply. E.g., 1312,1315 +DMWM_PRS= + # Function to sanitize args to a folder name # From here: https://stackoverflow.com/a/44811468/6562491 # echoes "null" if no input given. @@ -82,8 +86,37 @@ preliminary_checks() { echo "WARNING: $INSTALLATION_DIR/$DMWM_GIT_TAG exists, deleting contents" rm -rf "${INSTALLATION_DIR:?}/${DMWM_GIT_TAG:?}/*" fi -} + if [ -n "$DMWM_PRS" ]; then + # If there are PRs to apply, check if patch is available locally + if ! command -v patch >/dev/null; then + echo "ERROR: PRs to apply were specified but the patch command is not available" + exit 1 + fi + OLD_IFS=$IFS + IFS=',' + # Split PRs with commas + for pr in $DMWM_PRS; do + # Each should be a number + if ! [[ "$pr" =~ ^[0-9]+$ ]]; then + echo "ERROR: $pr is not a valid PR number" + exit 1 + fi + # Did not find diff locally, try downloading it + if ! _find_patch $pr >/dev/null; then + if ! command -v curl >/dev/null; then + echo "ERROR: $pr not available locally and curl is not installed" + fi + echo "INFO: Did not find $pr diff locally, trying downloading it from $DMWM_PRS_URL_BASE" + if ! curl --silent -L "${DMWM_PRS_URL_BASE}/${pr}.diff" >"/tmp/${pr}.diff"; then + echo "ERROR: Could not download diff for PR $pr from $DMWM_PRS_URL_BASE" + exit 1 + fi + fi + done + IFS=$OLD_IFS + fi +} # Check for needed OS-wide dependencies check_dependencies() { # Read in the required packages @@ -309,16 +342,13 @@ install_classlib() { install_boost_gil() { mkdir -p $INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/ tar -xzf "$SCRIPT_DIR/boost_gil/boost_gil.tar.gz" -C "${TMP_BASE_PATH}" - rm -rf "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost" # Cleanup dir if exists mv "${TMP_BASE_PATH}/boost_gil/include/boost" "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost" } install_gil_numeric() { - tar -xzf "$SCRIPT_DIR/numeric/numeric.tar.gz" -C "${TMP_BASE_PATH}" mkdir -p "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost/gil/extension/" - rm -rf "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost/gil/extension/numeric" # Cleanup dir if exists mv "$NUMERIC_TMP_DIR" "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost/gil/extension/numeric" } @@ -350,6 +380,44 @@ install_dmwm() { rm -rf $DMWM_TMP_DIR } +# Tries to look for a .patch or .diff in /tmp or /globalscratch +# Returns nothing if it wasn't found. +_find_patch() { + pr_num=${1?} + dirs_to_check=("/tmp" "/globalscratch") + valid_extensions=(".patch" ".diff") + for dir in "${dirs_to_check[@]}"; do + for extension in "${valid_extensions[@]}"; do + patch_filename="${pr_num}${extension}" + patch_filepath="${dir}/${patch_filename}" + if [ -f "$patch_filepath" ]; then + echo "$patch_filepath" + return 0 + fi + done + done + return 1 +} + +# Apply patches to DMWM. Assumes that the patches are avilable +patch_dmwm() { + OLD_IFS=$IFS + IFS=',' + cd $DMWM_TMP_DIR + for pr in $DMWM_PRS; do + echo "INFO: Looking for the PR $pr patch" + patch_filepath="$(_find_patch $pr)" + if [ -z "$patch_filepath" ]; then + echo "ERROR: Could not find patch for PR $pr" + return 1 + fi + echo "INFO: Applying $patch_filepath" + patch -p1 <"$patch_filepath" + done + IFS=$OLD_IFS + cd - +} + # Create a configuration file for logrotate to manage...(surprise!) rotating logs. _create_logrotate_conf() { echo "# DQMGUI logrotate configuration file @@ -602,6 +670,7 @@ declare -a installation_steps=(preliminary_checks install_classlib compile_classlib extract_dmwm + patch_dmwm install_dmwm install_root compile_root