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.
 
 
 
 
 
 

368 lines
10 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.3-fpm \
  62. php7.3-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 librtlsdr..."
  90. (
  91. cd /tmp/
  92. git clone https://github.com/librtlsdr/librtlsdr.git
  93. cd librtlsdr/
  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 command -v predict &> /dev/null; 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 ]; then
  167. log_done "medet was already installed"
  168. else
  169. if [[ $(uname -m) == *"arm"* ]]; then
  170. log_running "Installing medet_arm..."
  171. sudo cp software/medet_arm /usr/bin/medet
  172. elif [[ $(uname -m) == *"x86_64"* ]]; then
  173. log_running "Installing medet_x86_64..."
  174. sudo cp software/medet_x86_64 /usr/bin/medet
  175. else
  176. log_error "Unknown archictecture $(uname -m)!"
  177. exit -1
  178. fi
  179. sudo chmod +x /usr/bin/medet
  180. log_done "medet installed"
  181. fi
  182. ### Install noaa-apt
  183. if command -v noaa-apt &> /dev/null; then
  184. log_done "noaa-apt was already installed"
  185. else
  186. if [[ $(uname -m) == *"arm"* ]]; then
  187. log_running "Installing noaa-apt arm..."
  188. unzip software/noaa-apt-1.3.0-armv7-linux-gnueabihf-nogui.zip
  189. sudo mv noaa-apt /usr/bin
  190. sudo mv res /usr/bin #ok, this is not so nice, but it works
  191. elif [[ $(uname -m) == *"x86_64"* ]]; then
  192. log_running "Installing noaa-apt x86..."
  193. sudo dpkg -i software/noaa-apt_1.3.0-1_amd64.deb
  194. else
  195. log_error "Unknown archictecture $(uname -m)!"
  196. exit -1
  197. fi
  198. mkdir -p "$HOME/.config/noaa-apt"
  199. cp templates/settings.toml "$HOME/.config/noaa-apt"
  200. log_done "noaa-apt installed"
  201. fi
  202. ### Cron the scheduler
  203. set +e
  204. crontab -l | grep -q "raspberry-noaa"
  205. if [ $? -eq 0 ]; then
  206. log_done "Crontab for schedule.sh already exists"
  207. else
  208. cat <(crontab -l) <(echo "1 0 * * * $HOME/raspberry-noaa/schedule.sh") | crontab -
  209. log_done "Crontab installed"
  210. fi
  211. set -e
  212. ### Setup Nginx
  213. log_running "Setting up Nginx..."
  214. usr=$(whoami)
  215. sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default
  216. (
  217. sudo mkdir -p /var/www/wx/images
  218. sudo chown -R $usr:$usr /var/www/wx
  219. sudo usermod -a -G www-data $usr
  220. sudo chmod 775 /var/www/wx
  221. )
  222. sudo systemctl restart nginx
  223. sudo cp -rp templates/webpanel/* /var/www/wx/
  224. sed -i -e "s/pi/${usr}/g" "/var/www/wx/Model/Conn.php"
  225. log_done "Nginx configured"
  226. ### Setup ramFS
  227. SYSTEM_MEMORY=$(free -m | awk '/^Mem:/{print $2}')
  228. if [ "$SYSTEM_MEMORY" -lt 2000 ]; then
  229. sed -i -e "s/1000M/200M/g" templates/fstab
  230. fi
  231. set +e
  232. cat /etc/fstab | grep -q "ramfs"
  233. if [ $? -eq 0 ]; then
  234. log_done "ramfs already setup"
  235. else
  236. sudo mkdir -p /var/ramfs
  237. cat templates/fstab | sudo tee -a /etc/fstab > /dev/null
  238. log_done "Ramfs installed"
  239. fi
  240. sudo mount -a
  241. sudo chmod 777 /var/ramfs
  242. set -e
  243. if [ -f "$HOME/raspberry-noaa/demod.py" ]; then
  244. log_done "pd120_decoder already installed"
  245. else
  246. wget -qr https://github.com/reynico/pd120_decoder/archive/master.zip -O /tmp/master.zip
  247. (
  248. cd /tmp
  249. unzip master.zip
  250. cd pd120_decoder-master/pd120_decoder/
  251. python3 -m pip install --user -r requirements.txt
  252. cp demod.py utils.py "$HOME/raspberry-noaa/"
  253. )
  254. log_done "pd120_decoder installed"
  255. fi
  256. success "Install (almost) done!"
  257. read -rp "Do you want to enable bias-tee? (y/N)"
  258. if [[ $REPLY =~ ^[Yy]$ ]]; then
  259. sed -i -e "s/enable_bias_tee/-T/g" "$HOME/.noaa.conf"
  260. log_done "Bias-tee is enabled!"
  261. else
  262. sed -i -e "s/enable_bias_tee//g" "$HOME/.noaa.conf"
  263. fi
  264. echo "
  265. Next we'll configure your webpanel language
  266. and locale settings - you can update these in the
  267. future by modifying 'lang' in /var/www/wx/Config.php
  268. and 'date_default_timezone_set' in /var/www/wx/header.php
  269. "
  270. # language configuration
  271. langs=($(find templates/webpanel/language/ -type f -printf "%f\n" | cut -f 1 -d '.'))
  272. while : ; do
  273. read -rp "Enter your preferred language (${langs[*]}): "
  274. lang=$REPLY
  275. if [[ ! " ${langs[@]} " =~ " ${lang} " ]]; then
  276. log_error "choice $lang is not one of the available options (${langs[*]})"
  277. else
  278. break
  279. fi
  280. done
  281. sed -i -e "s/'lang' => '.*'$/'lang' => '${lang}'/" "/var/www/wx/Config.php"
  282. echo "Visit https://www.php.net/manual/en/timezones.php for a list of available timezones"
  283. read -rp "Enter your preferred timezone: "
  284. timezone=$REPLY
  285. timezone=$(echo $timezone | sed 's/\//\\\//g')
  286. sed -i -e "s/date_default_timezone_set('.*');/date_default_timezone_set('${timezone}');/" "/var/www/wx/header.php"
  287. echo "
  288. It's time to configure your ground station
  289. You'll be asked for your latitude and longitude
  290. Use negative values for South and West
  291. "
  292. read -rp "Enter your latitude (South values are negative): "
  293. lat=$REPLY
  294. read -rp "Enter your longitude (West values are negative): "
  295. lon=$REPLY
  296. # note: this can probably be improved by calculating this
  297. # automatically - good for a future iteration
  298. read -rp "Enter your timezone offset (ex: -3 for Argentina time): "
  299. tzoffset=$REPLY
  300. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/pi/${usr}/g" "$HOME/.noaa.conf"
  301. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.wxtoimgrc"
  302. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "$HOME/.predict/predict.qth"
  303. sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g;s/change_tz/$(echo "$tzoffset * -1" | bc)/g" "sun.py"
  304. sed -i -e "s/change_tz/$tzoffset/g" "$HOME/.config/noaa-apt/settings.toml"
  305. sed -i -e "s/change_tz/$tzoffset/g" "sun.py"
  306. success "Install done! Double check your $HOME/.noaa.conf settings"
  307. echo "
  308. If you want to post your images to Twitter, please setup
  309. your Twitter credentials on $HOME/.tweepy.conf
  310. "
  311. set +e
  312. ### Running WXTOIMG to have the user accept the licensing agreement
  313. wxtoimg
  314. read -rp "reboot now? (Y/n)"
  315. doreboot=$REPLY
  316. [ ! -z "$doreboot" ] || sudo reboot
  317. [ "$doreboot" == "y" ] && sudo reboot