#!/bin/bash

SRCDIR="/var/local/src"

SEPARATOR="##############################################################################"



echo
echo
echo $SEPARATOR
echo "# Getting base packages"
echo

sudo apt-get update

sudo apt-get install cmake build-essential python-pip libusb-1.0-0-dev python-numpy git git-core pandoc



echo
echo
echo $SEPARATOR
echo "# Building RTL-SDR"
echo

read -p "Install base RTL-SDR?  " install_rtlsdr

if [[ "$install_rtlsdr" == "y" ]]; then

   cd $SRCDIR
   
   git clone git://git.osmocom.org/rtl-sdr.git
   
   cd rtl-sdr
   
   mkdir build
   
   cd build
   
   cmake ../ -DINSTALL_UDEV_RULES=ON   # Pi
   #cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON
   
      # Note that faster execution can be had on more recent Raspberry Pi 
      # models (B+, 3) by using four processors. The command becomes:
      # make -j5
   make
   
   sudo make install
   
   sudo ldconfig
      # if it was successful you should see no return on the previous command.
   
   sudo cp ../rtl-sdr.rules /etc/udev/rules.d/01-rtl-sdr.rules   # Pi
   #sudo cp ../rtl-sdr.rules /etc/udev/rules.d/
   
   #  blacklist and unload kernel modules
   cat > /etc/modprobe.d/no-dvb.conf << EOF
blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2830
EOF

   # maybe for Pi
   ## rmmod dvb_usb_rtl28xxu 
   ## rmmod rtl2830
   ## rmmod rtl2832

else 

   echo "...skipping\n"

fi





echo
echo $SEPARATOR
echo "# Installing libacars"
echo

cd $SRCDIR

git clone https://github.com/szpajder/libacars.git
sudo apt-get install zlib1g-dev libxml2-dev
cd libacars/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig





echo
echo $SEPARATOR
echo "# Installing acarsdec"
echo

cd $SRCDIR

git clone https://github.com/TLeconte/acarsdec.git
cd acarsdec/
mkdir build
cd build/
cmake .. -Drtl=ON
make
sudo make install





