This repository was archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·76 lines (63 loc) · 2.04 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·76 lines (63 loc) · 2.04 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
#!/usr/bin/env bash
# Configuration Variables
PHP_PORT=8080
# Auto-Configuration Variables
CHENARD_ENABLED=$(php -r '$CONFIG = require "app/configuration.php"; echo (int)$CONFIG["chenard"]["enabled"];')
CHENARD_PORT=$(php -r '$CONFIG = require "app/configuration.php"; echo isset($CONFIG["chenard"]["port"]) ? (int)$CONFIG["chenard"]["port"] : 12345;')
# Do not touch - State Variables
CHENARD_CONTROL=1
# Some Functions
runPHP(){
# Run the PHP Server blocking, if it gets closed we just clean up afterwards
pushd web > /dev/null
php -S localhost:${PHP_PORT} -t $(pwd)
popd > /dev/null
}
runChenardServer() {
# Run Chenard if it does not exist
if [[ ! -e .chenard.pid ]]; then
echo "Starting Chenard on localhost:${CHENARD_PORT}"
chenserver -p ${CHENARD_PORT} &
CHENARD_PID=$!
echo ${CHENARD_PID} > .chenard.pid
fi
}
checkChenardPid() {
# Pid file Handling
if [[ -e .chenard.pid ]]; then
if ps -p $(cat .chenard.pid); then
echo "Found running Chenard instance, won't start my own."
# We didn't started it so we won't kill it then...
CHENARD_CONTROL=0
else
echo "Found stale Chenard pid file, removing."
rm .chenard.pid
fi
fi
}
cleanupChenardPid() {
# Only clean up chenard process if we started it.
if [[ ${CHENARD_CONTROL} -eq 1 ]]; then
echo "Killing Chenard..."
kill $(cat .chenard.pid) > /dev/null
rm .chenard.pid
fi
}
# Vendors check
if [[ ! -e vendor ]]; then
echo "You need to run 'install-vendors.sh' first."
exit 1
fi
if [[ ${CHENARD_ENABLED} -eq 1 ]]; then
if ! which chenserver > /dev/null 2>&1; then
echo "You need to have chenserver in your PATH, you may install it through the 'install-chenard.sh' script (build tools needed!).";
exit 1
fi
checkChenardPid
runChenardServer
runPHP
cleanupChenardPid
else
echo "Run without Chenard-Chess-AI (to enable toggle configuration in 'app/configuration.php')"
runPHP;
fi