fourier_install.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 alsa-utils
  66. sudo apt-get install -y libudev-dev
  67. sudo apt-get install -y tmux
  68. sudo apt-get install -y vim
  69. sudo apt-get install -y autossh
  70. sudo apt-get install -y git-core
  71. sudo apt-get install -y build-essential
  72. sudo apt-get install -y nodejs
  73. sudo apt-get install -y python-dev
  74. sudo apt-get install -y lame
  75. sudo apt-get install -y ezstream
  76. sudo apt-get install -y cmake
  77. sudo apt-get install -y rtl-sdr
  78. sudo apt-get install sqlite3
  79. wget https://bootstrap.pypa.io/get-pip.py
  80. sudo python get-pip.py
  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. if [[ "$OSTYPE" != darwin* ]]; then
  157. sudo mysql -u root -e "create database $mysql_db;"
  158. sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';"
  159. sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;"
  160. cd ~
  161. sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql
  162. sudo cp $installerpath/fourier-key.json /etc/Fourier-key.json
  163. fi
  164. echo "****************************************************************************"
  165. echo "REMEMBER: Initialize attached storage and create a symlink named $datapath pointing to the storage volume"
  166. echo "****************************************************************************"