fourier_install.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. echo "Fourier installer $installer_version"
  17. echo "------------------------------------"
  18. sudo apt-get install python pip
  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 (from API): " BOX_ID
  30. read -p "API secret: " API_SECRET
  31. findmnt /media/datadrive
  32. if [ "$?" -neq 0 ]; then
  33. echo -e '\e[34mData drive is not mounted\e[0m'
  34. fi
  35. if [[ "$OSTYPE" == darwin* ]]; then
  36. keyfile="$programspath/fourier.key"
  37. [ ! -f "$keyfile" ] && ssh-keygen -t rsa -b 2048 -f $keyfile
  38. else
  39. keyspath=~/.ssh
  40. keyfile="$keyspath/id_rsa"
  41. [ ! -d "$keyspath" ] && mkdir $keyspath
  42. ssh-keygen -t rsa -b 2048 -C "$HOSTNAME" -f $keyfile
  43. fi
  44. echo -e "\e[33mPlease add the following public key to server's authorized keys:\e[0m"
  45. cat $keyfile.pub
  46. read -p "Press enter to continue"
  47. if [[ "$OSTYPE" != darwin* ]]; then
  48. 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
  49. sudo mv $installerpath/ssh-tunnel.service /etc/systemd/system/ssh-tunnel.service
  50. sudo systemctl enable ssh-tunnel
  51. sudo systemctl start ssh-tunnel
  52. fi
  53. if [[ "$OSTYPE" == darwin* ]]; then
  54. depend=( python gcc vim tmux autossh lame nodejs \
  55. ezstream libusb rtl-sdr nim portaudio )
  56. for dep in "${depend[@]}"
  57. do
  58. brew list $dep > /dev/null
  59. [ "$?" -eq 1 ] && brew install $dep
  60. done
  61. envpath="$programspath/env"
  62. [ ! -d "$envpath" ] && virtualenv $programspath/env
  63. source $envpath/bin/activate
  64. pip install -r $installerpath/requirements.txt
  65. else
  66. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  67. sudo apt-get install -y alsa-utils
  68. sudo apt-get install -y libudev-dev
  69. sudo apt-get install -y tmux
  70. sudo apt-get install -y vim
  71. sudo apt-get install -y autossh
  72. sudo apt-get install -y git-core
  73. sudo apt-get install -y build-essential
  74. sudo apt-get install -y nodejs
  75. sudo apt-get install -y python-dev
  76. sudo apt-get install -y lame
  77. sudo apt-get install -y ezstream
  78. sudo apt-get install -y cmake
  79. sudo apt-get install -y rtl-sdr
  80. sudo apt-get install sqlite3
  81. sudo apt-get install -y portaudio19-dev
  82. sudo pip install pyaudio
  83. sudo apt-get install -y ffmpeg
  84. sudo pip install pydub
  85. sudo pip install numpy
  86. sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
  87. sudo pip install scipy
  88. sudo apt-get install -y python-matplotlib
  89. sudo apt-get install -y curl
  90. sudo pip install requests
  91. sudo pip install python-firebase
  92. cd tools
  93. sudo python ./setup.py install
  94. cd ..
  95. fi
  96. sudo chmod 0600 $installerpath/repokey
  97. cd $programspath
  98. clonerepo fourier-module.git module
  99. clonerepo fourier-common.git common
  100. clonerepo fourier-server.git server
  101. clonerepo fourier-fourier.git fourier
  102. clonerepo fourier-alt.git fourier-alt
  103. clonerepo fourier-monitor.git monitor
  104. clonerepo fourier-uploader.git uploader
  105. clonerepo fourier-ondemand.git ondemand
  106. cd $programspath/server
  107. npm install
  108. cd $programspath/monitor
  109. npm install
  110. cd $programspath/uploader
  111. npm install
  112. cd $programspath/module
  113. sudo python setup.py install
  114. cd $programspath/ondemand
  115. sudo python setup.py install
  116. sudo npm install -g pm2
  117. # build sdr lib
  118. if [[ "$OSTYPE" != darwin* ]]; then
  119. sudo apt-get install -y libusb-1.0-0-dev
  120. cd $programspath
  121. clonerepo rtl-sdr.git rtl-sdr
  122. cd $programspath/rtl-sdr
  123. mkdir build
  124. cd build
  125. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  126. make
  127. sudo cp ./src/rtl_fm /usr/bin/rtl_fm
  128. echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules
  129. #build and install nim
  130. cd $programspath
  131. curl -L https://nim-lang.org/download/nim-0.17.0.tar.xz -o nim-0.17.0.tar.xz
  132. tar xvf nim-0.17.0.tar.xz
  133. cd nim-0.17.0
  134. sh build.sh
  135. bin/nim c koch
  136. ./koch tools
  137. echo "export PATH=$programspath/nim-0.17.0/bin:$PATH" >> ~/.bashrc
  138. fi
  139. cd $programspath/fourier-alt
  140. nimble build
  141. # --------------------------------- #
  142. # Generación de los scripts con pm2 #
  143. # --------------------------------- #
  144. # cd $programspath
  145. # pm2 start fourier-ondemand --interpreter python --name ondemand
  146. # pm2 start server
  147. # pm2 start monitor
  148. # pm2 start uploader
  149. [ ! -f "$configfile" ] && \
  150. sudo python $installerpath/configure.py \
  151. $installerpath/fourier-config.json \
  152. $configfile \
  153. -programs "$programspath" \
  154. -receivers $RECEIVERS_COUNT \
  155. -api-secret $API_SECRET \
  156. -box-id "$BOX_ID"
  157. if [[ "$OSTYPE" != darwin* ]]; then
  158. sudo mysql -u root -e "create database $mysql_db;"
  159. sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';"
  160. sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;"
  161. cd ~
  162. sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql
  163. sudo cp $installerpath/fourier-key.json /etc/Fourier-key.json
  164. fi
  165. echo "****************************************************************************"
  166. echo "REMEMBER: Initialize attached storage and create a symlink named $datapath pointing to the storage volume"
  167. echo "****************************************************************************"