您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

225 行
5.9 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. ### Verify cloned repo
  25. if [ ! -e "$HOME/raspberry-noaa" ]; then
  26. die "Is https://github.com/reynico/raspberry-noaa cloned in your home directory?"
  27. fi
  28. ### Install required packages
  29. log_running "Installing required packages..."
  30. sudo apt update -yq
  31. sudo apt install -yq predict \
  32. python-setuptools \
  33. ntp \
  34. cmake \
  35. libusb-1.0 \
  36. sox \
  37. at \
  38. bc \
  39. nginx \
  40. libncurses5-dev \
  41. libncursesw5-dev \
  42. libatlas-base-dev \
  43. python3-pip \
  44. imagemagick \
  45. libxft-dev \
  46. libxft2 \
  47. libjpeg9 \
  48. libjpeg9-dev
  49. sudo pip3 install numpy ephem tweepy Pillow
  50. log_done "Packages installed"
  51. ### Blacklist DVB modules
  52. if [ -e /etc/modprobe.d/rtlsdr.conf ]; then
  53. log_done "DVB modules were already blacklisted"
  54. else
  55. sudo cp templates/modprobe.d/rtlsdr.conf /etc/modprobe.d/rtlsdr.conf
  56. log_done "DVB modules are blacklisted now"
  57. fi
  58. ### Install RTL-SDR
  59. if [ -e /usr/local/bin/rtl_fm ]; then
  60. log_done "rtl-sdr was already installed"
  61. else
  62. log_running "Installing rtl-sdr from osmocom..."
  63. (
  64. cd /tmp/
  65. git clone https://github.com/osmocom/rtl-sdr.git
  66. cd rtl-sdr/
  67. mkdir build
  68. cd build
  69. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  70. make
  71. sudo make install
  72. sudo ldconfig
  73. cd /tmp/
  74. sudo cp ./rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/
  75. )
  76. log_done "rtl-sdr install done"
  77. fi
  78. ### Install WxToIMG
  79. if [ -e /usr/local/bin/xwxtoimg ]; then
  80. log_done "WxToIMG was already installed"
  81. else
  82. log_running "Installing WxToIMG..."
  83. sudo dpkg -i software/wxtoimg-armhf-2.11.2-beta.deb
  84. log_done "WxToIMG installed"
  85. fi
  86. ### Install default config file
  87. if [ -e "$HOME/.noaa.conf" ]; then
  88. log_done "$HOME/.noaa.conf already exists"
  89. else
  90. cp "templates/noaa.conf" "$HOME/.noaa.conf"
  91. log_done "$HOME/.noaa.conf installed"
  92. fi
  93. if [ -d "$HOME/.predict" ] && [ -e "$HOME/.predict/predict.qth" ]; then
  94. log_done "$HOME/.predict/predict.qth already exists"
  95. else
  96. mkdir "$HOME/.predict"
  97. cp "templates/predict.qth" "$HOME/.predict/predict.qth"
  98. log_done "$HOME/.predict/predict.qth installed"
  99. fi
  100. if [ -e "$HOME/.wxtoimgrc" ]; then
  101. log_done "$HOME/.wxtoimgrc already exists"
  102. else
  103. cp "templates/wxtoimgrc" "$HOME/.wxtoimgrc"
  104. log_done "$HOME/.wxtoimgrc installed"
  105. fi
  106. if [ -e "$HOME/.tweepy.conf" ]; then
  107. log_done "$HOME/.tweepy.conf already exists"
  108. else
  109. cp "templates/tweepy.conf" "$HOME/.tweepy.conf"
  110. log_done "$HOME/.tweepy.conf installed"
  111. fi
  112. ### Install meteor_demod
  113. if [ -e /usr/bin/meteor_demod ]; then
  114. log_done "meteor_demod was already installed"
  115. else
  116. log_running "Installing meteor_demod..."
  117. (
  118. cd /tmp
  119. git clone https://github.com/dbdexter-dev/meteor_demod.git
  120. cd meteor_demod
  121. make
  122. sudo make install
  123. )
  124. log_done "meteor_demod installed"
  125. fi
  126. ### Install medet_arm
  127. if [ -e /usr/bin/medet_arm ]; then
  128. log_done "medet_arm was already installed"
  129. else
  130. log_running "Installing medet_arm..."
  131. sudo cp software/medet_arm /usr/bin/medet_arm
  132. sudo chmod +x /usr/bin/medet_arm
  133. log_done "medet_arm installed"
  134. fi
  135. ### Cron the scheduler
  136. crontab -l | grep -q "raspberry-noaa"
  137. if [ $? -eq 0 ]; then
  138. log_done "Crontab for schedule.sh already exists"
  139. else
  140. cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa/schedule.sh") | crontab -
  141. log_done "Crontab installed"
  142. fi
  143. ### Setup Nginx
  144. log_running "Setting up Nginx..."
  145. sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
  146. (
  147. sudo mkdir -p /var/www/wx
  148. sudo chown -R www-data:www-data /var/www/wx
  149. sudo usermod -a -G www-data pi
  150. sudo chmod 775 /var/www/wx
  151. )
  152. sudo systemctl restart nginx
  153. if [ ! -e /var/www/wx/index.html ]; then
  154. cp templates/index.html /var/www/wx/index.html
  155. fi
  156. if [ ! -e /var/www/wx/logo-small.png ]; then
  157. cp templates/logo-small.png /var/www/wx/logo-small.png
  158. fi
  159. log_done "Nginx configured"
  160. ### Setup ramFS
  161. cat /etc/fstab | grep -q "ramfs"
  162. if [ $? -eq 0 ]; then
  163. log_done "ramfs already setup"
  164. else
  165. sudo mkdir -p /var/ramfs
  166. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  167. log_done "Ramfs installed"
  168. fi
  169. set +e
  170. sudo mount -a
  171. set -e
  172. sudo chmod 777 /var/ramfs
  173. success "Install (almost) done!"
  174. echo "
  175. It's time to configure your ground station
  176. You'll be asked for your latitude and longitude
  177. Use negative values for South and West
  178. "
  179. read -rp "Enter your latitude (South values are negative): "
  180. lat=$REPLY
  181. read -rp "Enter your longitude (West values are negative): "
  182. lon=$REPLY
  183. read -rp "Enter your timezone (Ex: -3 for Argentina time): "
  184. timezone=$REPLY
  185. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.noaa.conf"
  186. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  187. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  188. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$timezone * -1" | bc)/g" "sun.py"
  189. # Running WXTOIMG to have the user accept the licensing agreement
  190. wxtoimg
  191. success "Install done! Double check your $HOME/.noaa.conf settings"
  192. echo "
  193. If you want to post your images to Twitter, please setup
  194. your Twitter credentials on $HOME/.tweepy.conf
  195. "