-
Notifications
You must be signed in to change notification settings - Fork 105
/
install_and_upgrade.sh
executable file
·181 lines (156 loc) · 5.93 KB
/
install_and_upgrade.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
#!/bin/bash
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
BOLD=$(tput bold)
RESET=$(tput sgr0)
die() {
>&2 echo "${RED}Error: $1${RESET}" && exit 1
}
log_running() {
echo " ${YELLOW}* $1${RESET}"
}
log_done() {
echo " ${GREEN}✓ $1${RESET}"
}
log_finished() {
echo " ${GREEN}$1${RESET}"
}
# run as a normal user
if [ $EUID -eq 0 ]; then
die "Don't use sudo when running this script, quitting..."
fi
# verify the repo exists as expected in the home directory
if [ ! -e "$HOME/raspberry-noaa-v2" ]; then
die "Please clone https://github.com/jekhokie/raspberry-noaa-v2 to your home directory"
fi
# check if this is a new install or an upgrade based on modprobe settings
# which is likey a safe way to tell if the user has already installed
# tools and rebooted
install_type='install'
if [ -f /etc/modprobe.d/rtlsdr.conf ]; then
install_type='upgrade'
fi
log_running "Installing yaml and jsonschema Python modules..."
sudo apt install python3-yaml python3-jsonschema -y
log_running "Checking configuration files..."
python3 scripts/tools/validate_yaml.py config/settings.yml config/settings_schema.json
if [ $? -eq 0 ]; then
log_done " Config check complete!"
else
die " Please update your config/settings.yml file to accommodate the above errors"
fi
# install ansible
which ansible-playbook 2>&1 >/dev/null
if [ $? -ne 0 ]; then
log_running "Updating and installing Ansible..."
sudo apt update -yq
sudo apt install -yq ansible
if [ $? -eq 0 ]; then
log_done " Ansible install complete!"
else
die " Could not install Ansible - please inspect the logs above"
fi
fi
log_running "Configure ATRM rule and PHP Controller based on scheduling user..."
if [ $? -eq 0 ]; then
chmod +x $HOME/raspberry-noaa-v2/scripts/tools/atrm_rule_and_removal.sh
$HOME/raspberry-noaa-v2/scripts/tools/atrm_rule_and_removal.sh
else
die " Something failed with the install - please inspect the logs above"
fi
log_running "Running Ansible to install and/or update your raspberry-noaa-v2..."
ansible-playbook -i ansible/hosts --extra-vars "@config/settings.yml" ansible/site.yml -e "target_user=$USER system_architecture=$(dpkg --print-architecture)"
if [ $? -eq 0 ]; then
log_done " Ansible apply complete!"
else
die " Something failed with the install - please inspect the logs above"
fi
# source some env vars
. "$HOME/.noaa-v2.conf"
# Allow or remove HTTP port
if [ "$ENABLE_NON_TLS" = true ]; then
log_running "Adding HTTP firewall rule for port $WEBPANEL_PORT..."
sudo ufw allow $WEBPANEL_PORT/tcp
else
log_running "Removing HTTP firewall rule for port $WEBPANEL_PORT..."
sudo ufw delete allow $WEBPANEL_PORT/tcp
fi
# Allow or remove HTTPS port
if [ "$ENABLE_TLS" = true ]; then
log_running "Adding HTTPS firewall rule for port $WEBPANEL_TLS_PORT..."
sudo ufw allow $WEBPANEL_TLS_PORT/tcp
else
log_running "Removing HTTP firewall rule for port $WEBPANEL_TLS_PORT..."
sudo ufw delete allow $WEBPANEL_TLS_PORT/tcp
fi
log_running "Installing certbot for SSL certificates signed by the Let's Encrypt..."
if [ $? -eq 0 ]; then
sudo apt install certbot -y
else
die " Something failed with the install - please inspect the logs above"
fi
log_running "Configure PHP local time zone..."
if [ $? -eq 0 ]; then
chmod +x $HOME/raspberry-noaa-v2/scripts/tools/configure_php_local_timezone.sh
$HOME/raspberry-noaa-v2/scripts/tools/configure_php_local_timezone.sh
else
die " Something failed with the install - please inspect the logs above"
fi
#log_running "Installing SSL certificates..."
#if [ $? -eq 0 ] && [ $ENABLE_TLS == "true" ] && [ -n $WEB_SERVER_NAME ]; then
# sudo certbot certonly --webroot -w /var/www/wx-new/public -d $WEB_SERVER_NAME
# log_running "Restarting NGINX web server..."
# sudo systemctl restart nginx
#else
# die " Something failed with the install - please inspect the logs above"
#fi
# TLE data files
# NOTE: This should be DRY-ed up with the scripts/schedule.sh script
WEATHER_TXT="${NOAA_HOME}/tmp/weather.txt"
AMATEUR_TXT="${NOAA_HOME}/tmp/amateur.txt"
TLE_OUTPUT="${NOAA_HOME}/tmp/orbit.tle"
# run database migrations
log_running "Updating database schema with any changes..."
$NOAA_HOME/db_migrations/update_database.sh
if [ $? -eq 0 ]; then
log_done " Database schema updated!"
else
die " Something failed with database update - please inspect the logs above"
fi
# update all web content and permissions
log_running "Updating web content..."
(
find $WEB_HOME/ -mindepth 1 -type d -name "Config" -prune -o -print | xargs rm -rf &&
cp -r $NOAA_HOME/webpanel/* $WEB_HOME/ &&
sudo chown -R $USER:www-data $WEB_HOME/ &&
composer install -d $WEB_HOME/
) || die " Something went wrong updating web content - please inspect the logs above"
# run a schedule of passes (as opposed to waiting until cron kicks in the evening)
log_running "Scheduling passes for imagery..."
if [ ! -f $WEATHER_TXT ] || [ ! -f $AMATEUR_TXT ] || [ ! -f $TLE_OUTPUT ]; then
log_running "Scheduling with new TLE downloaded data..."
./scripts/schedule.sh -t
else
log_running "Scheduling with existing TLE data (not downloading new)..."
./scripts/schedule.sh
fi
log_running "Passes scheduled!"
echo ""
echo "-------------------------------------------------------------------------------"
log_finished "CONGRATULATIONS!"
echo ""
log_finished "raspberry-noaa-v2 has been successfully installed/upgraded!"
echo ""
log_finished "You can view the webpanel updates by visiting the URL(s) listed in the"
log_finished "'output web server url' and 'output web server tls url' play outputs above."
echo "-------------------------------------------------------------------------------"
echo ""
if [ $install_type == 'install' ]; then
log_running "Reloading udev rules and trigger so correct permissions fire for SDR Dongles"
sudo udevadm control --reload-rules && sudo udevadm trigger
log_running "Running RN2 Verification Tool..."
${HOME}/raspberry-noaa-v2/scripts/tools/verification_tool/verification.sh quick
sudo reboot
fi