Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

install.sh 6.7 KiB

4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/images
  161. sudo chown -R www-data:www-data /var/www/wx/images
  162. sudo usermod -a -G www-data pi
  163. sudo chmod 775 /var/www/wx/images
  164. )
  165. sudo systemctl restart nginx
  166. sudo cp -rp templates/webpanel/* /var/www/wx/
  167. log_done "Nginx configured"
  168. ### Setup ramFS
  169. SYSTEM_MEMORY=$(free -m | awk '/^Mem:/{print $2}')
  170. if [ "$SYSTEM_MEMORY" -lt 2000 ]; then
  171. sed -i -e "s/1000M/200M/g" templates/fstab
  172. fi
  173. set +e
  174. cat /etc/fstab | grep -q "ramfs"
  175. if [ $? -eq 0 ]; then
  176. log_done "ramfs already setup"
  177. else
  178. sudo mkdir -p /var/ramfs
  179. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  180. log_done "Ramfs installed"
  181. fi
  182. sudo mount -a
  183. sudo chmod 777 /var/ramfs
  184. set -e
  185. success "Install (almost) done!"
  186. read -rp "Do you want to enable bias-tee? (y/N)"
  187. if [[ $REPLY =~ ^[Yy]$ ]]; then
  188. sed -i -e "s/enable_bias_tee/-T/g" "$HOME/.noaa.conf"
  189. log_done "Bias-tee is enabled!"
  190. else
  191. sed -i -e "s/enable_bias_tee//g" "$HOME/.noaa.conf"
  192. fi
  193. echo "
  194. It's time to configure your ground station
  195. You'll be asked for your latitude and longitude
  196. Use negative values for South and West
  197. "
  198. read -rp "Enter your latitude (South values are negative): "
  199. lat=$REPLY
  200. read -rp "Enter your longitude (West values are negative): "
  201. lon=$REPLY
  202. read -rp "Enter your timezone (Ex: -3 for Argentina time): "
  203. timezone=$REPLY
  204. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.noaa.conf"
  205. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  206. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  207. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$timezone * -1" | bc)/g" "sun.py"
  208. success "Install done! Double check your $HOME/.noaa.conf settings"
  209. echo "
  210. If you want to post your images to Twitter, please setup
  211. your Twitter credentials on $HOME/.tweepy.conf
  212. "
  213. set +e
  214. ### Fix permissions on audio/meteor/images folder
  215. sudo chmod -R 775 /var/www/wx/audio/
  216. sudo chmod -R 775 /var/www/wx/images/
  217. sudo chmod -R 775 /var/www/wx/meteor/
  218. ### Running WXTOIMG to have the user accept the licensing agreement
  219. wxtoimg
  220. sudo reboot