fourier_install.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. clonerepo() {
  20. GIT_SSH_COMMAND="ssh -i $installerpath/repokey -o StrictHostKeychecking=no" \
  21. git clone $gitbase/$1 $2
  22. }
  23. [ ! -d "$programspath" ] && mkdir $programspath
  24. read -p "Whats this box port (last 3 numbers with zero for padding)? " PORT
  25. read -p "How many receivers has this box? " RECEIVERS_COUNT
  26. read -p "Box ID: " BOX_ID
  27. read -p "API secret: " API_SECRET
  28. sudo apt-get install -y python python-pip python-setuptools
  29. findmnt "$mount_point"
  30. if [ "$?" -neq 0 ]; then
  31. echo -e 'Data drive is not mounted'
  32. fi
  33. keyspath=~/.ssh
  34. keyfile="$keyspath/id_rsa"
  35. [ ! -d "$keyspath" ] && mkdir $keyspath
  36. ssh-keygen -t rsa -b 2048 -C "$HOSTNAME" -P "" -f $keyfile
  37. keycontent=$(cat $keyfile.pub)
  38. curl -X POST -F "key=$keycontent" \
  39. -H "Authorization: $BOX_ID $API_SECRET" \
  40. https://api.audiovalid.com/public-key
  41. # Give permissions to tune DVB devices
  42. # So it can use the devices in /dev/dvb/adapter*
  43. sudo usermod -a -G video fourier
  44. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  45. sudo apt-get install -y alsa-utils alsa-tools
  46. sudo apt-get install -y libudev-dev
  47. sudo apt-get install -y tmux
  48. sudo apt-get install -y vim
  49. sudo apt-get install -y autossh
  50. sudo apt-get install -y git-core
  51. sudo apt-get install -y build-essential
  52. sudo apt-get install -y nodejs
  53. sudo apt-get install -y python-dev
  54. sudo apt-get install -y lame
  55. sudo apt-get install -y ezstream
  56. sudo apt-get install -y cmake
  57. # Install to fix usb permission
  58. sudo apt-get install -y rtl-sdr
  59. sudo apt-get install -y libusb-1.0-0-dev
  60. sudo apt-get install -y sqlite3
  61. sudo apt-get install -y portaudio19-dev
  62. sudo apt-get install -y dvb-apps
  63. sudo pip install pyaudio pyusb pydub numpy requests \
  64. scipy python-firebase tornado mutagen \
  65. pyopenssl google-auth
  66. sudo apt-get install -y ffmpeg
  67. sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
  68. sudo apt-get install -y python-matplotlib
  69. sudo apt-get install -y curl
  70. sudo apt-get install -y libshout3 libshout3-dev
  71. sudo npm install -g http-server
  72. sudo npm install -g pm2
  73. cd tools
  74. sudo python ./setup.py install
  75. cd ..
  76. sudo chown -R 1000:1000 ~/.npm
  77. sudo chmod 0600 $installerpath/repokey
  78. cd $installerpath
  79. sudo mv fourier-key.json /etc/Fourier-key.json
  80. cd $programspath
  81. clonerepo fourier-module.git module
  82. clonerepo fourier-common.git common
  83. clonerepo fourier-recorder.git recorder
  84. clonerepo fourier-fourier.git fourier
  85. clonerepo fourier-alt.git fourier-alt
  86. clonerepo fourier-monitor.git monitor
  87. clonerepo fourier-uploader.git uploader
  88. clonerepo fourier-ondemand.git ondemand
  89. clonerepo rtl-sdr.git rtl-sdr
  90. cd $programspath/recorder
  91. npm install
  92. cd $programspath/monitor
  93. npm install
  94. cd $programspath/uploader
  95. npm install
  96. cd $programspath/module
  97. sudo python setup.py install
  98. cd $programspath/ondemand
  99. sudo python setup.py install
  100. # Build sdr library
  101. cd $programspath/rtl-sdr
  102. mkdir build
  103. cd build
  104. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  105. make
  106. sudo cp ./src/rtl_fm /usr/bin/rtl_fm
  107. #sudo make install
  108. echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules
  109. [ ! -f "$configfile" ] && \
  110. sudo python $installerpath/configure.py \
  111. $installerpath/fourier-config.json \
  112. $configfile \
  113. -programs "$programspath" \
  114. -receivers $RECEIVERS_COUNT \
  115. -api-secret $API_SECRET \
  116. -box-id "$BOX_ID"
  117. echo "** Downloading TV channels."
  118. fourier tv update
  119. if [ "$?" -eq 0 ]; then
  120. cd "$programspath"
  121. pm2 start recorder
  122. pm2 start monitor
  123. pm2 start uploader
  124. pm2 start ondemand/ondemand/service.py \
  125. --interpreter=python \
  126. --name=ondemand
  127. cd "$datapath"
  128. pm2 start http-server
  129. cd "$programspath"
  130. pm2 save
  131. pm2 startup
  132. sudo env PATH=$PATH:/usr/bin \
  133. /usr/lib/node_modules/pm2/bin/pm2 \
  134. startup systemd -u fourier \
  135. --hp ~/
  136. fi
  137. if [ ! -f "/etc/systemd/system/ssh-tunnel.service" ]; then
  138. 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
  139. sudo mv $installerpath/ssh-tunnel.service \
  140. /etc/systemd/system/ssh-tunnel.service
  141. sudo systemctl enable ssh-tunnel
  142. sudo systemctl start ssh-tunnel
  143. fi