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

330 行
8.8 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. log_error() {
  22. echo " ${RED}error: $1${RESET}"
  23. }
  24. success() {
  25. echo "${GREEN}$1${RESET}"
  26. }
  27. ### Run as a normal user
  28. if [ $EUID -eq 0 ]; then
  29. die "This script shouldn't be run as root."
  30. fi
  31. ### Verify cloned repo
  32. if [ ! -e "$HOME/raspberry-noaa" ]; then
  33. die "Is https://github.com/reynico/raspberry-noaa cloned in your home directory?"
  34. fi
  35. ### Install required packages
  36. log_running "Installing required packages..."
  37. raspbian_version="$(lsb_release -c --short)"
  38. if [ "$raspbian_version" == "stretch" ]; then
  39. wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
  40. echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php7.list
  41. fi
  42. sudo apt update -yq
  43. sudo apt install -yq python-setuptools \
  44. ntp \
  45. unzip zip \
  46. cmake \
  47. libusb-1.0-0-dev \
  48. sox libsox-fmt-mp3 \
  49. at \
  50. bc \
  51. nginx \
  52. libncurses5-dev \
  53. libncursesw5-dev \
  54. libatlas-base-dev \
  55. python3-pip \
  56. imagemagick \
  57. libxft-dev \
  58. libxft2 \
  59. libjpeg9 \
  60. libjpeg9-dev \
  61. socat \
  62. php7.4-fpm \
  63. php7.4-sqlite3 \
  64. sqlite3
  65. if [ "$raspbian_version" == "stretch" ]; then
  66. sudo apt install -yq libgfortran-5-dev
  67. else
  68. sudo apt install -yq libgfortran5
  69. fi
  70. sudo python3 -m pip install numpy ephem tweepy Pillow
  71. log_done "Packages installed"
  72. ### Create the database schema
  73. if [ -e "$HOME/raspberry-noaa/panel.db" ]; then
  74. log_done "Database already created"
  75. else
  76. sqlite3 "panel.db" < "templates/webpanel_schema.sql"
  77. log_done "Database schema created"
  78. fi
  79. ### Blacklist DVB modules
  80. if [ -e /etc/modprobe.d/rtlsdr.conf ]; then
  81. log_done "DVB modules were already blacklisted"
  82. else
  83. sudo cp templates/modprobe.d/rtlsdr.conf /etc/modprobe.d/rtlsdr.conf
  84. log_done "DVB modules are blacklisted now"
  85. fi
  86. ### Install RTL-SDR
  87. if [ -e /usr/local/bin/rtl_fm ]; then
  88. log_done "rtl-sdr was already installed"
  89. else
  90. log_running "Installing rtl-sdr from osmocom..."
  91. (
  92. cd /tmp/
  93. git clone https://github.com/osmocom/rtl-sdr.git
  94. cd rtl-sdr/
  95. mkdir build
  96. cd build
  97. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  98. make
  99. sudo make install
  100. sudo ldconfig
  101. cd /tmp/
  102. sudo cp ./rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/
  103. )
  104. log_done "rtl-sdr install done"
  105. fi
  106. ### Install WxToIMG
  107. if [ -e /usr/local/bin/xwxtoimg ]; then
  108. log_done "WxToIMG was already installed"
  109. else
  110. log_running "Installing WxToIMG..."
  111. sudo dpkg -i software/wxtoimg-armhf-2.11.2-beta.deb
  112. log_done "WxToIMG installed"
  113. fi
  114. ### install predict
  115. $orig_dir=$(pwd)
  116. cd software
  117. #todo: Build predict
  118. cd $orig_dir
  119. ### Install default config file
  120. if [ -e "$HOME/.noaa.conf" ]; then
  121. log_done "$HOME/.noaa.conf already exists"
  122. else
  123. cp "templates/noaa.conf" "$HOME/.noaa.conf"
  124. log_done "$HOME/.noaa.conf installed"
  125. fi
  126. if [ -d "$HOME/.predict" ] && [ -e "$HOME/.predict/predict.qth" ]; then
  127. log_done "$HOME/.predict/predict.qth already exists"
  128. else
  129. mkdir "$HOME/.predict"
  130. cp "templates/predict.qth" "$HOME/.predict/predict.qth"
  131. log_done "$HOME/.predict/predict.qth installed"
  132. fi
  133. if [ -e "$HOME/.wxtoimgrc" ]; then
  134. log_done "$HOME/.wxtoimgrc already exists"
  135. else
  136. cp "templates/wxtoimgrc" "$HOME/.wxtoimgrc"
  137. log_done "$HOME/.wxtoimgrc installed"
  138. fi
  139. if [ -e "$HOME/.tweepy.conf" ]; then
  140. log_done "$HOME/.tweepy.conf already exists"
  141. else
  142. cp "templates/tweepy.conf" "$HOME/.tweepy.conf"
  143. log_done "$HOME/.tweepy.conf installed"
  144. fi
  145. ### Install meteor_demod
  146. if [ -e /usr/bin/meteor_demod ]; then
  147. log_done "meteor_demod was already installed"
  148. else
  149. log_running "Installing meteor_demod..."
  150. (
  151. cd /tmp
  152. git clone https://github.com/dbdexter-dev/meteor_demod.git
  153. cd meteor_demod
  154. make
  155. sudo make install
  156. )
  157. log_done "meteor_demod installed"
  158. fi
  159. ### Install medet_arm
  160. if [ -e /usr/bin/medet_arm ]; then
  161. log_done "medet_arm was already installed"
  162. else
  163. log_running "Installing medet_arm..."
  164. sudo cp software/medet_arm /usr/bin/medet_arm
  165. sudo chmod +x /usr/bin/medet_arm
  166. log_done "medet_arm installed"
  167. fi
  168. ### Cron the scheduler
  169. set +e
  170. crontab -l | grep -q "raspberry-noaa"
  171. if [ $? -eq 0 ]; then
  172. log_done "Crontab for schedule.sh already exists"
  173. else
  174. cat <(crontab -l) <(echo "1 0 * * * $HOME/raspberry-noaa/schedule.sh") | crontab -
  175. log_done "Crontab installed"
  176. fi
  177. set -e
  178. ### Setup Nginx
  179. log_running "Setting up Nginx..."
  180. usr=$(whoami)
  181. sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
  182. (
  183. sudo mkdir -p /var/www/wx/images
  184. sudo chown -R $usr:$usr /var/www/wx
  185. sudo usermod -a -G www-data $usr
  186. sudo chmod 775 /var/www/wx
  187. )
  188. sudo systemctl restart nginx
  189. sudo cp -rp templates/webpanel/* /var/www/wx/
  190. sed -i -e "s/pi/${usr}/g" "/var/www/wx/Model/Conn.php"
  191. log_done "Nginx configured"
  192. ### Setup ramFS
  193. SYSTEM_MEMORY=$(free -m | awk '/^Mem:/{print $2}')
  194. if [ "$SYSTEM_MEMORY" -lt 2000 ]; then
  195. sed -i -e "s/1000M/200M/g" templates/fstab
  196. fi
  197. set +e
  198. cat /etc/fstab | grep -q "ramfs"
  199. if [ $? -eq 0 ]; then
  200. log_done "ramfs already setup"
  201. else
  202. sudo mkdir -p /var/ramfs
  203. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  204. log_done "Ramfs installed"
  205. fi
  206. sudo mount -a
  207. sudo chmod 777 /var/ramfs
  208. set -e
  209. if [ -f "$HOME/raspberry-noaa/demod.py" ]; then
  210. log_done "pd120_decoder already installed"
  211. else
  212. wget -qr https://github.com/reynico/pd120_decoder/archive/master.zip -O /tmp/master.zip
  213. (
  214. cd /tmp
  215. unzip master.zip
  216. cd pd120_decoder-master/pd120_decoder/
  217. python3 -m pip install --user -r requirements.txt
  218. cp demod.py utils.py "$HOME/raspberry-noaa/"
  219. )
  220. log_done "pd120_decoder installed"
  221. fi
  222. success "Install (almost) done!"
  223. read -rp "Do you want to enable bias-tee? (y/N)"
  224. if [[ $REPLY =~ ^[Yy]$ ]]; then
  225. sed -i -e "s/enable_bias_tee/-T/g" "$HOME/.noaa.conf"
  226. log_done "Bias-tee is enabled!"
  227. else
  228. sed -i -e "s/enable_bias_tee//g" "$HOME/.noaa.conf"
  229. fi
  230. echo "
  231. Next we'll configure your webpanel language
  232. and locale settings - you can update these in the
  233. future by modifying 'lang' in /var/www/wx/Config.php
  234. and 'date_default_timezone_set' in /var/www/wx/header.php
  235. "
  236. # language configuration
  237. langs=($(find templates/webpanel/language/ -type f -printf "%f\n" | cut -f 1 -d '.'))
  238. while : ; do
  239. read -rp "Enter your preferred language (${langs[*]}): "
  240. lang=$REPLY
  241. if [[ ! " ${langs[@]} " =~ " ${lang} " ]]; then
  242. log_error "choice $lang is not one of the available options (${langs[*]})"
  243. else
  244. break
  245. fi
  246. done
  247. sed -i -e "s/'lang' => '.*'$/'lang' => '${lang}'/" "/var/www/wx/Config.php"
  248. echo "Visit https://www.php.net/manual/en/timezones.php for a list of available timezones"
  249. read -rp "Enter your preferred timezone: "
  250. timezone=$REPLY
  251. timezone=$(echo $timezone | sed 's/\//\\\//g')
  252. sed -i -e "s/date_default_timezone_set('.*');/date_default_timezone_set('${timezone}');/" "/var/www/wx/header.php"
  253. echo "
  254. It's time to configure your ground station
  255. You'll be asked for your latitude and longitude
  256. Use negative values for South and West
  257. "
  258. read -rp "Enter your latitude (South values are negative): "
  259. lat=$REPLY
  260. read -rp "Enter your longitude (West values are negative): "
  261. lon=$REPLY
  262. # note: this can probably be improved by calculating this
  263. # automatically - good for a future iteration
  264. read -rp "Enter your timezone offset (ex: -3 for Argentina time): "
  265. tzoffset=$REPLY
  266. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/pi/${usr}/g" "$HOME/.noaa.conf"
  267. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  268. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  269. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$tzoffset * -1" | bc)/g" "sun.py"
  270. success "Install done! Double check your $HOME/.noaa.conf settings"
  271. echo "
  272. If you want to post your images to Twitter, please setup
  273. your Twitter credentials on $HOME/.tweepy.conf
  274. "
  275. set +e
  276. ### Running WXTOIMG to have the user accept the licensing agreement
  277. wxtoimg
  278. read -rp "reboot now? (Y/n)"
  279. doreboot=$REPLY
  280. [ ! -z "$doreboot" ] || sudo reboot
  281. [ "$doreboot" == "y" ] && sudo reboot