# version 1.0.2 # install essential software # sudo apt-get update installer_version=1.0.3 programspath=~/programs installerpath=$(pwd) configfile='/etc/fourier-config.json' gitbase="gogs@git.miralo.xyz:AudioValid" tunnel_user=rtunnel datapath='/var/fourier' serverhost='monitor.audiovalid.com' tunnelfile="$programspath/ssh-tunnel.sh" mysql_user=fourier mysql_passwd='Sup3rDuper!' mysql_db=fourier mount_point=/media/datadrive echo "Fourier installer $installer_version" echo "------------------------------------" if [[ "$OSTYPE" == darwin* ]]; then programspath=~/fourier fi clonerepo() { GIT_SSH_COMMAND="ssh -i $installerpath/repokey -o StrictHostKeychecking=no" \ git clone $gitbase/$1 $2 } [ ! -d "$programspath" ] && mkdir $programspath read -p "Whats this box port (last 3 numbers with zero for padding)? " PORT read -p "How many receivers has this box? " RECEIVERS_COUNT read -p "Box ID (or rolame url id): " BOX_ID curl -f -H "Accept: text/plain" "https://rola.me/$BOX_ID" \ 1>/tmp/fourier-api \ 2>/dev/null if [ "$?" -eq 0 ]; then IFS=':' read -ra APIDATA <<< "$(cat /tmp/fourier-api)" BOX_ID="${APIDATA[0]}" API_SECRET="${APIDATA[1]}" rm /tmp/fourier-api else read -p "API secret: " API_SECRET fi sudo apt-get install -y python python-pip python-setuptools findmnt "$mount_point" if [ "$?" -neq 0 ]; then echo -e 'Data drive is not mounted' fi if [[ "$OSTYPE" == darwin* ]]; then keyfile="$programspath/fourier.key" [ ! -f "$keyfile" ] && ssh-keygen -t rsa -b 2048 -f $keyfile else keyspath=~/.ssh keyfile="$keyspath/id_rsa" [ ! -d "$keyspath" ] && mkdir $keyspath ssh-keygen -t rsa -b 2048 -C "$HOSTNAME" -P "" -f $keyfile fi keycontent=$(cat $keyfile.pub) curl -X POST -F "key=$keycontent" \ -H "Authorization: $BOX_ID $API_SECRET" \ https://api.audiovalid.com/public-key if [[ "$OSTYPE" == darwin* ]]; then depend=( python gcc vim tmux autossh lame nodejs \ ezstream libusb rtl-sdr portaudio ) for dep in "${depend[@]}" do brew list $dep > /dev/null [ "$?" -eq 1 ] && brew install $dep done envpath="$programspath/env" [ ! -d "$envpath" ] && virtualenv $programspath/env source $envpath/bin/activate pip install -r $installerpath/requirements.txt else curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y alsa-utils alsa-tools sudo apt-get install -y libudev-dev sudo apt-get install -y tmux sudo apt-get install -y vim sudo apt-get install -y autossh sudo apt-get install -y git-core sudo apt-get install -y build-essential sudo apt-get install -y nodejs sudo apt-get install -y python-dev sudo apt-get install -y lame sudo apt-get install -y ezstream sudo apt-get install -y cmake sudo apt-get install -y rtl-sdr sudo apt-get install -y sqlite3 sudo apt-get install -y portaudio19-dev sudo apt install dvb-apps sudo pip install pyaudio pyusb pydub numpy requests \ scipy python-firebase sudo apt-get install -y ffmpeg sudo apt-get install -y gfortran libopenblas-dev liblapack-dev sudo apt-get install -y python-matplotlib sudo apt-get install -y curl sudo pip install sudo npm install -g http-server cd tools sudo python ./setup.py install cd .. fi sudo chmod 0600 $installerpath/repokey cd $programspath clonerepo fourier-module.git module clonerepo fourier-common.git common clonerepo fourier-server.git server clonerepo fourier-fourier.git fourier clonerepo fourier-alt.git fourier-alt clonerepo fourier-monitor.git monitor clonerepo fourier-uploader.git uploader clonerepo fourier-ondemand.git ondemand cd $programspath/server npm install cd $programspath/monitor npm install cd $programspath/uploader npm install cd $programspath/module sudo python setup.py install cd $programspath/ondemand sudo python setup.py install sudo npm install -g pm2 # build sdr lib if [[ "$OSTYPE" != darwin* ]]; then sudo apt-get install -y libusb-1.0-0-dev cd $programspath clonerepo rtl-sdr.git rtl-sdr cd $programspath/rtl-sdr mkdir build cd build cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON make sudo cp ./src/rtl_fm /usr/bin/rtl_fm echo "SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"" | sudo tee -a /etc/udev/rules.d/rtl-sdr.rules fi [ ! -f "$configfile" ] && \ sudo python $installerpath/configure.py \ $installerpath/fourier-config.json \ $configfile \ -programs "$programspath" \ -receivers $RECEIVERS_COUNT \ -api-secret $API_SECRET \ -box-id "$BOX_ID" if [ "$?" -eq 0 ]; then cd "$programspath" pm2 start server pm2 start monitor pm2 start uploader pm2 start ondemand/ondemand/service.py \ --interpreter=python \ --name=ondemand pm2 start http-server pm2 save pm2 startup sudo env PATH=$PATH:/usr/bin \ /usr/lib/node_modules/pm2/bin/pm2 \ startup systemd -u fourier \ --hp ~/ fi if [ ! -f "/etc/systemd/system/ssh-tunnel.service" ]; then 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 sudo mv $installerpath/ssh-tunnel.service \ /etc/systemd/system/ssh-tunnel.service sudo systemctl enable ssh-tunnel sudo systemctl start ssh-tunnel fi if [[ "$OSTYPE" != darwin* ]]; then sudo mysql -u root -e "create database $mysql_db;" sudo mysql -u root -e "create user '$mysql_user'@'localhost' identified by '$mysql_passwd';" sudo mysql -u root -e "grant all privileges on $mysql_db.* to '$mysql_user'@'localhost';flush privileges;" cd ~ sudo mysql -u root -h localhost $mysql_db < $installerpath/fourier.sql sudo cp $installerpath/fourier-key.json /etc/Fourier-key.json fi