forked from jekhokie/raspberry-noaa-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_and_upgrade.sh
executable file
·161 lines (138 loc) · 5.15 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
#!/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 "Please run this script as the pi user (not as root)"
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 "Checking for python3-pip..."
dpkg -l python3-pip 2>&1 >/dev/null
if [ $? -eq 0 ]; then
log_done " python3-pip already installed!"
else
log_running " python3-pip not yet installed - installing..."
sudo apt-get -y install python3-pip
if [ $? -eq 0 ]; then
log_done " python3-pip successfully installed!"
else
die " Could not install python3-pip - please check the logs above"
fi
fi
log_running "Installing Python dependencies..."
sudo python3 -m pip install -r $HOME/raspberry-noaa-v2/requirements.txt
if [ $? -eq 0 ]; then
log_done " Successfully aligned required Python packages!"
else
die " Could not install dependent Python packages - please check the logs above"
fi
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 "Setting ~/.config/meteordemod ownership to the current user"
sudo chown $USER:$USER -R ~/.config/meteordemod
log_running "Checking for configuration settings..."
if [ -f config/settings.yml ]; then
log_done " Settings file ready!"
else
die " No settings file detected - please copy config/settings.yml.sample to config/settings.yml and edit for your environment"
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
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"
# 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 pi: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 "It looks like this is a fresh install of the tooling for captures."
log_running "If you've never had the software tools installed previously (e.g. if you've"
log_running "not installed the original raspberry-noaa repo content), you likely need to"
log_running "restart your device. Please do this to rule out any potential issues in the"
log_running "software and libraries that have been installed."
fi