-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
59 lines (43 loc) · 1.48 KB
/
install.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
#!/bin/bash
PW="$1"
BASE_FOLDER="/home/lg/lg-retro-gaming"
#Create file name with name as date
date=$(date +%Y-%m-%d)
filename="$date.txt"
# Add to log with timestamp
time=$(date +%H:%M:%S)
echo "[$time] Installing Liquid Galaxy Retro Gaming..."
# Open port 3123
LINE=`cat /etc/iptables.conf | grep "tcp" | grep "8111" | awk -F " -j" '{print $1}'`
RESULT=$LINE",3123"
DATA=`cat /etc/iptables.conf | grep "tcp" | grep "8111" | grep "3123"`
if [ "$DATA" == "" ]; then
time=$(date +%H:%M:%S)
echo "[$time] Port 3123 not open, opening port..."
echo $PW | sudo -S sed -i "s/$LINE/$RESULT/g" /etc/iptables.conf
else
time=$(date +%H:%M:%S)
echo "[$time] Port already open."
fi
# Install dependencies on server folder
time=$(date +%H:%M:%S)
echo "[$time] Installing dependencies..."
cd $BASE_FOLDER/server
echo $PW | sudo -S npm install -y
cd ..
# Add access for pm2
echo $PW | sudo -S chown lg:lg /home/lg/.pm2/rpc.sock /home/lg/.pm2/pub.sock
# Stop server if already started
echo $PW | sudo -S pm2 delete LGRG_PORT:3123 2> /dev/null
# Start server
time=$(date +%H:%M:%S)
echo "[$time] Starting pm2..."
echo $PW | sudo -S pm2 start $BASE_FOLDER/server/index.js --name LGRG_PORT:3123
echo $PW | sudo -S pm2 save
# Add automatic pm2 resurrect script
time=$(date +%H:%M:%S)
echo "[$time] Updating resurrect script..."
RESURRECT=$(pm2 startup | grep 'sudo')
echo $PW | sudo -S eval $RESURRECT
time=$(date +%H:%M:%S)
echo "[$time] Installation complete. Reboot machine to finish installation"