Skip to content

Commit

Permalink
Merge pull request #580 from crhultay/patch-5
Browse files Browse the repository at this point in the history
Installation Script Enhancement and Startup Script
  • Loading branch information
NuSkooler authored Nov 27, 2024
2 parents 419ec7d + ed04b28 commit efe3b5e
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ www/*
www/assets/*
!www/otp_register_template.html
!www/reset_password.template.html

# Runtime Environment
.venv
90 changes: 90 additions & 0 deletions autoexec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

# Environment
ENIGMA_INSTALL_DIR=${ENIGMA_INSTALL_DIR:=$HOME/enigma-bbs}
AUTOEXEC_LOGFILE="$ENIGMA_INSTALL_DIR/logs/autoexec.log"
TIME_FORMAT=`date "+%Y-%m-%d %H:%M:%S"`

# Mise en place
~/.local/bin/mise activate bash >> bash

# Environment Versions
ENIGMA_NODE_VERSION=${ENIGMA_NODE_VERSION:=$(toml get --toml-path=$ENIGMA_INSTALL_DIR/mise.toml tools.node)}
ENIGMA_PYTHON_VERSION=${ENIGMA_PYTHON_VERSION:=$(toml get --toml-path=$ENIGMA_INSTALL_DIR/mise.toml tools.python)}

# Validate Environment
DEPENDENCIES_VALIDATED=1

# Shared Functions
log() {
echo "${TIME_FORMAT} " "$*" >> $AUTOEXEC_LOGFILE
}

# If this is a first run, the log path will not yet exist and must be created
if [ ! -d "$ENIGMA_INSTALL_DIR/logs" ]
then
mkdir -p $ENIGMA_INSTALL_DIR/logs
fi

log "START:"
log "- PATH: $PATH"
log "- CURRENT DIR: ${PWD##}"

if ! command -v "mise" 2>&1 >/dev/null
then
log "mise is not in your PATH, activating"
eval "$(~/.local/bin/mise activate bash)"
fi

if ! command -v "node" 2>&1 >/dev/null
then
log "Node environment is not in your PATH"
log "ERROR END"
exit 1
else
NODE_VERSION=$(node --version | tee /dev/null)
log "- NODE VERSION: $NODE_VERSION"
if [[ $NODE_VERSION != "v$ENIGMA_NODE_VERSION."* ]]; then
log "Node version found in your PATH is $NODE_VERSION, was expecting v$ENIGMA_NODE_VERSION.*; you may encounter compatibility issues"
DEPENDENCIES_VALIDATED=0
fi
fi

if ! command -v "python" 2>&1 >/dev/null
then
log "Python environment is not in your PATH"
log "ERROR END"
exit 1
else
PYTHON_VERSION=$(python --version | tee /dev/null)
log "- PYTHON VERSION: $PYTHON_VERSION"
if [[ $PYTHON_VERSION != "Python $ENIGMA_PYTHON_VERSION"* ]]; then
log "Python version found in your PATH is $PYTHON_VERSION, was expecting Python $ENIGMA_PYTHON_VERSION.*; you may encounter compatibility issues"
DEPENDENCIES_VALIDATED=0
fi
fi

# Validate whether we are good to Start
if [ "$DEPENDENCIES_VALIDATED" == "0" ]; then
if [ -v ENIGMA_IGNORE_DEPENDENCIES ] && [ "${ENIGMA_IGNORE_DEPENDENCIES}" == "1" ]; then
log "ENIGMA_IGNORE_DEPENDENCIES=1 detected, starting up..."
else
log "NOTE: Please re-run with 'ENIGMA_IGNORE_DEPENDENCIES=1 /path/to/autoexec.sh' to force startup"
log "ERROR END"
exit 1
fi
fi

# Start BBS
log "Starting ENiGMA½"
~/enigma-bbs/main.js
result=$?

# Determine whether a Startup Crash Occurred
# if [ $result -eq 0 ]; then
# # TODO: Notify via SMS / Email of Startup Failure
# fi

log "ENiGMA½ exited with $result"
log "END"
exit $result
Loading

0 comments on commit efe3b5e

Please sign in to comment.