From a0c582928f1b4a2a0e1b19ac60fab097516b9615 Mon Sep 17 00:00:00 2001 From: Mriyam Tamuli Date: Wed, 24 Jan 2018 14:38:58 +0530 Subject: [PATCH] Add update command and update paths in setup script Signed-off-by: Mriyam Tamuli --- scripts/ee4 | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-- scripts/setup | 9 +++++---- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/scripts/ee4 b/scripts/ee4 index a5bff85..4476845 100755 --- a/scripts/ee4 +++ b/scripts/ee4 @@ -4,7 +4,6 @@ PROJECT_NAME="ee4" EE_INSTALL_DIR="/opt/$PROJECT_NAME" ETC_HOSTS=/etc/hosts LOCALHOST_IP="127.0.0.1" -WEBROOT="/var/www" # runs the given command as root (detects if we are root already) runAsRoot() { @@ -43,7 +42,9 @@ help () { singleWordPress() { echo "Installing WordPress site $SITE_NAME" - mkdir -p "$WEBROOT" > /dev/null 2>&1 + if ! [[ -d "$WEBROOT" ]]; then + runAsRoot mkdir -p "$WEBROOT" > /dev/null 2>&1 + fi ### # Setup site configuration @@ -195,6 +196,31 @@ fail_trap() { exit $result } +initEE4() { + if ! [[ -d ~/.ee4 ]]; then + mkdir ~/.ee4 + fi + + if [[ $# -eq 0 ]]; then + read -p "Where would you like to create your sites(default: ~/Documents/Sites): " + WEBROOT="${REPLY:-~/Documents/Sites}" + elif [[ $# -eq 1 ]]; then + WEBROOT="$1" + fi + + echo "WEBROOT=$WEBROOT" > ~/.ee4/config +} + +updateEE4() { + REPO_URL="${1:-https://github.com/EasyEngine/docker-compose-wordpress}" + VERSION="${2:-master}" + + echo "git pull -b "$VERSION" "$REPO_URL"" + + pushd "$EE_INSTALL_DIR" > /dev/null 2>&1 + git pull "$REPO_URL" "$VERSION" + popd > /dev/null 2>&1 +} # Execution @@ -202,6 +228,8 @@ fail_trap() { trap "fail_trap" EXIT set -e +[[ -f ~/.ee4/config ]] && source ~/.ee4/config || initEE4 + # Parsing input arguments (if any) export INPUT_ARGUMENTS="${@}" set -u @@ -254,6 +282,14 @@ while [[ $# -gt 0 ]]; do exit 0 fi ;; + 'init') + shift + if [[ $# -ne 0 ]]; then + initEE4 $1 + else + initEE4 + fi + ;; 'restart') shift if [[ $# -ne 0 ]]; then @@ -264,6 +300,20 @@ while [[ $# -gt 0 ]]; do exit 0 fi ;; + 'update') + shift + if [[ $# -eq 0 ]]; then + updateEE4 + exit 0 + elif [[ $# -eq 1 ]]; then + #statements + updateEE4 $1 master + exit 0 + elif [[ $# -eq 2 ]]; then + updateEE4 $1 $2 + exit 0 + fi + ;; 'wp') shift if [[ $# -ne 0 ]]; then diff --git a/scripts/setup b/scripts/setup index c900ab0..de9040c 100755 --- a/scripts/setup +++ b/scripts/setup @@ -1,8 +1,9 @@ #!/usr/bin/env bash PROJECT_NAME="ee4" -REPO_URL="https://github.com/EasyEngine/docker-compose-wordpress" -VERSION="master" +REPO_URL="${REPO_URL:-https://github.com/EasyEngine/docker-compose-wordpress}" +VERSION="${VERSION:-master}" + # runs the given command as root (detects if we are root already) runAsRoot() { @@ -62,9 +63,9 @@ cloneRepo() { # installScript installs the main script. installScript() { - EE_INSTALL_DIR="/opt/$PROJECT_NAME" + EE_INSTALL_DIR="${EE_INSTALL_DIR:-/opt/$PROJECT_NAME}" EE_SCRIPT="scripts/ee4" - EE_SCRIPT_INSTALL_PATH="/usr/local/bin/ee4" + EE_SCRIPT_INSTALL_PATH="${EE_SCRIPT_INSTALL_PATH:-/usr/local/bin/ee4}" rm -rf "$EE_INSTALL_DIR" echo "Preparing to install into $EE_INSTALL_DIR"