summaryrefslogtreecommitdiff
path: root/setup.sh
blob: 9da9e7053db95f00eb91611948048781da413ecd (plain)
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
#!/bin/bashset -euo pipefail# Run once on cremonde as root (or with sudo) to install the synoptic service.# Usage: sudo ./setup.shif [ "$(id -u)" -ne 0 ]; then    echo "Must run as root or with sudo." >&2    exit 1fiSCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)OWNER=st33v# ---------------------------------------------------------------------------# Packages# ---------------------------------------------------------------------------echo "==> Installing required packages..."pacman -Sy --needed --noconfirm curl imagemagick ghostscript ffmpeg nginx# ---------------------------------------------------------------------------# Nginx conflict checks# ---------------------------------------------------------------------------echo "==> Checking for nginx conflicts..."CONFLICT=0if grep -rl "server_name.*pestrel\.com" /etc/nginx/ 2>/dev/null; then    echo "WARNING: The above nginx config(s) already reference pestrel.com — check for duplicate server blocks."    CONFLICT=1fiif grep -rl "server_name.*radar\.pestrel\.com" /etc/nginx/ 2>/dev/null; then    echo "WARNING: The above nginx config(s) already reference radar.pestrel.com — check for duplicate server blocks."    CONFLICT=1fiif grep -rl "listen.*80.*default_server" /etc/nginx/ 2>/dev/null; then    echo "WARNING: The above nginx config(s) define a default_server on port 80 — may intercept traffic intended for this site."    CONFLICT=1fiif ! grep -q "include.*conf\.d" /etc/nginx/nginx.conf 2>/dev/null; then    echo "WARNING: /etc/nginx/nginx.conf does not appear to include conf.d/*.conf — you may need to add the following line manually:"    echo "         include /etc/nginx/conf.d/*.conf;"    CONFLICT=1fi[ "$CONFLICT" -eq 0 ] && echo "    No conflicts detected."# ---------------------------------------------------------------------------# Directories# ---------------------------------------------------------------------------echo "==> Creating directories..."install -d -o "$OWNER" -g "$OWNER" /opt/synopticinstall -d -o "$OWNER" -g "$OWNER" /var/lib/synopticinstall -d -o "$OWNER" -g "$OWNER" /var/lib/synoptic/archiveinstall -d -o "$OWNER" -g "$OWNER" /var/lib/synoptic/archive/rawinstall -d /srv/wwwinstall -d -o "$OWNER" -g "$OWNER" /srv/www/pestrelchown "$OWNER:$OWNER" /srv/www/pestrelinstall -d -o "$OWNER" -g "$OWNER" /opt/radarinstall -d -o "$OWNER" -g "$OWNER" /var/lib/radarinstall -d -o "$OWNER" -g "$OWNER" /srv/www/radarif [ -d /mnt/enclave ]; then    install -d -o "$OWNER" -g "$OWNER" /mnt/enclave/synoptic /mnt/enclave/synoptic/pairs /mnt/enclave/synoptic/outelse    echo "WARNING: /mnt/enclave does not exist; synoptic-morph will need its workspace path configured."fiinstall -d -o "$OWNER" -g "$OWNER" /srv/www/radar/sydneyinstall -d -o "$OWNER" -g "$OWNER" /srv/www/radar/brisbaneinstall -d -o "$OWNER" -g "$OWNER" /srv/www/radar/canberrainstall -d -o "$OWNER" -g "$OWNER" /srv/www/radar/cairns# ---------------------------------------------------------------------------# Web content# ---------------------------------------------------------------------------echo "==> Writing index.html..."install -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/index.html" /srv/www/pestrel/index.htmlinstall -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/radar.index.html"    /srv/www/radar/index.htmlinstall -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/radar.sydney.html"   /srv/www/radar/sydney/index.htmlinstall -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/radar.brisbane.html" /srv/www/radar/brisbane/index.htmlinstall -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/radar.canberra.html" /srv/www/radar/canberra/index.htmlinstall -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/radar.cairns.html"   /srv/www/radar/cairns/index.htmlecho "==> Installing radarFetch.sh..."install -o "$OWNER" -g "$OWNER" -m 755 "$SCRIPT_DIR/radarFetch.sh" /opt/radar/radarFetch.shecho "==> Installing synopticMorph.sh and morph.html..."install -o "$OWNER" -g "$OWNER" -m 755 "$SCRIPT_DIR/synopticMorph.sh" /opt/synoptic/synopticMorph.shinstall -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/morph.html" /srv/www/pestrel/morph.html# ---------------------------------------------------------------------------# Systemd units# ---------------------------------------------------------------------------echo "==> Installing systemd unit files..."for unit in synoptic.service synoptic.timer synoptic-retry.service synoptic-retry.timer \            synoptic-morph.service \            radar.service radar.timer radar-retry.service radar-retry.timer; do    install -m 644 "$SCRIPT_DIR/systemd/${unit}" "/etc/systemd/system/${unit}"    echo "    installed ${unit}"doneecho "==> Reloading systemd and enabling timers..."systemctl daemon-reloadsystemctl enable --now synoptic.timersystemctl enable --now radar.timer# ---------------------------------------------------------------------------# Nginx# ---------------------------------------------------------------------------#echo "==> Installing nginx configs..."#install -m 644 "$SCRIPT_DIR/nginx/pestrel.com.conf"       /etc/nginx/conf.d/synoptic.conf#install -m 644 "$SCRIPT_DIR/nginx/radar.pestrel.com.conf" /etc/nginx/conf.d/radar.conf#echo "==> Testing nginx config..."#nginx -t#echo "==> Reloading nginx..."#systemctl reload nginx# ---------------------------------------------------------------------------echo "==> Done."echo "    Run 'systemctl list-timers synoptic.timer' to confirm next scheduled run."