-
Notifications
You must be signed in to change notification settings - Fork 106
/
autoexec.sh
executable file
·93 lines (79 loc) · 2.66 KB
/
autoexec.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.local/share/mise/shims:$PATH"
export PATH="$HOME/.local/share/mise/installs/python/latest/bin:$PATH"
# 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"
log "ERROR END"
exit 1
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