Updated autoexec.sh per feedback

This commit is contained in:
Carl Roman Hultay
2024-11-27 07:34:51 -05:00
committed by GitHub
parent 350e2d576d
commit dec1d6acb0

View File

@@ -3,6 +3,7 @@
# Environment # Environment
ENIGMA_INSTALL_DIR=${ENIGMA_INSTALL_DIR:=$HOME/enigma-bbs} ENIGMA_INSTALL_DIR=${ENIGMA_INSTALL_DIR:=$HOME/enigma-bbs}
AUTOEXEC_LOGFILE="$ENIGMA_INSTALL_DIR/logs/autoexec.log" AUTOEXEC_LOGFILE="$ENIGMA_INSTALL_DIR/logs/autoexec.log"
TIME_FORMAT=`date "+%Y-%m-%d %H:%M:%S"`
# Mise en place # Mise en place
~/.local/bin/mise activate bash >> bash ~/.local/bin/mise activate bash >> bash
@@ -14,40 +15,51 @@ ENIGMA_PYTHON_VERSION=${ENIGMA_PYTHON_VERSION:=$(toml get --toml-path=$ENIGMA_IN
# Validate Environment # Validate Environment
DEPENDENCIES_VALIDATED=1 DEPENDENCIES_VALIDATED=1
echo "$(date '+%Y-%m-%d %H:%M:%S') - START:" | tee -a $AUTOEXEC_LOGFILE # Shared Functions
echo "$(date '+%Y-%m-%d %H:%M:%S') - PATH: $PATH" | tee -a $AUTOEXEC_LOGFILE log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - CURRENT DIR: ${PWD##}" | tee -a $AUTOEXEC_LOGFILE 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 if ! command -v "mise" 2>&1 >/dev/null
then then
echo "$(date '+%Y-%m-%d %H:%M:%S') - mise is not in your PATH, activating" | tee -a $AUTOEXEC_LOGFILE log "mise is not in your PATH, activating"
eval "$(~/.local/bin/mise activate bash)" eval "$(~/.local/bin/mise activate bash)"
fi fi
if ! command -v "node" 2>&1 >/dev/null if ! command -v "node" 2>&1 >/dev/null
then then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Node environment is not in your PATH" | tee -a $AUTOEXEC_LOGFILE log "Node environment is not in your PATH"
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR END" | tee -a $AUTOEXEC_LOGFILE log "ERROR END"
exit 1 exit 1
else else
NODE_VERSION=$(node --version | tee /dev/null) NODE_VERSION=$(node --version | tee /dev/null)
echo "$(date '+%Y-%m-%d %H:%M:%S') - NODE VERSION: $NODE_VERSION" | tee -a $AUTOEXEC_LOGFILE log "- NODE VERSION: $NODE_VERSION"
if [[ $NODE_VERSION != "v$ENIGMA_NODE_VERSION."* ]]; then if [[ $NODE_VERSION != "v$ENIGMA_NODE_VERSION."* ]]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Node version found in your PATH is $NODE_VERSION, was expecting v$ENIGMA_NODE_VERSION.*; you may encounter compatibility issues" | tee -a $AUTOEXEC_LOGFILE log "Node version found in your PATH is $NODE_VERSION, was expecting v$ENIGMA_NODE_VERSION.*; you may encounter compatibility issues"
DEPENDENCIES_VALIDATED=0 DEPENDENCIES_VALIDATED=0
fi fi
fi fi
if ! command -v "python" 2>&1 >/dev/null if ! command -v "python" 2>&1 >/dev/null
then then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Python environment is not in your PATH" log "Python environment is not in your PATH"
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR END" | tee -a $AUTOEXEC_LOGFILE log "ERROR END"
exit 1 exit 1
else else
PYTHON_VERSION=$(python --version | tee /dev/null) PYTHON_VERSION=$(python --version | tee /dev/null)
echo "$(date '+%Y-%m-%d %H:%M:%S') - PYTHON VERSION: $PYTHON_VERSION" | tee -a $AUTOEXEC_LOGFILE log "- PYTHON VERSION: $PYTHON_VERSION"
if [[ $PYTHON_VERSION != "Python $ENIGMA_PYTHON_VERSION"* ]]; then if [[ $PYTHON_VERSION != "Python $ENIGMA_PYTHON_VERSION"* ]]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Python version found in your PATH is $PYTHON_VERSION, was expecting Python $ENIGMA_PYTHON_VERSION.*; you may encounter compatibility issues" | tee -a $AUTOEXEC_LOGFILE log "Python version found in your PATH is $PYTHON_VERSION, was expecting Python $ENIGMA_PYTHON_VERSION.*; you may encounter compatibility issues"
DEPENDENCIES_VALIDATED=0 DEPENDENCIES_VALIDATED=0
fi fi
fi fi
@@ -55,16 +67,16 @@ fi
# Validate whether we are good to Start # Validate whether we are good to Start
if [ "$DEPENDENCIES_VALIDATED" == "0" ]; then if [ "$DEPENDENCIES_VALIDATED" == "0" ]; then
if [ -v ENIGMA_IGNORE_DEPENDENCIES ] && [ "${ENIGMA_IGNORE_DEPENDENCIES}" == "1" ]; then if [ -v ENIGMA_IGNORE_DEPENDENCIES ] && [ "${ENIGMA_IGNORE_DEPENDENCIES}" == "1" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - ENIGMA_IGNORE_DEPENDENCIES=1 detected, starting up..." | tee -a $AUTOEXEC_LOGFILE log "ENIGMA_IGNORE_DEPENDENCIES=1 detected, starting up..."
else else
echo "$(date '+%Y-%m-%d %H:%M:%S') - NOTE: Please re-run with 'ENIGMA_IGNORE_DEPENDENCIES=1 /path/to/autoexec.sh' to force startup" | tee $AUTOEXEC_LOGFILE log "NOTE: Please re-run with 'ENIGMA_IGNORE_DEPENDENCIES=1 /path/to/autoexec.sh' to force startup"
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR END" | tee -a $AUTOEXEC_LOGFILE log "ERROR END"
exit 1 exit 1
fi fi
fi fi
# Start BBS # Start BBS
echo "$(date '+%Y-%m-%d %H:%M:%S') - Starting ENiGMA½" | tee -a $AUTOEXEC_LOGFILE log "Starting ENiGMA½"
~/enigma-bbs/main.js ~/enigma-bbs/main.js
result=$? result=$?
@@ -73,6 +85,6 @@ result=$?
# # TODO: Notify via SMS / Email of Startup Failure # # TODO: Notify via SMS / Email of Startup Failure
# fi # fi
echo "$(date '+%Y-%m-%d %H:%M:%S') - ENiGMA½ exited with $result" | tee -a $AUTOEXEC_LOGFILE log "ENiGMA½ exited with $result"
echo "$(date '+%Y-%m-%d %H:%M:%S') - END" | tee -a $AUTOEXEC_LOGFILE log "END"
exit $result exit $result