Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

337 wiersze
9.0 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. if [ -e $(which predict) ]; then
  116. log_done "predict was already installed"
  117. else
  118. $orig_dir=$(pwd)
  119. cd software
  120. tar -xzf predict-2.2.7.tar.gz
  121. cd predict-2.2.7
  122. sudo ./configure #this also installs :X
  123. cd $orig_dir
  124. log_done "predict installed"
  125. fi
  126. ### Install default config file
  127. if [ -e "$HOME/.noaa.conf" ]; then
  128. log_done "$HOME/.noaa.conf already exists"
  129. else
  130. cp "templates/noaa.conf" "$HOME/.noaa.conf"
  131. log_done "$HOME/.noaa.conf installed"
  132. fi
  133. if [ -d "$HOME/.predict" ] && [ -e "$HOME/.predict/predict.qth" ]; then
  134. log_done "$HOME/.predict/predict.qth already exists"
  135. else
  136. mkdir "$HOME/.predict"
  137. cp "templates/predict.qth" "$HOME/.predict/predict.qth"
  138. log_done "$HOME/.predict/predict.qth installed"
  139. fi
  140. if [ -e "$HOME/.wxtoimgrc" ]; then
  141. log_done "$HOME/.wxtoimgrc already exists"
  142. else
  143. cp "templates/wxtoimgrc" "$HOME/.wxtoimgrc"
  144. log_done "$HOME/.wxtoimgrc installed"
  145. fi
  146. if [ -e "$HOME/.tweepy.conf" ]; then
  147. log_done "$HOME/.tweepy.conf already exists"
  148. else
  149. cp "templates/tweepy.conf" "$HOME/.tweepy.conf"
  150. log_done "$HOME/.tweepy.conf installed"
  151. fi
  152. ### Install meteor_demod
  153. if [ -e /usr/bin/meteor_demod ]; then
  154. log_done "meteor_demod was already installed"
  155. else
  156. log_running "Installing meteor_demod..."
  157. (
  158. cd /tmp
  159. git clone https://github.com/dbdexter-dev/meteor_demod.git
  160. cd meteor_demod
  161. make
  162. sudo make install
  163. )
  164. log_done "meteor_demod installed"
  165. fi
  166. ### Install medet_arm
  167. if [ -e /usr/bin/medet_arm ]; then
  168. log_done "medet_arm was already installed"
  169. else
  170. log_running "Installing medet_arm..."
  171. sudo cp software/medet_arm /usr/bin/medet_arm
  172. sudo chmod +x /usr/bin/medet_arm
  173. log_done "medet_arm installed"
  174. fi
  175. ### Cron the scheduler
  176. set +e
  177. crontab -l | grep -q "raspberry-noaa"
  178. if [ $? -eq 0 ]; then
  179. log_done "Crontab for schedule.sh already exists"
  180. else
  181. cat <(crontab -l) <(echo "1 0 * * * $HOME/raspberry-noaa/schedule.sh") | crontab -
  182. log_done "Crontab installed"
  183. fi
  184. set -e
  185. ### Setup Nginx
  186. log_running "Setting up Nginx..."
  187. usr=$(whoami)
  188. sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
  189. (
  190. sudo mkdir -p /var/www/wx/images
  191. sudo chown -R $usr:$usr /var/www/wx
  192. sudo usermod -a -G www-data $usr
  193. sudo chmod 775 /var/www/wx
  194. )
  195. sudo systemctl restart nginx
  196. sudo cp -rp templates/webpanel/* /var/www/wx/
  197. sed -i -e "s/pi/${usr}/g" "/var/www/wx/Model/Conn.php"
  198. log_done "Nginx configured"
  199. ### Setup ramFS
  200. SYSTEM_MEMORY=$(free -m | awk '/^Mem:/{print $2}')
  201. if [ "$SYSTEM_MEMORY" -lt 2000 ]; then
  202. sed -i -e "s/1000M/200M/g" templates/fstab
  203. fi
  204. set +e
  205. cat /etc/fstab | grep -q "ramfs"
  206. if [ $? -eq 0 ]; then
  207. log_done "ramfs already setup"
  208. else
  209. sudo mkdir -p /var/ramfs
  210. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  211. log_done "Ramfs installed"
  212. fi
  213. sudo mount -a
  214. sudo chmod 777 /var/ramfs
  215. set -e
  216. if [ -f "$HOME/raspberry-noaa/demod.py" ]; then
  217. log_done "pd120_decoder already installed"
  218. else
  219. wget -qr https://github.com/reynico/pd120_decoder/archive/master.zip -O /tmp/master.zip
  220. (
  221. cd /tmp
  222. unzip master.zip
  223. cd pd120_decoder-master/pd120_decoder/
  224. python3 -m pip install --user -r requirements.txt
  225. cp demod.py utils.py "$HOME/raspberry-noaa/"
  226. )
  227. log_done "pd120_decoder installed"
  228. fi
  229. success "Install (almost) done!"
  230. read -rp "Do you want to enable bias-tee? (y/N)"
  231. if [[ $REPLY =~ ^[Yy]$ ]]; then
  232. sed -i -e "s/enable_bias_tee/-T/g" "$HOME/.noaa.conf"
  233. log_done "Bias-tee is enabled!"
  234. else
  235. sed -i -e "s/enable_bias_tee//g" "$HOME/.noaa.conf"
  236. fi
  237. echo "
  238. Next we'll configure your webpanel language
  239. and locale settings - you can update these in the
  240. future by modifying 'lang' in /var/www/wx/Config.php
  241. and 'date_default_timezone_set' in /var/www/wx/header.php
  242. "
  243. # language configuration
  244. langs=($(find templates/webpanel/language/ -type f -printf "%f\n" | cut -f 1 -d '.'))
  245. while : ; do
  246. read -rp "Enter your preferred language (${langs[*]}): "
  247. lang=$REPLY
  248. if [[ ! " ${langs[@]} " =~ " ${lang} " ]]; then
  249. log_error "choice $lang is not one of the available options (${langs[*]})"
  250. else
  251. break
  252. fi
  253. done
  254. sed -i -e "s/'lang' => '.*'$/'lang' => '${lang}'/" "/var/www/wx/Config.php"
  255. echo "Visit https://www.php.net/manual/en/timezones.php for a list of available timezones"
  256. read -rp "Enter your preferred timezone: "
  257. timezone=$REPLY
  258. timezone=$(echo $timezone | sed 's/\//\\\//g')
  259. sed -i -e "s/date_default_timezone_set('.*');/date_default_timezone_set('${timezone}');/" "/var/www/wx/header.php"
  260. echo "
  261. It's time to configure your ground station
  262. You'll be asked for your latitude and longitude
  263. Use negative values for South and West
  264. "
  265. read -rp "Enter your latitude (South values are negative): "
  266. lat=$REPLY
  267. read -rp "Enter your longitude (West values are negative): "
  268. lon=$REPLY
  269. # note: this can probably be improved by calculating this
  270. # automatically - good for a future iteration
  271. read -rp "Enter your timezone offset (ex: -3 for Argentina time): "
  272. tzoffset=$REPLY
  273. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/pi/${usr}/g" "$HOME/.noaa.conf"
  274. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  275. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/$(echo "$lon * -1" | bc)/g" "$HOME/.predict/predict.qth"
  276. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$tzoffset * -1" | bc)/g" "sun.py"
  277. success "Install done! Double check your $HOME/.noaa.conf settings"
  278. echo "
  279. If you want to post your images to Twitter, please setup
  280. your Twitter credentials on $HOME/.tweepy.conf
  281. "
  282. set +e
  283. ### Running WXTOIMG to have the user accept the licensing agreement
  284. wxtoimg
  285. read -rp "reboot now? (Y/n)"
  286. doreboot=$REPLY
  287. [ ! -z "$doreboot" ] || sudo reboot
  288. [ "$doreboot" == "y" ] && sudo reboot