From 6c1a364864694fcf4b922e13f09f8ed61543570a Mon Sep 17 00:00:00 2001 From: David Stephens Date: Mon, 22 Aug 2016 22:55:05 +0100 Subject: [PATCH 1/2] First stab at an ENiGMA installer --- misc/install.sh | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 misc/install.sh diff --git a/misc/install.sh b/misc/install.sh new file mode 100755 index 00000000..1603c62a --- /dev/null +++ b/misc/install.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +ENIGMA_NODE_VERSION=4.4 +ENIGMA_INSTALL_DIR=$HOME/enigma-bbs +ENIGMA_SOURCE=https://github.com/NuSkooler/enigma-bbs.git +TIME_FORMAT=`date "+%Y-%m-%d %H:%M:%S"` + +enigma_header() { + cat << EndOfMessage + ______ +_____________________ _____ ____________________ __________\\_ / +\\__ ____/\\_ ____ \\ /____/ / _____ __ \\ / ______/ // /___jp! + // __|___// | \\// |// | \\// | | \\// \\ /___ /_____ +/____ _____| __________ ___|__| ____| \\ / _____ \\ +---- \\______\\ -- |______\\ ------ /______/ ---- |______\\ - |______\\ /__/ // ___/ + /__ _\\ + <*> ENiGMA½ // https://github.com/NuSkooler/enigma-bbs <*> /__/ + +This script will install Node 4.4 via nvm, download Enigma½, install its dependencies, +then run the config generator for you. If this isn't what you were expecting, hit ctrl-c now. + +If you already have nvm installed, this will update it to the latest version. + +EndOfMessage + read -p ">> Hit Enter To Continue <<" +} + +enigma_install_needs() { + command -v $1 >/dev/null 2>&1 || { log_error "ENiGMA½ requires $1 but it's not installed. Please install it and restart the installer."; exit 1; } +} + +log() { + printf "${TIME_FORMAT} %b\n" "$*"; +} + +log_error() { + printf "${TIME_FORMAT} \e[41mERROR:\033[0m %b\n" "$*" >&2; +} + +enigma_install_init() { + log "Checking git installation" + enigma_install_needs git + + log "Checking curl installation" + enigma_install_needs curl +} + +install_nvm() { + log "Installing nvm" + curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash +} + +configure_nvm() { + log "Installing Node ${ENIGMA_NODE_VERSION} via nvm" + . ~/.nvm/nvm.sh + nvm install ${ENIGMA_NODE_VERSION} + nvm use ${ENIGMA_NODE_VERSION} +} + +download_enigma_source() { + local INSTALL_DIR + INSTALL_DIR=${ENIGMA_INSTALL_DIR} + + if [ -d "$INSTALL_DIR/.git" ]; then + log "ENiGMA½ is already installed in $INSTALL_DIR, trying to update using git" + command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch 2> /dev/null || { + log_error "Failed to update ENiGMA½, run 'git fetch' in $INSTALL_DIR yourself." + exit 1 + } + else + log "Downloading ENiGMA½ from git to '$INSTALL_DIR'" + mkdir -p "$INSTALL_DIR" + command git clone ${ENIGMA_SOURCE} "$INSTALL_DIR" || { + log_error "Failed to clone ENiGMA½ repo. Please report this!" + exit 1 + } + fi +} + +install_node_packages() { + log "Installing required Node packages" + cd ${ENIGMA_INSTALL_DIR} + npm install + if [ $? -eq 0 ]; then + log "npm package installation complete" + else + log_error "Failed to install ENiGMA½ npm packages. Please report this!" + fi +} + +generate_enigma_config() { + log "Launching config generator" + cd ${ENIGMA_INSTALL_DIR} + ./oputil.js config --new +} + +enigma_footer() { + log "ENiGMA½ installation complete!" +} + +enigma_header +enigma_install_init +install_nvm +configure_nvm +download_enigma_source +install_node_packages +generate_enigma_config +enigma_footer \ No newline at end of file From ff9748814d2bc42a6aa595dd0bf19bd17e282e1b Mon Sep 17 00:00:00 2001 From: David Stephens Date: Sat, 27 Aug 2016 22:36:29 +0100 Subject: [PATCH 2/2] Few tweaks: * Ensure entire script is downloaded before execution * Remove requirement to hit enter to continue * Allow overriding of install path, node version and git source * Prompt user to generate config after install --- misc/install.sh | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/misc/install.sh b/misc/install.sh index 1603c62a..7ef9455e 100755 --- a/misc/install.sh +++ b/misc/install.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash -ENIGMA_NODE_VERSION=4.4 -ENIGMA_INSTALL_DIR=$HOME/enigma-bbs -ENIGMA_SOURCE=https://github.com/NuSkooler/enigma-bbs.git +{ # this ensures the entire script is downloaded before execution + +ENIGMA_NODE_VERSION=${ENIGMA_NODE_VERSION:=4.4} +ENIGMA_INSTALL_DIR=${ENIGMA_INSTALL_DIR:=$HOME/enigma-bbs} +ENIGMA_SOURCE=${ENIGMA_SOURCE:=https://github.com/NuSkooler/enigma-bbs.git} TIME_FORMAT=`date "+%Y-%m-%d %H:%M:%S"` +WAIT_BEFORE_INSTALL=10 enigma_header() { + clear cat << EndOfMessage ______ _____________________ _____ ____________________ __________\\_ / @@ -16,13 +20,14 @@ _____________________ _____ ____________________ __________\\_ / /__ _\\ <*> ENiGMA½ // https://github.com/NuSkooler/enigma-bbs <*> /__/ -This script will install Node 4.4 via nvm, download Enigma½, install its dependencies, -then run the config generator for you. If this isn't what you were expecting, hit ctrl-c now. +ENiGMA½ will be installed to ${ENIGMA_INSTALL_DIR}, from source ${ENIGMA_SOURCE}. -If you already have nvm installed, this will update it to the latest version. +ENiGMA½ requires Node, v${ENIGMA_NODE_VERSION} will be installed via nvm. If you already have nvm installed, this install script will update it to the latest version. + +If this isn't what you were expecting, hit ctrl-c now. Installation will continue in ${WAIT_BEFORE_INSTALL} seconds... EndOfMessage - read -p ">> Hit Enter To Continue <<" + sleep ${WAIT_BEFORE_INSTALL} } enigma_install_needs() { @@ -88,14 +93,17 @@ install_node_packages() { fi } -generate_enigma_config() { - log "Launching config generator" - cd ${ENIGMA_INSTALL_DIR} - ./oputil.js config --new -} - enigma_footer() { log "ENiGMA½ installation complete!" + echo -e "\e[33m" + cat << EndOfMessage +If this is the first time you've installed ENiGMA½, you now need to generate a minimal configuration. To do so, run the following commands: + +cd ${ENIGMA_INSTALL_DIR} +./oputil.js config --new + +EndOfMessage + echo -e "\e[39m" } enigma_header @@ -104,5 +112,6 @@ install_nvm configure_nvm download_enigma_source install_node_packages -generate_enigma_config -enigma_footer \ No newline at end of file +enigma_footer + +} # this ensures the entire script is downloaded before execution \ No newline at end of file