eost_gissmo_tools/launch.sh

145 lines
3.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# CONFIG
## Default
PROGRAM=`basename $0`
GIT_URL="git@github.com:eost/gissmo.git"
GIT_BRANCH="dev" # Default Git Branch
GIT_DIR_NAME="gissmo"
DOCKERFILE_NAME="Dockerfile"
## User
. config || exit 1
## Composed
GISSMO_DIR="${PROJECT_DIR}/${GIT_DIR_NAME}"
DOCKERFILE="${GISSMO_DIR}/${DOCKERFILE_NAME}"
COMMAND="$1"
# METHODS
error_and_continue() {
echo "ERROR: $1"
}
error_and_quit() {
error_and_continue "$1"
exit 0
}
info() {
echo "INFO: $1"
}
not_implemented() {
error_and_quit "Not implemented"
}
show_help() {
echo "$PROGRAM [COMMAND]"
echo -e " Where COMMAND is one of:"
echo -e " - create "
echo -e " - init "
echo -e " - restore "
echo -e " - start "
echo -e " - stop "
}
check_command() {
if test $1 == "create"; then
return 0
elif test $1 == "init"; then
return 0
elif test $1 == "restore"; then
return 0
elif test $1 == "start"; then
return 0
elif test $1 == "stop"; then
return 0
fi
error_and_continue "Unknown command."
show_help
exit 1
}
create() {
init
not_implemented
}
init() {
# check directory existence
if ! test -d "$PROJECT_DIR"; then
mkdir -p "$PROJECT_DIR" || error_and_quit "Create ${PROJECT_DIR} failed."
info "$PROJECT_DIR created."
echo "${PROJECT_DIR} created."
virtualenv -p python3 $PROJECT_DIR || error_and_quit "Create ${PROJECT_DIR} python virtual environment failed."
info "Python virtual environment initialized."
fi
cd $PROJECT_DIR
sudo apt-get install -qq libpq-dev python3-dev python-virtualenv git-core python3-pip || error_and_quit "Dependancies installation failed."
info "Dependancies via apt-get checked/installed."
if ! test -d "$GISSMO_DIR/.git/"; then
git clone -q $GIT_URL $GISSMO_DIR || error_and_quit "Fetch Git repository failed."
else
GIT_WORK_TREE="${GISSMO_DIR}/" GIT_DIR="${GISSMO_DIR}/.git/" git pull -q origin master || error_and_quit "Pull command on Git repository failed."
fi
info "Git repository checked."
. bin/activate || error_and_quit "Failed entering python virtual environment"
cd $GISSMO_DIR
pip install -q -r requirements.txt || error_and_quit "Python dependancies installation failed."
info "Python dependancies checked."
deactivate || error_and_quit "Failed exiting python virtual environment."
}
restore() {
not_implemented
}
start() {
not_implemented
}
stop() {
not_implemented
}
generate_database_persistent_volume() {
not_implemented
}
# CHECK CONFIG
if test -z $PROJECT_DIR; then
error_and_quit "No project directory given."
fi
if test -z $GIT_BRANCH; then
error_and_quit "No git branch given."
fi
# Don't check repository if INIT COMMAND is given
if ! test -d $GIT_REPOSITORY && ! test "$COMMAND" == "init"; then
error_and_quit "Repository don't exists: ${GIT_REPOSITORY}"
fi
if test -z $DOCKERFILE_NAME; then
error_and_quit "No docker filename given."
fi
if ! test -f $DOCKERFILE && ! test "$COMMAND" == "init"; then
error_and_quit "Docker file don't exists: ${DOCKERFILE}"
fi
if ! test -z $COMMAND; then
check_command "$COMMAND"
$COMMAND
else
show_help
fi
exit 1