#!/bin/bash
#
# Instalator narzedzi do DAB:
#
# * ODR-DabMux
# * ODR-DabMod
# * toolame
# * fdk-aac-dabplus
# * SDR-TX
# * skrypty pomocnicze
#
# oraz wiele innych bezsensownych zaleznosci ;)
# na Debianie Buster 10 64bit
#
nano_v="nano-5.4"
mbuff="mbuffer-20200929"
zmq="zeromq-4.3.3"
mod_ver="dabmod-v13"
jacek="jack2-1.9.12"

RED='\033[0;31m'
GREEN="\e[92m"
NORMAL="\e[0m"
sleep 1
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
apt update
#sleep 1
#apt upgrade
echo -e "$GREEN No to instalujemy DAB :) $NORMAL"
sleep 2
apt purge nano acpid
apt autoremove
apt --no-install-recommends build-dep nano wavemon htop libstrophe mpg321 mbuffer jackd2

apt --no-install-recommends install libboost-all-dev libusb-dev openvpn lame \
git libfftw3-dev sox wpasupplicant lm-sensors mc \
firmware-atheros libsodium-dev yasm cmake strace iw wireless-tools \
libcurl4-openssl-dev aptitude libcurses-ocaml-dev libmp3lame-dev \
curl libunwind-dev net-tools bsdtar linux-cpupower mosquitto-clients \
gnupg1 apt-transport-https dirmngr lsb-release python-dbus \
firmware-linux-nonfree firmware-realtek psmisc haveged intel-microcode

wget 2pi.eu:411/soft/lsd_0.18.0_amd64.deb
wget 2pi.eu:411/soft/jackd2_1.9.12~dfsg-2_amd64.deb
wget 2pi.eu:411/soft/libjack-jackd2-0_1.9.12~dfsg-2_amd64.deb
wget 2pi.eu:411/soft/libjack-jackd2-dev_1.9.12~dfsg-2_amd64.deb
sleep 2
dpkg -i lsd_0.18.0_amd64.deb
dpkg -i libjack-jackd2-0_1.9.12~dfsg-2_amd64.deb
dpkg -i jackd2_1.9.12~dfsg-2_amd64.deb
dpkg -i libjack-jackd2-dev_1.9.12~dfsg-2_amd64.deb

echo
echo -e "$GREEN Instalowanie nano $NORMAL"
echo
sleep 2
wget 2pi.eu:411/soft/$nano_v.tar.gz
tar -xf $nano_v.tar.gz
pushd $nano_v
./configure --prefix=/usr --exec-prefix= --sysconfdir=/etc
make $1
make install
cp doc/sample.nanorc /etc/nanorc
popd

exit
#echo
#echo -e "$GREEN Instalowanie Jack $NORMAL"
#echo
#sleep 2
#wget 2pi.eu:411/soft/$jacek.tar.gz
#tar -xf $jacek.tar.gz
#pushd $jacek
#./waf configure --prefix=/usr --autostart=none
#./waf build
#./waf install
#popd

echo
echo -e "$GREEN Instalowanie jack-stdio $NORMAL"
echo
sleep 2
git clone https://github.com/x42/jack-stdio.git
pushd jack-stdio
make install PREFIX=/usr
popd

echo
echo -e "$GREEN Instalowanie silentjack $NORMAL"
echo
sleep 2
git clone https://github.com/njh/silentjack.git
pushd silentjack
./autogen.sh
./configure --prefix=/usr
make $1
make install
popd

#echo
#echo -e "$GREEN Instalowanie ezstream $NORMAL"
#echo
#sleep 2
#wget http://2pi.eu:411/soft/ezstream-1.0.1.tar.gz
#tar -xf ezstream-1.0.1.tar.gz
#pushd ezstream-1.0.1
#./configure --prefix=/usr
#make $1
#make install
#popd

echo
echo -e "$GREEN Instalowanie ZMQ $NORMAL"
echo
sleep 2
wget http://2pi.eu:411/soft/$zmq.tar.gz
tar -xf $zmq.tar.gz
pushd $zmq
./configure --prefix=/usr
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie KA9Q libfec $NORMAL"
echo
sleep 2
git clone https://github.com/Opendigitalradio/ka9q-fec.git
pushd ka9q-fec
./bootstrap
./configure --prefix=/usr
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie ODR-DabMux $NORMAL"
echo
sleep 2
git clone -b next https://github.com/Opendigitalradio/ODR-DabMux.git
pushd ODR-DabMux
./bootstrap.sh
./configure --prefix=/usr --enable-output-raw
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie ODR-DabMod $NORMAL"
echo
sleep 2
wget 2pi.eu:411/soft/$mod_ver.tar.gz
tar -xf $mod_ver.tar.gz
pushd $mod_ver
./bootstrap.sh
./configure --prefix=/usr --disable-output-uhd
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie ODR-AudioEnc $NORMAL"
echo
sleep 2
git clone -b next https://github.com/Opendigitalradio/ODR-AudioEnc.git
pushd ODR-AudioEnc
./bootstrap
./configure --prefix=/usr --enable-jack --enable-alsa
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie ODR-PadEnc $NORMAL"
echo
sleep 2
git clone -b next https://github.com/Opendigitalradio/ODR-PadEnc.git
pushd ODR-PadEnc
./bootstrap
./configure --prefix=/usr
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie libstrophe $NORMAL"
echo
sleep 2
git clone https://github.com/strophe/libstrophe.git
pushd libstrophe
./bootstrap.sh
./configure
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie wavemon $NORMAL"
echo
sleep 2
git clone https://github.com/uoaerg/wavemon.git
pushd wavemon
./configure --prefix=/usr
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie mbuffer $NORMAL"
echo
sleep 2
wget 2pi.eu:411/soft/$mbuff.tgz
tar -xf $mbuff.tgz
pushd $mbuff
./configure --prefix=/usr
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie htop $NORMAL"
echo
sleep 2
git clone https://github.com/hishamhm/htop.git
pushd htop
./autogen.sh
./configure --prefix=/usr
make $1
make install
popd

echo
echo -e "$GREEN Instalowanie mpg321 $NORMAL"
echo
sleep 2
wget 2pi.eu:411/soft/mpg321.tar.gz
tar -xf mpg321.tar.gz
pushd mpg321
./configure --prefix=/usr --disable-mpg123-symlink
make $1
make install
popd

mkdir -p /usr/share/sdrtx/firmware

echo
echo -e "$GREEN Instalowanie SDR-TX $NORMAL"
echo
sleep 2
wget 2pi.eu:411/soft/sdrtx2-lib.tar.gz
tar -xf sdrtx2-lib.tar.gz
pushd sdrtx2-lib
./configure --prefix=/usr
make $1
make install
install txS_1024.ihx /usr/share/sdrtx/firmware/txS_1024.ihx
install host/apps/.libs/test_sdrtx_standard_tx /usr/bin/sdrtx
popd
echo "blacklist usbtest" > /etc/modprobe.d/usbtest.conf
echo -e "\c" > /etc/motd

echo
echo -e "$GREEN fdk-aac $NORMAL"
echo
sleep 2
git clone https://github.com/mstorsjo/fdk-aac.git
pushd fdk-aac
./autogen.sh
./configure --prefix=/usr --disable-static
make $1
make install
popd

echo
echo -e "$GREEN FFmpeg $NORMAL"
echo
sleep 2
wget 2pi.eu:411/soft/ffmpeg-4.3.1.tar.bz2
tar -xf ffmpeg-4.3.1.tar.bz2
pushd ffmpeg-4.3.1
./configure --prefix=/usr --disable-debug --disable-static --disable-stripping \
--enable-libmp3lame --enable-libfdk-aac --enable-shared --enable-libjack
make $1
make install
popd

echo
echo -e "$GREEN MPlayer $NORMAL"
echo
czas=$(date "+%Y-%m-%d")
sleep 2
wget http://www.mplayerhq.hu/MPlayer/releases/mplayer-checkout-snapshot.tar.bz2
tar -xf mplayer-checkout-snapshot.tar.bz2
pushd mplayer-checkout-2*
./configure --prefix=/usr --disable-mpg123 --disable-lirc \
--disable-lircc --disable-ffmpeg_a --disable-gui --confdir=/etc/mplayer
make $1
make install
popd

#echo -e "\c" > /etc/motd
#echo "blacklist usbtest" > /etc/modprobe.d/usbtest.conf

hash -r
ldconfig
echo
echo -e "$GREEN Koniec $NORMAL"
echo

