Created
May 12, 2020 16:49
-
-
Save kunathj/823402207fb72a7ffccb07960db26af3 to your computer and use it in GitHub Desktop.
Manage the ILD software environment additions on my machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
help=""" | |
############################################################################## | |
# | |
# The script expects to be called with one of the following options: | |
# | |
# setup, status, pull, push. | |
# | |
# The goal is to stitch together the multiple parts that together form my | |
# software environment for the work with ILD. | |
# | |
############################################################################## | |
""" | |
#----------------------------------------------------------------------------- | |
# List the (git) repositories that consitute the environment. | |
projects=( | |
"Jonas-CEDViewer" | |
"reference-sample" | |
"scratches" | |
"ZH" | |
"Ztau-identification" | |
) | |
tools=( | |
"pySteer" | |
"toolbox-iLCSoft" | |
) | |
#----------------------------------------------------------------------------- | |
# The directory structure. | |
HEAD_DIR=$PWD | |
PROJECTS_DIR=$HEAD_DIR/projects | |
DATA_DIR=$HEAD_DIR/data | |
TOOLS_DIR=$HEAD_DIR/myLCSoft | |
LOCAL_REPOS=() | |
for name in "${projects[@]}"; do | |
LOCAL_REPOS+=("$PROJECTS_DIR/${name}") | |
done | |
for name in "${tools[@]}"; do | |
LOCAL_REPOS+=("$TOOLS_DIR/${name}") | |
done | |
#----------------------------------------------------------------------------- | |
# Initial setup functionality. | |
data_skeleton() { | |
printf "\n-- Set up the skeleton for the data directory.\n" | |
mkdir -p ${DATA_DIR} | |
for name in "${projects[@]}"; do | |
mkdir -p "${DATA_DIR}/${name}" | |
ln -s "${DATA_DIR}/${name}" "${PROJECTS_DIR}/${name}/data" | |
done | |
printf "\n!!\n!!The data files must be manually put into the folder.\n!!\n\n" | |
} | |
git_clone() { | |
printf "\n-- Try to clone the projects and tools.\n" | |
mkdir -p ${PROJECTS_DIR} | |
cd ${PROJECTS_DIR} | |
for reponame in "${projects[@]}"; do | |
git clone git@github.com:kunathj/$reponame.git | |
done | |
mkdir -p ${TOOLS_DIR} | |
cd ${TOOLS_DIR} | |
for reponame in "${tools[@]}"; do | |
git clone git@github.com:kunathj/$reponame.git | |
done | |
cd $HEAD_DIR | |
} | |
#----------------------------------------------------------------------------- | |
# Git command extende to multi-repo use. | |
git_status() { | |
printf "\n-- Git status.\n" | |
for repo in "${LOCAL_REPOS[@]}"; do | |
if [ -d "$repo" ]; then | |
cd $repo | |
printf "\n- $(basename $PWD):\n" | |
git status | |
else | |
printf "\n$repo does not exist.\n" | |
fi | |
done | |
cd $HEAD_DIR | |
} | |
git_pull() { | |
printf "\n-- Pull all.\n" | |
for repo in "${LOCAL_REPOS[@]}"; do | |
cd $repo | |
printf "$(basename $PWD): " | |
git pull | |
done | |
cd $HEAD_DIR | |
} | |
git_push() { | |
printf "\n-- Push all.\n" | |
for repo in "${LOCAL_REPOS[@]}"; do | |
cd $repo | |
printf "$(basename $PWD): " | |
git push | |
done | |
cd $HEAD_DIR | |
} | |
#----------------------------------------------------------------------------- | |
# Envoke different actions depending on the user input. | |
case $1 in | |
"setup") | |
git_clone | |
#data_skeleton | |
git_pull | |
;; | |
"status") | |
git_status | |
;; | |
"pull") | |
git_pull | |
;; | |
"push") | |
git_push | |
;; | |
*) | |
echo "The keyword '$1' is not one of the expected values for the script." | |
printf "${help}\n" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment