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.
 
 
 
 
 
 

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