Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

227 rindas
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. set +e
  137. crontab -l | grep -q "raspberry-noaa"
  138. if [ $? -eq 0 ]; then
  139. log_done "Crontab for schedule.sh already exists"
  140. else
  141. cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa/schedule.sh") | crontab -
  142. log_done "Crontab installed"
  143. fi
  144. set -e
  145. ### Setup Nginx
  146. log_running "Setting up Nginx..."
  147. sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
  148. (
  149. sudo mkdir -p /var/www/wx
  150. sudo chown -R www-data:www-data /var/www/wx
  151. sudo usermod -a -G www-data pi
  152. sudo chmod 775 /var/www/wx
  153. )
  154. sudo systemctl restart nginx
  155. if [ ! -e /var/www/wx/index.html ]; then
  156. sudo cp templates/index.html /var/www/wx/index.html
  157. fi
  158. if [ ! -e /var/www/wx/logo-small.png ]; then
  159. sudo cp templates/logo-small.png /var/www/wx/logo-small.png
  160. fi
  161. log_done "Nginx configured"
  162. ### Setup ramFS
  163. set +e
  164. cat /etc/fstab | grep -q "ramfs"
  165. if [ $? -eq 0 ]; then
  166. log_done "ramfs already setup"
  167. else
  168. sudo mkdir -p /var/ramfs
  169. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  170. log_done "Ramfs installed"
  171. fi
  172. sudo mount -a
  173. sudo chmod 777 /var/ramfs
  174. set -e
  175. success "Install (almost) done!"
  176. echo "
  177. It's time to configure your ground station
  178. You'll be asked for your latitude and longitude
  179. Use negative values for South and West
  180. "
  181. read -rp "Enter your latitude (South values are negative): "
  182. lat=$REPLY
  183. read -rp "Enter your longitude (West values are negative): "
  184. lon=$REPLY
  185. read -rp "Enter your timezone (Ex: -3 for Argentina time): "
  186. timezone=$REPLY
  187. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.noaa.conf"
  188. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  189. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  190. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$timezone * -1" | bc)/g" "sun.py"
  191. # Running WXTOIMG to have the user accept the licensing agreement
  192. wxtoimg
  193. success "Install done! Double check your $HOME/.noaa.conf settings"
  194. echo "
  195. If you want to post your images to Twitter, please setup
  196. your Twitter credentials on $HOME/.tweepy.conf
  197. "