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.

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