-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch.sh
196 lines (164 loc) · 4.97 KB
/
launch.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
echo "Starting Configuration Script for Smart Mirror..."
# some sleeping time till wifi connects
sleep 10
# check display rotation
display_rotation="$(grep "display_rotate" /boot/config.txt)"
if [ -z $display_rotation ]
then
echo "display_rotation empty, setting now."
sudo sh -c "echo 'display_rotate=1' >> /boot/config.txt"
sudo reboot
else
if [ $display_rotation == "display_rotate=1" ]
then
echo "Display rotation correct"
else
echo "Setting display rotation for all"
sudo sed -i -e 's/display_rotate=0/display_rotate=1/g' /boot/config.txt
sudo sed -i -e 's/display_rotate=2/display_rotate=1/g' /boot/config.txt
sudo sed -i -e 's/display_rotate=3/display_rotate=1/g' /boot/config.txt
sudo reboot
fi
fi
#change to directory where the code folder is based
cd ~/Desktop
if [ $(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error) == "ok" ]
then
echo "Internet connection okay"
# get ip...
#ip="$(hostname -I | awk '{print $1}')"
#ip="${ip//[[:space:]]/}"
#ip_router="${ip%.*}.1"
#ip_static="${ip%.*}.200"
# setup static ip address
#static_ip_address="$(grep "static ip_address=" /etc/dhcpcd.conf)"
#static_routers="$(grep "static_routers=" /etc/dhcpcd.conf)"
#static_domain_name_servers="$(grep "static domain_name_servers=" /etc/dhcpcd.conf)"
#if [[ ($static_ip_address=$ip+"/24" || $static_routers=$ip_router+"/24" || $static_domain_name_servers=$ip_router) ]]
#then
# sudo rm -rf /etc/dhcpcd.conf
# echo "static ip empty or wrong, setting now."
# static_ip_address=$ip_static
# static_ip_address+="/24"
# static_routers=$ip_router
# static_domain_name_servers=$ip_router
# echo $static_ip_address
# echo $static_routers
# echo $static_domain_name_servers
# sudo touch /etc/dhcpcd.conf
# sudo sh -c "echo '# Static IP' >> /etc/dhcpcd.conf"
# sudo sh -c "echo 'static ip_address=$static_ip_address' >> /etc/dhcpcd.conf"
# sudo sh -c "echo 'static routers=$static_routers' >> /etc/dhcpcd.conf"
# sudo sh -c "echo 'static domain_name_servers=$static_domain_name_servers' >> /etc/dhcpcd.conf"
#else
# echo "static ip is fine..."
# echo $ip_router
# echo $ip_static
#fi
# important package installations and updates
sudo apt-get -y install jq
sudo apt-get -y install dirmngr
sudo apt-get -y install xdotool
sudo apt-get -y install curl
sudo apt-get -y install git
sudo apt-get -y install mongodb
sudo apt-get -y install unclutter
# check if project exists: yes = direct to that folder, no = git clone
if [ -d "mirrorserver" ];
then
echo "Project mirrorserver exists!"
else
echo "Project mirrorserver does not exists!"
git clone https://github.com/felixwaldbach/mirrorserver.git
cd mirrorserver
nohup npm install &
# wait some time till installation of packages is done...
sleep 3m
cd client
nohup npm install &
# wait some time till installation of packages is done...
sleep 8m
fi
# change to project directory
cd ~/Desktop/mirrorserver
echo "Setting up database"
node mongoWidgetScript.js
# check if .env for environment variables exists
if [ -e .env ]
then
echo ".env exists!"
else
echo ".env does not exist, creating now...!"
$(touch .env)
secretkey="secretkey="
key=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 100 | head -n 1)
secretkey+=$key
echo $secretkey >> .env
fi
# check if config.json exists
if [ -e config.json ]
then
echo "config.json exists!"
config="$(cat config.json | jq '.')"
else
echo "config.json does not exist, creating now...!"
$(touch config.json)
fi
# check if config.json has content
if [ -z "$config" ]
then
echo "config.json is empty!"
configIsEmpty=true
else
echo "config.json is not empty!"
configIsEmpty=false
fi
if [ "$configIsEmpty" = true ]
then
echo "Setting up new config.json..."
ip="$(hostname -I | awk '{print $1}')"
ip="${ip//[[:space:]]/}"
# Set IP address of host and django server
host_address="http://"
django_address="http://"
host_address+=$ip
django_address+="172.20.10.2"
host_address+=:5000
django_address+=:8000
uuid=$(cat /proc/sys/kernel/random/uuid)
echo $host_address
echo $django_address
echo $uuid
# write this new configuration into config.json which is created before
configuration=$( jq -n \
--arg ip "$ip" \
--arg bn "$host_address" \
--arg on "$django_address" \
--arg tl "$uuid" \
'{ip_host: $ip, host_address: $bn, django_address: $on, uuid: $tl}' )
echo $configuration > config.json
else
# check for IPs and uuid
echo $config
fi
# Start express server and frontend
echo "Starting Backend..."
nohup node server.js &
echo "Starting Frontend..."
cd client
nohup npm start &
cd ~/Desktop
# Start Browser in fullscreen
echo "Opening Browser..."
chromium-browser --disable-session-crashed-bubble --disable-infobars &
sleep 15
xdotool key "F11" &
else
echo "No Internet connection"
# try again in 60 seconds...
sleep 60
sudo reboot
fi
exec bash
# EOF