fourier_install.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. # version 1.0.4
  2. # install essential software
  3. # sudo apt-get update
  4. installer_version=1.0.4
  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: " BOX_ID
  30. read -p "API secret: " API_SECRET
  31. sudo apt-get install -y python python-pip python-setuptools
  32. findmnt "$mount_point"
  33. if [ "$?" -neq 0 ]; then
  34. echo -e 'Data drive is not mounted'
  35. fi
  36. if [[ "$OSTYPE" == darwin* ]]; then
  37. keyfile="$programspath/fourier.key"
  38. [ ! -f "$keyfile" ] && ssh-keygen -t rsa -b 2048 -f $keyfile
  39. else
  40. keyspath=~/.ssh
  41. keyfile="$keyspath/id_rsa"
  42. [ ! -d "$keyspath" ] && mkdir $keyspath
  43. ssh-keygen -t rsa -b 2048 -C "$HOSTNAME" -P "" -f $keyfile
  44. fi
  45. keycontent=$(cat $keyfile.pub)
  46. curl -X POST -F "key=$keycontent" \
  47. -H "Authorization: $BOX_ID $API_SECRET" \
  48. https://api.audiovalid.com/public-key
  49. # Give permissions to tune DVB devices
  50. # So it can use the devices in /dev/dvb/adapter*
  51. sudo usermod -a -G video fourier
  52. if [[ "$OSTYPE" == darwin* ]]; then
  53. depend=( python gcc vim tmux autossh lame nodejs \
  54. ezstream libusb rtl-sdr portaudio )
  55. for dep in "${depend[@]}"
  56. do
  57. brew list $dep > /dev/null
  58. [ "$?" -eq 1 ] && brew install $dep
  59. done
  60. envpath="$programspath/env"
  61. [ ! -d "$envpath" ] && virtualenv $programspath/env
  62. source $envpath/bin/activate
  63. pip install -r $installerpath/requirements.txt
  64. else
  65. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  66. sudo apt-get install -y alsa-utils alsa-tools
  67. sudo apt-get install -y libudev-dev
  68. sudo apt-get install -y tmux
  69. sudo apt-get install -y vim
  70. sudo apt-get install -y autossh
  71. sudo apt-get install -y git-core
  72. sudo apt-get install -y build-essential
  73. sudo apt-get install -y nodejs
  74. sudo apt-get install -y python-dev
  75. sudo apt-get install -y lame
  76. sudo apt-get install -y ezstream
  77. sudo apt-get install -y cmake
  78. sudo apt-get install -y rtl-sdr
  79. sudo apt-get install -y sqlite3
  80. sudo apt-get install -y portaudio19-dev
  81. sudo apt-get install -y dvb-apps
  82. sudo pip install pyaudio pyusb pydub numpy requests \
  83. scipy python-firebase tornado mutagen \
  84. pyopenssl
  85. sudo apt-get install -y ffmpeg
  86. sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
  87. sudo apt-get install -y python-matplotlib
  88. sudo apt-get install -y curl
  89. sudo apt-get install -y libshout3 libshout3-dev
  90. sudo npm install -g http-server
  91. cd tools
  92. sudo python ./setup.py install
  93. cd ..
  94. fi
  95. sudo chmod 0600 $installerpath/repokey
  96. cd $programspath
  97. clonerepo fourier-module.git module
  98. clonerepo fourier-common.git common
  99. clonerepo fourier-recorder.git recorder
  100. clonerepo fourier-fourier.git fourier
  101. clonerepo fourier-alt.git fourier-alt
  102. clonerepo fourier-monitor.git monitor
  103. clonerepo fourier-uploader.git uploader
  104. clonerepo fourier-ondemand.git ondemand
  105. cd $programspath/recorder
  106. npm install
  107. cd $programspath/monitor
  108. npm install
  109. cd $programspath/uploader
  110. npm install
  111. cd $programspath/module
  112. sudo python setup.py install
  113. cd $programspath/ondemand
  114. sudo python setup.py install
  115. sudo npm install -g pm2
  116. # build sdr lib
  117. if [[ "$OSTYPE" != darwin* ]]; then
  118. sudo apt-get install -y libusb-1.0-0-dev
  119. cd $programspath
  120. clonerepo rtl-sdr.git rtl-sdr
  121. cd $programspath/rtl-sdr
  122. mkdir build
  123. cd build
  124. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  125. make
  126. sudo cp ./src/rtl_fm /usr/bin/rtl_fm
  127. echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules
  128. fi
  129. [ ! -f "$configfile" ] && \
  130. sudo python $installerpath/configure.py \
  131. $installerpath/fourier-config.json \
  132. $configfile \
  133. -programs "$programspath" \
  134. -receivers $RECEIVERS_COUNT \
  135. -api-secret $API_SECRET \
  136. -box-id "$BOX_ID"
  137. echo "** Downloading TV channels."
  138. fourier tv update
  139. if [ "$?" -eq 0 ]; then
  140. cd "$programspath"
  141. pm2 start recorder
  142. pm2 start monitor
  143. pm2 start uploader
  144. pm2 start ondemand/ondemand/service.py \
  145. --interpreter=python \
  146. --name=ondemand
  147. cd "$datapath"
  148. pm2 start http-server
  149. cd "$programspath"
  150. pm2 save
  151. pm2 startup
  152. sudo env PATH=$PATH:/usr/bin \
  153. /usr/lib/node_modules/pm2/bin/pm2 \
  154. startup systemd -u fourier \
  155. --hp ~/
  156. fi
  157. if [ ! -f "/etc/systemd/system/ssh-tunnel.service" ]; then
  158. 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
  159. sudo mv $installerpath/ssh-tunnel.service \
  160. /etc/systemd/system/ssh-tunnel.service
  161. sudo systemctl enable ssh-tunnel
  162. sudo systemctl start ssh-tunnel
  163. fi
  164. if [[ "$OSTYPE" != darwin* ]]; then
  165. sudo mysql -u root -e "create database $mysql_db;"
  166. sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';"
  167. sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;"
  168. cd ~
  169. sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql
  170. sudo cp $installerpath/fourier-key.json /etc/Fourier-key.json
  171. fi