fourier_install.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # version 1.0.2
  2. # install essential software
  3. # sudo apt-get update
  4. installer_version=1.0.3
  5. programspath=~/programs
  6. installerpath=$(pwd)
  7. configfile='/etc/fourier-config.json'
  8. gitbase="gogs@git.miralo.xyz:AudioValid"
  9. tunnel_user=rtunnel
  10. datapath='/var/fourier'
  11. serverhost='monitor.audiovalid.com'
  12. tunnelfile="$programspath/ssh-tunnel.sh"
  13. mysql_user=fourier
  14. mysql_passwd='Sup3rDuper!'
  15. mysql_db=fourier
  16. mount_point=/media/datadrive
  17. echo "Fourier installer $installer_version"
  18. echo "------------------------------------"
  19. if [[ "$OSTYPE" == darwin* ]]; then
  20. programspath=~/fourier
  21. fi
  22. clonerepo() {
  23. GIT_SSH_COMMAND="ssh -i $installerpath/repokey -o StrictHostKeychecking=no" \
  24. git clone $gitbase/$1 $2
  25. }
  26. [ ! -d "$programspath" ] && mkdir $programspath
  27. read -p "Whats this box port (last 3 numbers with zero for padding)? " PORT
  28. read -p "How many receivers has this box? " RECEIVERS_COUNT
  29. read -p "Box ID (or rolame url id): " BOX_ID
  30. curl -f -H "Accept: text/plain" "https://rola.me/$BOX_ID" \
  31. 1>/tmp/fourier-api \
  32. 2>/dev/null
  33. if [ "$?" -eq 0 ]; then
  34. IFS=':' read -ra APIDATA <<< "$(cat /tmp/fourier-api)"
  35. BOX_ID="${APIDATA[0]}"
  36. API_SECRET="${APIDATA[1]}"
  37. rm /tmp/fourier-api
  38. else
  39. read -p "API secret: " API_SECRET
  40. fi
  41. sudo apt-get install -y python python-pip python-setuptools
  42. findmnt "$mount_point"
  43. if [ "$?" -neq 0 ]; then
  44. echo -e 'Data drive is not mounted'
  45. fi
  46. if [[ "$OSTYPE" == darwin* ]]; then
  47. keyfile="$programspath/fourier.key"
  48. [ ! -f "$keyfile" ] && ssh-keygen -t rsa -b 2048 -f $keyfile
  49. else
  50. keyspath=~/.ssh
  51. keyfile="$keyspath/id_rsa"
  52. [ ! -d "$keyspath" ] && mkdir $keyspath
  53. ssh-keygen -t rsa -b 2048 -C "$HOSTNAME" -P "" -f $keyfile
  54. fi
  55. keycontent=$(cat $keyfile.pub)
  56. curl -X POST -F "key=$keycontent" \
  57. -H "Authorization: $BOX_ID $API_SECRET" \
  58. https://api.audiovalid.com/public-key
  59. if [[ "$OSTYPE" == darwin* ]]; then
  60. depend=( python gcc vim tmux autossh lame nodejs \
  61. ezstream libusb rtl-sdr portaudio )
  62. for dep in "${depend[@]}"
  63. do
  64. brew list $dep > /dev/null
  65. [ "$?" -eq 1 ] && brew install $dep
  66. done
  67. envpath="$programspath/env"
  68. [ ! -d "$envpath" ] && virtualenv $programspath/env
  69. source $envpath/bin/activate
  70. pip install -r $installerpath/requirements.txt
  71. else
  72. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  73. sudo apt-get install -y alsa-utils alsa-tools
  74. sudo apt-get install -y libudev-dev
  75. sudo apt-get install -y tmux
  76. sudo apt-get install -y vim
  77. sudo apt-get install -y autossh
  78. sudo apt-get install -y git-core
  79. sudo apt-get install -y build-essential
  80. sudo apt-get install -y nodejs
  81. sudo apt-get install -y python-dev
  82. sudo apt-get install -y lame
  83. sudo apt-get install -y ezstream
  84. sudo apt-get install -y cmake
  85. sudo apt-get install -y rtl-sdr
  86. sudo apt-get install -y sqlite3
  87. sudo apt-get install -y portaudio19-dev
  88. sudo apt install dvb-apps
  89. sudo pip install pyaudio pyusb pydub numpy requests \
  90. scipy python-firebase
  91. sudo apt-get install -y ffmpeg
  92. sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
  93. sudo apt-get install -y python-matplotlib
  94. sudo apt-get install -y curl
  95. sudo pip install
  96. sudo npm install -g http-server
  97. cd tools
  98. sudo python ./setup.py install
  99. cd ..
  100. fi
  101. sudo chmod 0600 $installerpath/repokey
  102. cd $programspath
  103. clonerepo fourier-module.git module
  104. clonerepo fourier-common.git common
  105. clonerepo fourier-server.git server
  106. clonerepo fourier-fourier.git fourier
  107. clonerepo fourier-alt.git fourier-alt
  108. clonerepo fourier-monitor.git monitor
  109. clonerepo fourier-uploader.git uploader
  110. clonerepo fourier-ondemand.git ondemand
  111. cd $programspath/server
  112. npm install
  113. cd $programspath/monitor
  114. npm install
  115. cd $programspath/uploader
  116. npm install
  117. cd $programspath/module
  118. sudo python setup.py install
  119. cd $programspath/ondemand
  120. sudo python setup.py install
  121. sudo npm install -g pm2
  122. # build sdr lib
  123. if [[ "$OSTYPE" != darwin* ]]; then
  124. sudo apt-get install -y libusb-1.0-0-dev
  125. cd $programspath
  126. clonerepo rtl-sdr.git rtl-sdr
  127. cd $programspath/rtl-sdr
  128. mkdir build
  129. cd build
  130. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  131. make
  132. sudo cp ./src/rtl_fm /usr/bin/rtl_fm
  133. echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules
  134. fi
  135. [ ! -f "$configfile" ] && \
  136. sudo python $installerpath/configure.py \
  137. $installerpath/fourier-config.json \
  138. $configfile \
  139. -programs "$programspath" \
  140. -receivers $RECEIVERS_COUNT \
  141. -api-secret $API_SECRET \
  142. -box-id "$BOX_ID"
  143. if [ "$?" -eq 0 ]; then
  144. cd "$programspath"
  145. pm2 start server
  146. pm2 start monitor
  147. pm2 start uploader
  148. pm2 start ondemand/ondemand/service.py \
  149. --interpreter=python \
  150. --name=ondemand
  151. pm2 start http-server
  152. pm2 save
  153. pm2 startup
  154. sudo env PATH=$PATH:/usr/bin \
  155. /usr/lib/node_modules/pm2/bin/pm2 \
  156. startup systemd -u fourier \
  157. --hp ~/
  158. fi
  159. if [ ! -f "/etc/systemd/system/ssh-tunnel.service" ]; then
  160. echo "/usr/bin/autossh -N -f -M 7$PORT -oPubkeyAuthentication=yes -oPasswordAuthentication=no -oLogLevel=error -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i $keyfile -R 6$PORT:localhost:22 $tunnel_user@$serverhost -p 22" > $tunnelfile
  161. sudo mv $installerpath/ssh-tunnel.service \
  162. /etc/systemd/system/ssh-tunnel.service
  163. sudo systemctl enable ssh-tunnel
  164. sudo systemctl start ssh-tunnel
  165. fi
  166. if [[ "$OSTYPE" != darwin* ]]; then
  167. sudo mysql -u root -e "create database $mysql_db;"
  168. sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';"
  169. sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;"
  170. cd ~
  171. sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql
  172. sudo cp $installerpath/fourier-key.json /etc/Fourier-key.json
  173. fi