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

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