fourier_install.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # version 1.0.2
  2. # install essential software
  3. # sudo apt-get update
  4. installer_version=1.0.2
  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 tmux
  66. sudo apt-get install -y vim
  67. sudo apt-get install -y autossh
  68. sudo apt-get install -y git-core
  69. sudo apt-get install -y build-essential
  70. sudo apt-get install -y nodejs
  71. sudo apt-get install -y python-dev
  72. sudo apt-get install -y lame
  73. sudo apt-get install -y ezstream
  74. sudo apt-get install -y cmake
  75. sudo apt-get install -y rtl-sdr
  76. sudo apt-get install sqlite3
  77. wget https://bootstrap.pypa.io/get-pip.py
  78. sudo python get-pip.py
  79. sudo apt-get install -y portaudio19-dev
  80. sudo pip install pyaudio
  81. sudo apt-get install -y ffmpeg
  82. sudo pip install pydub
  83. sudo pip install numpy
  84. sudo apt-get install -y gfortran libopenblas-dev liblapack-dev
  85. sudo pip install scipy
  86. sudo apt-get install -y python-matplotlib
  87. sudo apt-get install -y curl
  88. sudo pip install requests
  89. sudo pip install python-firebase
  90. cd tools
  91. sudo python ./setup.py install
  92. cd ..
  93. fi
  94. cd $programspath
  95. clonerepo fourier-common.git common
  96. clonerepo fourier-server.git server
  97. clonerepo fourier-fourier.git fourier
  98. clonerepo fourier-alt.git fourier-alt
  99. clonerepo fourier-monitor.git monitor
  100. clonerepo fourier-uploader.git uploader
  101. clonerepo fourier-ondemand.git ondemand
  102. cd $programspath/server
  103. npm install
  104. cd $programspath/monitor
  105. npm install
  106. cd $programspath/uploader
  107. npm install
  108. cd $programspath/ondemand
  109. npm install
  110. sudo npm install -g pm2
  111. # build sdr lib
  112. if [[ "$OSTYPE" != darwin* ]]; then
  113. sudo apt-get install -y libusb-1.0-0-dev
  114. cd $programspath
  115. clonerepo rtl-sdr.git rtl-sdr
  116. cd $programspath/rtl-sdr
  117. mkdir build
  118. cd build
  119. cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
  120. make
  121. sudo cp ./src/rtl_fm /usr/bin/rtl_fm
  122. echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules
  123. #build and install nim
  124. cd $programspath
  125. curl -L https://nim-lang.org/download/nim-0.17.0.tar.xz -o nim-0.17.0.tar.xz
  126. tar xvf nim-0.17.0.tar.xz
  127. cd nim-0.17.0
  128. sh build.sh
  129. bin/nim c koch
  130. ./koch tools
  131. echo "export PATH=$programspath/nim-0.17.0/bin:$PATH" >> ~/.bashrc
  132. fi
  133. cd $programspath/fourier-alt
  134. nimble build
  135. [ ! -f "$configfile" ] && \
  136. sudo python $installerpath/configure.py \
  137. $installerpath/fourier-config.json \
  138. $configfile \
  139. -programs "$programspath" \
  140. -receivers $RECEIVERS_COUNT
  141. -api-secret $API_SECRET
  142. if [[ "$OSTYPE" != darwin* ]]; then
  143. sudo mysql -u root -e "create database $mysql_db;"
  144. sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';"
  145. sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;"
  146. cd ~
  147. sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql
  148. sudo mv $installerpath/fourier-key.json /etc/Fourier-key.json
  149. fi
  150. echo "****************************************************************************"
  151. echo "REMEMBER: Initialize attached storage and create a symlink named $datapath pointing to the storage volume"
  152. echo "****************************************************************************"