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.
 
 
 
 
 
 

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