forked from reynico/raspberry-noaa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·226 lines (197 loc) · 5.92 KB
/
install.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
set -e
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() {
echo "$*"
}
log_done() {
echo " ${GREEN}✓${RESET} $1"
}
log_running() {
echo " ${YELLOW}*${RESET} $1"
}
success() {
echo "${GREEN}$1${RESET}"
}
### Verify cloned repo
if [ ! -e "$HOME/raspberry-noaa" ]; then
die "Is https://github.com/reynico/raspberry-noaa cloned in your home directory?"
fi
### Install required packages
log_running "Installing required packages..."
sudo apt update -yq
sudo apt install -yq predict \
python-setuptools \
ntp \
cmake \
libusb-1.0 \
sox \
at \
bc \
nginx \
libncurses5-dev \
libncursesw5-dev \
libatlas-base-dev \
python3-pip \
imagemagick \
libxft-dev \
libxft2 \
libjpeg9 \
libjpeg9-dev
sudo pip3 install numpy ephem tweepy Pillow
log_done "Packages installed"
### Blacklist DVB modules
if [ -e /etc/modprobe.d/rtlsdr.conf ]; then
log_done "DVB modules were already blacklisted"
else
sudo cp templates/modprobe.d/rtlsdr.conf /etc/modprobe.d/rtlsdr.conf
log_done "DVB modules are blacklisted now"
fi
### Install RTL-SDR
if [ -e /usr/local/bin/rtl_fm ]; then
log_done "rtl-sdr was already installed"
else
log_running "Installing rtl-sdr from osmocom..."
(
cd /tmp/
git clone https://github.com/osmocom/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
make
sudo make install
sudo ldconfig
cd /tmp/
sudo cp ./rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/
)
log_done "rtl-sdr install done"
fi
### Install WxToIMG
if [ -e /usr/local/bin/xwxtoimg ]; then
log_done "WxToIMG was already installed"
else
log_running "Installing WxToIMG..."
sudo dpkg -i software/wxtoimg-armhf-2.11.2-beta.deb
log_done "WxToIMG installed"
fi
### Install default config file
if [ -e "$HOME/.noaa.conf" ]; then
log_done "$HOME/.noaa.conf already exists"
else
cp "templates/noaa.conf" "$HOME/.noaa.conf"
log_done "$HOME/.noaa.conf installed"
fi
if [ -d "$HOME/.predict" ] && [ -e "$HOME/.predict/predict.qth" ]; then
log_done "$HOME/.predict/predict.qth already exists"
else
mkdir "$HOME/.predict"
cp "templates/predict.qth" "$HOME/.predict/predict.qth"
log_done "$HOME/.predict/predict.qth installed"
fi
if [ -e "$HOME/.wxtoimgrc" ]; then
log_done "$HOME/.wxtoimgrc already exists"
else
cp "templates/wxtoimgrc" "$HOME/.wxtoimgrc"
log_done "$HOME/.wxtoimgrc installed"
fi
if [ -e "$HOME/.tweepy.conf" ]; then
log_done "$HOME/.tweepy.conf already exists"
else
cp "templates/tweepy.conf" "$HOME/.tweepy.conf"
log_done "$HOME/.tweepy.conf installed"
fi
### Install meteor_demod
if [ -e /usr/bin/meteor_demod ]; then
log_done "meteor_demod was already installed"
else
log_running "Installing meteor_demod..."
(
cd /tmp
git clone https://github.com/dbdexter-dev/meteor_demod.git
cd meteor_demod
make
sudo make install
)
log_done "meteor_demod installed"
fi
### Install medet_arm
if [ -e /usr/bin/medet_arm ]; then
log_done "medet_arm was already installed"
else
log_running "Installing medet_arm..."
sudo cp software/medet_arm /usr/bin/medet_arm
sudo chmod +x /usr/bin/medet_arm
log_done "medet_arm installed"
fi
### Cron the scheduler
set +e
crontab -l | grep -q "raspberry-noaa"
if [ $? -eq 0 ]; then
log_done "Crontab for schedule.sh already exists"
else
cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa/schedule.sh") | crontab -
log_done "Crontab installed"
fi
set -e
### Setup Nginx
log_running "Setting up Nginx..."
sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
(
sudo mkdir -p /var/www/wx
sudo chown -R www-data:www-data /var/www/wx
sudo usermod -a -G www-data pi
sudo chmod 775 /var/www/wx
)
sudo systemctl restart nginx
if [ ! -e /var/www/wx/index.html ]; then
sudo cp templates/index.html /var/www/wx/index.html
fi
if [ ! -e /var/www/wx/logo-small.png ]; then
sudo cp templates/logo-small.png /var/www/wx/logo-small.png
fi
log_done "Nginx configured"
### Setup ramFS
set +e
cat /etc/fstab | grep -q "ramfs"
if [ $? -eq 0 ]; then
log_done "ramfs already setup"
else
sudo mkdir -p /var/ramfs
cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
log_done "Ramfs installed"
fi
sudo mount -a
sudo chmod 777 /var/ramfs
set -e
success "Install (almost) done!"
echo "
It's time to configure your ground station
You'll be asked for your latitude and longitude
Use negative values for South and West
"
read -rp "Enter your latitude (South values are negative): "
lat=$REPLY
read -rp "Enter your longitude (West values are negative): "
lon=$REPLY
read -rp "Enter your timezone (Ex: -3 for Argentina time): "
timezone=$REPLY
sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.noaa.conf"
sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$timezone * -1" | bc)/g" "sun.py"
# Running WXTOIMG to have the user accept the licensing agreement
wxtoimg
success "Install done! Double check your $HOME/.noaa.conf settings"
echo "
If you want to post your images to Twitter, please setup
your Twitter credentials on $HOME/.tweepy.conf
"