Skip to content

Instantly share code, notes, and snippets.

@jmaupetit
Last active November 29, 2021 10:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmaupetit/7bd327a595ba0d3f332883dab7db6b94 to your computer and use it in GitHub Desktop.
Save jmaupetit/7bd327a595ba0d3f332883dab7db6b94 to your computer and use it in GitHub Desktop.
Perform actions in France Université Numerique data stack (for local development purpose)
#!/usr/bin/env bash
# Install this script somewhere in your $PATH
# Configurations
declare REPOSITORIES_ROOT_DIR="${HOME}/Work/fun"
declare -a REPOSITORIES=(potsie ralph learning-analytics-playground)
# Terminal colors
declare -r COLOR_BLUE='\033[0;36m'
declare -r COLOR_ORANGE='\033[0;33m'
declare -r COLOR_RESET='\033[0m'
# Utils
function usage(){
declare -i exit_code="${1:-0}"
echo "Usage: datastack [OPTIONS] COMMAND
OPTIONS:
-h, --help
display program usage
-r, --root
set repositories root directory
COMMANDS:
bootstrap bootstrap data services
run run data services
status get data services statuses
stop stop data services
"
exit "${exit_code}"
}
function _make_foreach_repository() {
local cmd="${1}"
local action="${2}"
for repository in "${REPOSITORIES[@]}"; do
echo -e "\n${COLOR_ORANGE} ===> ${COLOR_BLUE}${action} ${repository}${COLOR_RESET} 🚀\n";
cd "${REPOSITORIES_ROOT_DIR}/${repository}" && \
${cmd};
done
}
# Core functions
function bootstrap() {
echo " 🏁 Bootstrapping data development services..."
_make_foreach_repository "make bootstrap" "Bootstrapping"
}
function run() {
echo " 🏃 Running data development services..."
_make_foreach_repository "make run" "Running"
}
function status() {
echo " 🔎 Getting statuses for data development services..."
_make_foreach_repository "make status" "Getting status for"
}
function stop() {
echo " 🛑 Stopping data development services..."
_make_foreach_repository "make stop" "Stopping"
}
# -- Parse options
OPTS=$(getopt -o "r:h" --long "root:,help" -n "datastack" -- "$@")
eval set -- "$OPTS"
while true; do
case "${1}" in
-r|--root)
REPOSITORIES_ROOT_DIR="${2}"
shift 2;;
-h|--help)
usage 0;;
--)
shift; break;;
*)
echo "Invalid option, see usage (-h)."
exit 1;;
esac
done
# Print usage if no COMMAND has been passed
if [[ -z "${1}" ]]; then
usage 1
fi
echo -e "${COLOR_BLUE}
__ __ __ __
| \\ | \\ | \\ | \\
____| ▓▓ ______ _| ▓▓_ ______ _______ _| ▓▓_ ______ _______| ▓▓ __
/ ▓▓| \\| ▓▓ \\ | \\ / \\ ▓▓ \\ | \\ / \\ ▓▓ / \\
| ▓▓▓▓▓▓▓ \\▓▓▓▓▓▓\\\\▓▓▓▓▓▓ \\▓▓▓▓▓▓\\ ▓▓▓▓▓▓▓\\▓▓▓▓▓▓ \\▓▓▓▓▓▓\\ ▓▓▓▓▓▓▓ ▓▓_/ ▓▓
| ▓▓ | ▓▓/ ▓▓ | ▓▓ __ / ▓▓\\▓▓ \\ | ▓▓ __ / ▓▓ ▓▓ | ▓▓ ▓▓
| ▓▓__| ▓▓ ▓▓▓▓▓▓▓ | ▓▓| \\ ▓▓▓▓▓▓▓_\\▓▓▓▓▓▓\\ | ▓▓| \\ ▓▓▓▓▓▓▓ ▓▓_____| ▓▓▓▓▓▓\\
\\▓▓ ▓▓\\▓▓ ▓▓ \\▓▓ ▓▓\\▓▓ ▓▓ ▓▓ \\▓▓ ▓▓\\▓▓ ▓▓\\▓▓ \\ ▓▓ \\▓▓\\
\\▓▓▓▓▓▓▓ \\▓▓▓▓▓▓▓ \\▓▓▓▓ \\▓▓▓▓▓▓▓\\▓▓▓▓▓▓▓ \\▓▓▓▓ \\▓▓▓▓▓▓▓ \\▓▓▓▓▓▓▓\\▓▓ \\▓▓
${COLOR_RESET}
📂 Root directory: ${COLOR_BLUE}${REPOSITORIES_ROOT_DIR}${COLOR_RESET}
"
# Perform action
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment