From f58f99a0d7ddbc2aaffcfaebe71325afe9ba9c42 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Tue, 12 Jan 2016 15:03:52 +0100 Subject: [PATCH] [ADD] LAUNCH script: Create initial code with "init" command. --- config | 4 ++ launch.sh | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 config create mode 100755 launch.sh diff --git a/config b/config new file mode 100644 index 0000000..ba7eebb --- /dev/null +++ b/config @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + + +PROJECT_DIR="/home/olivier/gissmo_project" diff --git a/launch.sh b/launch.sh new file mode 100755 index 0000000..730e8e3 --- /dev/null +++ b/launch.sh @@ -0,0 +1,144 @@ +#!/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