Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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