fourier_install.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. sudo apt-get install -y python python-pip
  20. if [[ "$OSTYPE" == darwin* ]]; then
  21. programspath=~/fourier
  22. fi
  23. clonerepo() {
  24. GIT_SSH_COMMAND="ssh -i $installerpath/repokey -o StrictHostKeychecking=no" \
  25. git clone $gitbase/$1 $2
  26. }
  27. [ ! -d "$programspath" ] && mkdir $programspath
  28. read -p "Whats this box port (last 3 numbers with zero for padding)? " PORT
  29. read -p "How many receivers has this box? " RECEIVERS_COUNT
  30. read -p "Box ID (from API): " BOX_ID
  31. read -p "API secret: " API_SECRET
  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" -f $keyfile
  44. fi
  45. echo -e "\e[33mPlease add the following public key to server's authorized keys:\e[0m"
  46. cat $keyfile.pub
  47. read -p "Press enter to continue"
  48. if [[ "$OSTYPE" != darwin* ]]; then
  49. 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
  50. sudo mv $installerpath/ssh-tunnel.service /etc/systemd/system/ssh-tunnel.service
  51. sudo systemctl enable ssh-tunnel
  52. sudo systemctl start ssh-tunnel
  53. fi
  54. if [[ "$OSTYPE" == darwin* ]]; then
  55. depend=( python gcc vim tmux autossh lame nodejs \
  56. ezstream libusb rtl-sdr portaudio )
  57. for dep in "${depend[@]}"
  58. do
  59. brew list $dep > /dev/null
  60. [ "$?" -eq 1 ] && brew install $dep
  61. done
  62. envpath="$programspath/env"
  63. [ ! -d "$envpath" ] && virtualenv $programspath/env
  64. source $envpath/bin/activate
  65. pip install -r $installerpath/requirements.txt
  66. else
  67. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  68. sudo apt-get install -y alsa-utils alsa-tools
  69. sudo apt-get install -y libudev-dev
  70. sudo apt-get install -y tmux
  71. sudo apt-get install -y vim
  72. sudo apt-get install -y autossh
  73. sudo apt-get install -y git-core
  74. sudo apt-get install -y build-essential
  75. sudo apt-get install -y nodejs
  76. sudo apt-get install -y python-dev
  77. sudo apt-get install -y lame
  78. sudo apt-get install -y ezstream
  79. sudo apt-get install -y cmake
  80. sudo apt-get install -y rtl-sdr
  81. sudo apt-get install -y sqlite3
  82. sudo apt-get install -y portaudio19-dev
  83. sudo pip install pyaudio
  84. sudo apt-get install -y ffmpeg
  85. sudo pip install pydub
  86. sudo pip install numpy
  87. sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
  88. sudo pip install scipy
  89. sudo apt-get install -y python-matplotlib
  90. sudo apt-get install -y curl
  91. sudo pip install requests
  92. sudo pip install python-firebase
  93. cd tools
  94. sudo python ./setup.py install
  95. cd ..
  96. fi
  97. sudo chmod 0600 $installerpath/repokey
  98. cd $programspath
  99. clonerepo fourier-module.git module
  100. clonerepo fourier-common.git common
  101. clonerepo fourier-server.git server
  102. clonerepo fourier-fourier.git fourier
  103. clonerepo fourier-alt.git fourier-alt
  104. clonerepo fourier-monitor.git monitor
  105. clonerepo fourier-uploader.git uploader
  106. clonerepo fourier-ondemand.git ondemand
  107. cd $programspath/server
  108. npm install
  109. cd $programspath/monitor
  110. npm install
  111. cd $programspath/uploader
  112. npm install
  113. cd $programspath/module
  114. sudo python setup.py install
  115. cd $programspath/ondemand
  116. sudo python setup.py install
  117. sudo npm install -g pm2
  118. # build sdr lib
  119. if [[ "$OSTYPE" != darwin* ]]; then
  120. sudo apt-get install -y libusb-1.0-0-dev
  121. cd $programspath
  122. clonerepo rtl-sdr.git rtl-sdr
  123. cd $programspath/rtl-sdr
  124. mkdir build
  125. cd build
  126. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  127. make
  128. sudo cp ./src/rtl_fm /usr/bin/rtl_fm
  129. echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules
  130. fi
  131. # --------------------------------- #
  132. # Generación de los scripts con pm2 #
  133. # --------------------------------- #
  134. # cd $programspath
  135. # pm2 start fourier-ondemand --interpreter python --name ondemand
  136. # pm2 start server
  137. # pm2 start monitor
  138. # pm2 start uploader
  139. [ ! -f "$configfile" ] && \
  140. sudo python $installerpath/configure.py \
  141. $installerpath/fourier-config.json \
  142. $configfile \
  143. -programs "$programspath" \
  144. -receivers $RECEIVERS_COUNT \
  145. -api-secret $API_SECRET \
  146. -box-id "$BOX_ID"
  147. if [[ "$OSTYPE" != darwin* ]]; then
  148. sudo mysql -u root -e "create database $mysql_db;"
  149. sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';"
  150. sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;"
  151. cd ~
  152. sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql
  153. sudo cp $installerpath/fourier-key.json /etc/Fourier-key.json
  154. fi
  155. echo "****************************************************************************"
  156. echo "REMEMBER: Initialize attached storage and create a symlink named $datapath pointing to the storage volume"
  157. echo "****************************************************************************"