|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Stop in case of error |
| 4 | +set -e |
| 5 | + |
| 6 | +# Print script help |
| 7 | +print_usage() |
| 8 | +{ |
| 9 | + echo "Checkout develop branch of all EasyBuild repositories" |
| 10 | + echo "and pull changes from the remote repository." |
| 11 | + echo "To be used with the EasyBuild-develop module or a set git-working-dirs-path" |
| 12 | + echo "Usage: $0 [<git_dir>]" |
| 13 | + echo |
| 14 | + echo " git_dir: directory where all the EasyBuild repositories are installed." |
| 15 | + echo " Automatically detected if not specified." |
| 16 | + echo |
| 17 | +} |
| 18 | + |
| 19 | +if [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then |
| 20 | + print_usage |
| 21 | + exit 0 |
| 22 | +fi |
| 23 | + |
| 24 | +if [[ $# -gt 1 ]] ; then |
| 25 | + echo "Error: invalid arguments" |
| 26 | + echo |
| 27 | + print_usage |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +if [[ $# -eq 1 ]]; then |
| 32 | + git_dir=$1 |
| 33 | +else |
| 34 | + # Auto detect git_dir |
| 35 | + git_dir="" |
| 36 | + if ! which eb &> /dev/null; then |
| 37 | + module load EasyBuild-develop || module load EasyBuild || true |
| 38 | + if ! which eb &> /dev/null; then |
| 39 | + echo 'Found neither the `eb` command nor a working module.' |
| 40 | + echo 'Please specify the git_dir!' |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + fi |
| 44 | + if out=$(eb --show-config | grep -F 'git-working-dirs-path'); then |
| 45 | + path=$(echo "$out" | awk '{print $NF}') |
| 46 | + if [[ -n "$path" ]] && [[ -d "$path" ]]; then |
| 47 | + git_dir=$path |
| 48 | + echo "Using git_dir from git-working-dirs-path: $git_dir" |
| 49 | + fi |
| 50 | + fi |
| 51 | + if [[ -z "$git_dir" ]]; then |
| 52 | + eb_dir=$(dirname "$(which eb)") |
| 53 | + if [[ "$(basename "$eb_dir")" == "easybuild-framework" ]] && [[ -d "$eb_dir/.git" ]]; then |
| 54 | + git_dir=$(dirname "$eb_dir") |
| 55 | + echo "Using git_dir from eb command: $git_dir" |
| 56 | + else |
| 57 | + echo 'Please specify the git_dir as auto-detection failed!' |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + fi |
| 61 | +fi |
| 62 | + |
| 63 | +cd "$git_dir" |
| 64 | + |
| 65 | +for folder in easybuild easybuild-framework easybuild-easyblocks easybuild-easyconfigs; do |
| 66 | + echo # A newline |
| 67 | + if [[ -d "$folder" ]]; then |
| 68 | + echo "========= Checking ${folder} =========" |
| 69 | + else |
| 70 | + echo "========= Skipping non-existent ${folder} =========" |
| 71 | + fi |
| 72 | + cd "$folder" |
| 73 | + git checkout "develop" |
| 74 | + if git remote | grep -qF github_easybuilders; then |
| 75 | + git pull "github_easybuilders" |
| 76 | + else |
| 77 | + git pull |
| 78 | + fi |
| 79 | + cd .. |
| 80 | +done |
| 81 | + |
| 82 | +index_file="$git_dir/easybuild-easyconfigs/easybuild/easyconfigs/.eb-path-index" |
| 83 | +if [[ -f "$index_file" ]]; then |
| 84 | + echo -n "Trying to remove index from ${index_file}..." |
| 85 | + if rm "$index_file"; then |
| 86 | + echo "Done!" |
| 87 | + echo "Recreate with 'eb --create-index \"$(dirname "$index_file")\"'" |
| 88 | + else |
| 89 | + echo "Failed!" |
| 90 | + fi |
| 91 | +fi |
0 commit comments