You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

318 lines
8.5 KiB

  1. #!/bin/bash
  2. set -e
  3. RED=$(tput setaf 1)
  4. GREEN=$(tput setaf 2)
  5. YELLOW=$(tput setaf 3)
  6. BLUE=$(tput setaf 4)
  7. BOLD=$(tput bold)
  8. RESET=$(tput sgr0)
  9. die() {
  10. >&2 echo "${RED}error: $1${RESET}" && exit 1
  11. }
  12. log() {
  13. echo "$*"
  14. }
  15. log_done() {
  16. echo " ${GREEN}✓${RESET} $1"
  17. }
  18. log_running() {
  19. echo " ${YELLOW}*${RESET} $1"
  20. }
  21. log_error() {
  22. echo " ${RED}error: $1${RESET}"
  23. }
  24. success() {
  25. echo "${GREEN}$1${RESET}"
  26. }
  27. ### Run as a normal user
  28. if [ $EUID -eq 0 ]; then
  29. die "This script shouldn't be run as root."
  30. fi
  31. ### Verify cloned repo
  32. if [ ! -e "$HOME/raspberry-noaa" ]; then
  33. die "Is https://github.com/reynico/raspberry-noaa cloned in your home directory?"
  34. fi
  35. ### Install required packages
  36. log_running "Installing required packages..."
  37. raspbian_version="$(lsb_release -c --short)"
  38. if [ "$raspbian_version" == "stretch" ]; then
  39. wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
  40. echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php7.list
  41. fi
  42. sudo apt update -yq
  43. sudo apt install -yq predict \
  44. python-setuptools \
  45. ntp \
  46. cmake \
  47. libusb-1.0 \
  48. sox \
  49. at \
  50. bc \
  51. nginx \
  52. libncurses5-dev \
  53. libncursesw5-dev \
  54. libatlas-base-dev \
  55. python3-pip \
  56. imagemagick \
  57. libxft-dev \
  58. libxft2 \
  59. libjpeg9 \
  60. libjpeg9-dev \
  61. socat \
  62. php7.2-fpm \
  63. php7.2-sqlite \
  64. sqlite3
  65. if [ "$raspbian_version" == "stretch" ]; then
  66. sudo apt install -yq libgfortran-5-dev
  67. else
  68. sudo apt install -yq libgfortran5
  69. fi
  70. sudo python3 -m pip install numpy ephem tweepy Pillow
  71. log_done "Packages installed"
  72. ### Create the database schema
  73. if [ -e "$HOME/raspberry-noaa/panel.db" ]; then
  74. log_done "Database already created"
  75. else
  76. sqlite3 "panel.db" < "templates/webpanel_schema.sql"
  77. log_done "Database schema created"
  78. fi
  79. ### Blacklist DVB modules
  80. if [ -e /etc/modprobe.d/rtlsdr.conf ]; then
  81. log_done "DVB modules were already blacklisted"
  82. else
  83. sudo cp templates/modprobe.d/rtlsdr.conf /etc/modprobe.d/rtlsdr.conf
  84. log_done "DVB modules are blacklisted now"
  85. fi
  86. ### Install RTL-SDR
  87. if [ -e /usr/local/bin/rtl_fm ]; then
  88. log_done "rtl-sdr was already installed"
  89. else
  90. log_running "Installing rtl-sdr from osmocom..."
  91. (
  92. cd /tmp/
  93. git clone https://github.com/osmocom/rtl-sdr.git
  94. cd rtl-sdr/
  95. mkdir build
  96. cd build
  97. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  98. make
  99. sudo make install
  100. sudo ldconfig
  101. cd /tmp/
  102. sudo cp ./rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/
  103. )
  104. log_done "rtl-sdr install done"
  105. fi
  106. ### Install WxToIMG
  107. if [ -e /usr/local/bin/xwxtoimg ]; then
  108. log_done "WxToIMG was already installed"
  109. else
  110. log_running "Installing WxToIMG..."
  111. sudo dpkg -i software/wxtoimg-armhf-2.11.2-beta.deb
  112. log_done "WxToIMG installed"
  113. fi
  114. ### Install default config file
  115. if [ -e "$HOME/.noaa.conf" ]; then
  116. log_done "$HOME/.noaa.conf already exists"
  117. else
  118. cp "templates/noaa.conf" "$HOME/.noaa.conf"
  119. log_done "$HOME/.noaa.conf installed"
  120. fi
  121. if [ -d "$HOME/.predict" ] && [ -e "$HOME/.predict/predict.qth" ]; then
  122. log_done "$HOME/.predict/predict.qth already exists"
  123. else
  124. mkdir "$HOME/.predict"
  125. cp "templates/predict.qth" "$HOME/.predict/predict.qth"
  126. log_done "$HOME/.predict/predict.qth installed"
  127. fi
  128. if [ -e "$HOME/.wxtoimgrc" ]; then
  129. log_done "$HOME/.wxtoimgrc already exists"
  130. else
  131. cp "templates/wxtoimgrc" "$HOME/.wxtoimgrc"
  132. log_done "$HOME/.wxtoimgrc installed"
  133. fi
  134. if [ -e "$HOME/.tweepy.conf" ]; then
  135. log_done "$HOME/.tweepy.conf already exists"
  136. else
  137. cp "templates/tweepy.conf" "$HOME/.tweepy.conf"
  138. log_done "$HOME/.tweepy.conf installed"
  139. fi
  140. ### Install meteor_demod
  141. if [ -e /usr/bin/meteor_demod ]; then
  142. log_done "meteor_demod was already installed"
  143. else
  144. log_running "Installing meteor_demod..."
  145. (
  146. cd /tmp
  147. git clone https://github.com/dbdexter-dev/meteor_demod.git
  148. cd meteor_demod
  149. make
  150. sudo make install
  151. )
  152. log_done "meteor_demod installed"
  153. fi
  154. ### Install medet_arm
  155. if [ -e /usr/bin/medet_arm ]; then
  156. log_done "medet_arm was already installed"
  157. else
  158. log_running "Installing medet_arm..."
  159. sudo cp software/medet_arm /usr/bin/medet_arm
  160. sudo chmod +x /usr/bin/medet_arm
  161. log_done "medet_arm installed"
  162. fi
  163. ### Cron the scheduler
  164. set +e
  165. crontab -l | grep -q "raspberry-noaa"
  166. if [ $? -eq 0 ]; then
  167. log_done "Crontab for schedule.sh already exists"
  168. else
  169. cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa/schedule.sh") | crontab -
  170. log_done "Crontab installed"
  171. fi
  172. set -e
  173. ### Setup Nginx
  174. log_running "Setting up Nginx..."
  175. sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
  176. (
  177. sudo mkdir -p /var/www/wx/images
  178. sudo chown -R pi:pi /var/www/wx
  179. sudo usermod -a -G www-data pi
  180. sudo chmod 775 /var/www/wx
  181. )
  182. sudo systemctl restart nginx
  183. sudo cp -rp templates/webpanel/* /var/www/wx/
  184. log_done "Nginx configured"
  185. ### Setup ramFS
  186. SYSTEM_MEMORY=$(free -m | awk '/^Mem:/{print $2}')
  187. if [ "$SYSTEM_MEMORY" -lt 2000 ]; then
  188. sed -i -e "s/1000M/200M/g" templates/fstab
  189. fi
  190. set +e
  191. cat /etc/fstab | grep -q "ramfs"
  192. if [ $? -eq 0 ]; then
  193. log_done "ramfs already setup"
  194. else
  195. sudo mkdir -p /var/ramfs
  196. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  197. log_done "Ramfs installed"
  198. fi
  199. sudo mount -a
  200. sudo chmod 777 /var/ramfs
  201. set -e
  202. if [ -f "$HOME/raspberry-noaa/demod.py" ]; then
  203. log_done "pd120_decoder already installed"
  204. else
  205. wget -qr https://github.com/reynico/pd120_decoder/archive/master.zip -O /tmp/master.zip
  206. (
  207. cd /tmp
  208. unzip master.zip
  209. cd pd120_decoder-master/pd120_decoder/
  210. python3 -m pip install --user -r requirements.txt
  211. cp demod.py utils.py "$HOME/raspberry-noaa/"
  212. )
  213. log_done "pd120_decoder installed"
  214. fi
  215. success "Install (almost) done!"
  216. read -rp "Do you want to enable bias-tee? (y/N)"
  217. if [[ $REPLY =~ ^[Yy]$ ]]; then
  218. sed -i -e "s/enable_bias_tee/-T/g" "$HOME/.noaa.conf"
  219. log_done "Bias-tee is enabled!"
  220. else
  221. sed -i -e "s/enable_bias_tee//g" "$HOME/.noaa.conf"
  222. fi
  223. echo "
  224. Next we'll configure your webpanel language
  225. and locale settings - you can update these in the
  226. future by modifying 'lang' in /var/www/wx/Config.php
  227. and 'date_default_timezone_set' in /var/www/wx/header.php
  228. "
  229. # language configuration
  230. langs=($(find templates/webpanel/language/ -type f -printf "%f\n" | cut -f 1 -d '.'))
  231. while : ; do
  232. read -rp "Enter your preferred language (${langs[*]}): "
  233. lang=$REPLY
  234. if [[ ! " ${langs[@]} " =~ " ${lang} " ]]; then
  235. log_error "choice $lang is not one of the available options (${langs[*]})"
  236. else
  237. break
  238. fi
  239. done
  240. sed -i -e "s/'lang' => '.*'$/'lang' => '${lang}'/" "/var/www/wx/Config.php"
  241. echo "Visit https://www.php.net/manual/en/timezones.php for a list of available timezones"
  242. read -rp "Enter your preferred timezone: "
  243. timezone=$REPLY
  244. timezone=$(echo $timezone | sed 's/\//\\\//g')
  245. sed -i -e "s/date_default_timezone_set('.*');/date_default_timezone_set('${timezone}');/" "/var/www/wx/header.php"
  246. echo "
  247. It's time to configure your ground station
  248. You'll be asked for your latitude and longitude
  249. Use negative values for South and West
  250. "
  251. read -rp "Enter your latitude (South values are negative): "
  252. lat=$REPLY
  253. read -rp "Enter your longitude (West values are negative): "
  254. lon=$REPLY
  255. # note: this can probably be improved by calculating this
  256. # automatically - good for a future iteration
  257. read -rp "Enter your timezone offset (ex: -3 for Argentina time): "
  258. tzoffset=$REPLY
  259. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz_offset/${tzoffset}/g" "$HOME/.noaa.conf"
  260. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  261. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  262. success "Install done! Double check your $HOME/.noaa.conf settings"
  263. echo "
  264. If you want to post your images to Twitter, please setup
  265. your Twitter credentials on $HOME/.tweepy.conf
  266. "
  267. set +e
  268. ### Running WXTOIMG to have the user accept the licensing agreement
  269. wxtoimg
  270. sudo reboot