-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart_bbs.bash
More file actions
executable file
·141 lines (126 loc) · 4.65 KB
/
Copy pathstart_bbs.bash
File metadata and controls
executable file
·141 lines (126 loc) · 4.65 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
# copyright 2025 by moshix
# This is a BBS for 3270 terminals
# all rights reserved by moshix
# Detect if we're running on Linux
if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "linux"* ]]; then
# Linux machine - enable logging to /var/log/tsu.log
LOG_FILE="/var/log/tsu.log"
# Check if sudo is available and working
if ! command -v sudo &> /dev/null; then
echo "Error: sudo is not available. Cannot enable logging."
echo "Falling back to non-logging mode."
echo
# Fall back to non-logging mode
while true; do
time ./tsu
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "tsu exited successfully. Not restarting."
break
elif [ $EXIT_CODE -eq 42 ]; then
echo "REIPL requested. Restarting immediately..."
continue
else
echo "tsu exited with error $EXIT_CODE. Restarting in 2 seconds..."
sleep 2
fi
done
exit 0
fi
# Test if we can write to the log file
if ! sudo touch "$LOG_FILE" 2>/dev/null; then
echo "Error: Cannot create or write to log file $LOG_FILE"
echo "Check permissions or run with appropriate sudo access."
echo "Falling back to non-logging mode."
echo
# Fall back to non-logging mode
while true; do
time ./tsu
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "tsu exited successfully. Not restarting."
break
elif [ $EXIT_CODE -eq 42 ]; then
echo "REIPL requested. Restarting immediately..."
continue
else
echo "tsu exited with error $EXIT_CODE. Restarting in 2 seconds..."
sleep 2
fi
done
exit 0
fi
# Inform user about logging (console only, not in log file)
echo "=== TSU BBS Startup Script ==="
echo "Linux system detected - logging enabled"
echo "Log file: $LOG_FILE"
echo "All application output will be logged there"
echo "========================================"
echo
# Start logging to file
if ! echo "$(date '+%Y-%m-%d %H:%M:%S') - TSU BBS starting on Linux - logging to $LOG_FILE" | sudo tee -a "$LOG_FILE" >/dev/null; then
echo "Warning: Failed to write to log file. Continuing without logging."
echo
# Fall back to non-logging mode
while true; do
time ./tsu
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "tsu exited successfully. Not restarting."
break
elif [ $EXIT_CODE -eq 42 ]; then
echo "REIPL requested. Restarting immediately..."
continue
else
echo "tsu exited with error $EXIT_CODE. Restarting in 2 seconds..."
sleep 2
fi
done
exit 0
fi
# Function to log messages with error handling
log_message() {
if ! echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | sudo tee -a "$LOG_FILE" >/dev/null; then
echo "Warning: Failed to write to log file: $1"
fi
}
log_message "Starting TSU BBS application"
while true; do
log_message "Launching TSU application"
time ./tsu 2>&1 | sudo tee -a "$LOG_FILE"
EXIT_CODE=${PIPESTATUS[0]} # Get exit code of ./tsu, not tee
if [ $EXIT_CODE -eq 0 ]; then
log_message "TSU exited successfully. Not restarting."
break
elif [ $EXIT_CODE -eq 42 ]; then
log_message "REIPL requested. Restarting immediately..."
continue
else
log_message "TSU exited with error code $EXIT_CODE. Restarting in 2 seconds..."
sleep 2
fi
done
log_message "TSU BBS shutdown complete"
else
# Non-Linux machine - run without logging
echo "=== TSU BBS Startup Script ==="
echo "Non-Linux system detected - logging disabled"
echo "Logging is only available on Linux systems"
echo "========================================"
echo
while true; do
time ./tsu
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "tsu exited successfully. Not restarting."
break
elif [ $EXIT_CODE -eq 42 ]; then
echo "REIPL requested. Restarting immediately..."
continue
else
echo "tsu exited with error $EXIT_CODE. Restarting in 2 seconds..."
sleep 2
fi
done
fi