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.
 
 
 
 
 
 

259 lines
6.6 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. ### 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. success "Install (almost) done!"
  190. read -rp "Do you want to enable bias-tee? (y/N)"
  191. if [[ $REPLY =~ ^[Yy]$ ]]; then
  192. sed -i -e "s/enable_bias_tee/-T/g" "$HOME/.noaa.conf"
  193. log_done "Bias-tee is enabled!"
  194. else
  195. sed -i -e "s/enable_bias_tee//g" "$HOME/.noaa.conf"
  196. fi
  197. echo "
  198. It's time to configure your ground station
  199. You'll be asked for your latitude and longitude
  200. Use negative values for South and West
  201. "
  202. read -rp "Enter your latitude (South values are negative): "
  203. lat=$REPLY
  204. read -rp "Enter your longitude (West values are negative): "
  205. lon=$REPLY
  206. read -rp "Enter your timezone (Ex: -3 for Argentina time): "
  207. timezone=$REPLY
  208. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.noaa.conf"
  209. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  210. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  211. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$timezone * -1" | bc)/g" "sun.py"
  212. success "Install done! Double check your $HOME/.noaa.conf settings"
  213. echo "
  214. If you want to post your images to Twitter, please setup
  215. your Twitter credentials on $HOME/.tweepy.conf
  216. "
  217. set +e
  218. sudo mkdir -p /usr/share/html/iss
  219. ### Running WXTOIMG to have the user accept the licensing agreement
  220. wxtoimg
  221. sudo reboot