-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
81 lines (61 loc) · 2.55 KB
/
setup.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
set -x
set -e
# we assume that we have a Raspbian system running
# with a user named rdb
# setup wifi properly
sudo raspi-config nonint do_wifi_country IL
sudo rfkill unblock wifi
sudo swapoff /var/swap
sudo dd if=/dev/zero of=/var/swap count=8 bs=128M
sudo mkswap /var/swap
sudo chmod 0600 /var/swap
sudo swapon /var/swap
# install node.js from nodesource (raspbian has only node 12)
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - && sudo apt-get install -y nodejs
# install nginx and dnsmasq
sudo apt-get install -y nginx dnsmasq dhcpcd
sudo dpkg -i ravendb.deb
rm ravendb.deb
sudo mkdir -p /var/lib/ravendb/data/Databases
sudo mv Hugin /var/lib/ravendb/data/Databases/Hugin
sudo chown --recursive ravendb:ravendb /var/lib/ravendb/data/Databases
sudo mv settings.json /etc/ravendb/settings.json
sudo mv license.json /etc/ravendb/license.json
sudo chown root:ravendb /etc/ravendb/settings.json
sudo systemctl restart ravendb
# setup the web app users
getent group node-apps || sudo groupadd node-apps
NODE_GID=$(getent group node-apps | cut -d ':' -f 3)
getent passwd hugin || sudo adduser --disabled-login --disabled-password --system \
--home /var/lib/hugin --no-create-home --quiet --gid "$NODE_GID" hugin
cd /home/rdb/backend
npm install
cd /home/rdb
sudo mv ./backend /usr/lib/hugin
sudo mv ./dist /usr/lib/hugin/dist
sudo chown --recursive root:node-apps /usr/lib/hugin
sudo mv hugin.service /etc/systemd/system/hugin.service
sudo systemctl enable hugin
curl 'http://127.0.0.1:8080/admin/databases?name=Hugin&replicationFactor=1' \
-X 'PUT' --data-raw '{"DatabaseName":"Hugin"}' --retry 5 --retry-max-time 120 \
|| true # we ignore this error, as it might be that the database already exists
sudo systemctl start hugin
# configuration of the system
sudo mv etc.wpa_supplicant.wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
sudo mv etc.nginx.sites-available.default /etc/nginx/sites-available/default
sudo mv etc.dhcpcd.conf /etc/dhcpcd.conf
sudo mv etc.dnsmasq.conf /etc/dnsmasq.conf
sudo sed -i 's/#DNSMASQ_EXCEPT="lo"/DNSMASQ_EXCEPT="lo"/g' /etc/default/dnsmasq
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
# restart services and prepare...
sudo systemctl stop wpa_supplicant
sudo systemctl mask wpa_supplicant
sudo systemctl enable dnsmasq
sudo systemctl restart dnsmasq
sudo service dhcpcd restart
sudo wpa_cli -i wlan0 reconfigure
sudo nginx -s reload
# test the db works
curl http://127.0.0.1:8080/databases/Hugin/docs?id=questions%2Fsuperuser%2F1806936
rm ./* -rf # cleanup directoy
echo "Ready ..."