Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Script Enhancement and Startup Script #580

Merged
merged 29 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
78 changes: 78 additions & 0 deletions autoexec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

# Environment
ENIGMA_INSTALL_DIR=${ENIGMA_INSTALL_DIR:=$HOME/enigma-bbs}
AUTOEXEC_LOGFILE="$ENIGMA_INSTALL_DIR/logs/autoexec.log"

# 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

echo "$(date '+%Y-%m-%d %H:%M:%S') - START:" | tee -a $AUTOEXEC_LOGFILE
crhultay marked this conversation as resolved.
Show resolved Hide resolved
echo "$(date '+%Y-%m-%d %H:%M:%S') - PATH: $PATH" | tee -a $AUTOEXEC_LOGFILE
echo "$(date '+%Y-%m-%d %H:%M:%S') - CURRENT DIR: ${PWD##}" | tee -a $AUTOEXEC_LOGFILE

if ! command -v "mise" 2>&1 >/dev/null
then
echo "$(date '+%Y-%m-%d %H:%M:%S') - mise is not in your PATH, activating" | tee -a $AUTOEXEC_LOGFILE
eval "$(~/.local/bin/mise activate bash)"
fi

if ! command -v "node" 2>&1 >/dev/null
then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Node environment is not in your PATH" | tee -a $AUTOEXEC_LOGFILE
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR END" | tee -a $AUTOEXEC_LOGFILE
exit 1
else
NODE_VERSION=$(node --version | tee /dev/null)
echo "$(date '+%Y-%m-%d %H:%M:%S') - NODE VERSION: $NODE_VERSION" | tee -a $AUTOEXEC_LOGFILE
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
DEPENDENCIES_VALIDATED=0
fi
fi

if ! command -v "python" 2>&1 >/dev/null
then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Python environment is not in your PATH"
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR END" | tee -a $AUTOEXEC_LOGFILE
exit 1
else
PYTHON_VERSION=$(python --version | tee /dev/null)
echo "$(date '+%Y-%m-%d %H:%M:%S') - PYTHON VERSION: $PYTHON_VERSION" | tee -a $AUTOEXEC_LOGFILE
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
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
echo "$(date '+%Y-%m-%d %H:%M:%S') - ENIGMA_IGNORE_DEPENDENCIES=1 detected, starting up..." | tee -a $AUTOEXEC_LOGFILE
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
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR END" | tee -a $AUTOEXEC_LOGFILE
exit 1
fi
fi

# Start BBS
echo "$(date '+%Y-%m-%d %H:%M:%S') - Starting ENiGMA½" | tee -a $AUTOEXEC_LOGFILE
~/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

echo "$(date '+%Y-%m-%d %H:%M:%S') - ENiGMA½ exited with $result" | tee -a $AUTOEXEC_LOGFILE
echo "$(date '+%Y-%m-%d %H:%M:%S') - END" | tee -a $AUTOEXEC_LOGFILE
exit $result
Loading
Loading