fourier_install.sh 5.6 KB

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