forked from jekhokie/raspberry-noaa-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_and_upgrade.sh
executable file
·147 lines (126 loc) · 4.7 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
#!/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/diff_yaml_configs.py config/settings.yml.sample config/settings.yml
if [ $? -eq 0 ]; then
log_done " Config check complete!"
else
die " Please update your config/settings.yml file to include the missing parameters from config/settings.yml.sample"
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 "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"
# 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 first passes for imagery..."
./scripts/schedule.sh
log_running "First passes scheduled!"
echo ""
echo "-------------------------------------------------------------------------------"
log_finished "CONGRATULATIONS!"
echo ""
log_finished "raspberry-noaa-v2 has been successfully installed/upgraded!"
log_finished "You can view the webpanel updates by visiting the following URL in a web browser:"
log_finished "http://<YOUR_IP_OR_HOSTNAME>:<CONFIGURED_PORT>/"
echo ""
log_finished "You can also see the URL listed in the 'output web server url' play output 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