#!/bin/bash
#
# Instalator narzedzi do DAB:
#
# * ODR-DabMux
# * ODR-DabMod
# * toolame
# * fdk-aac-dabplus
# * SDR-TX
# * skrypty pomocnicze
#
# oraz wiele inny bezsensownych zaleznosci ;)
# na Arch 64bit
#
#nano_v="nano-4.9.3"
mbuff="mbuffer-20230301"
#zmq="zeromq-4.3.2"
mod_ver="dabmod-v15"
#jacek="jack2-1.9.12"

RED='\033[0;31m'
GREEN="\e[92m"
NORMAL="\e[0m"

echo -e "$GREEN No to instalujemy DAB :) $NORMAL"
sleep 2

sudo pacman -Syyu
sudo pacman -S libao libid3tag libmad openssh mc gcc make pkg-config cmake boost wget \
lame lsd check taglib git automake autoconf zeromq fftw htop \
wavemon wpa_supplicant crda fdkaac yasm strace net-tools openvpn opus jack2

#echo
#echo -e "$GREEN Instalowanie Jack $NORMAL"
#echo
#sleep 2
#wget http://2pi.eu:411/soft/$jacek.tar.gz
#tar -xf $jacek.tar.gz
#pushd $jacek
#touch __init__.py
#mkdir -vp tools
#cp -v waflib/extras/xcode*.py tools
#rm -rv waflib
#sed -e "s/load('xcode'/load('xcode', tooldir='tools'/g" \
#-e "s/load('xcode6'/load('xcode6', tooldir='tools'/g" \
#-i wscript
#export PYTHONPATH="${PWD}:${PYTHONPATH}"
#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
sudo 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
sudo 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 KA9Q libfec $NORMAL"
echo
sleep 2
git clone https://github.com/Opendigitalradio/ka9q-fec.git
pushd ka9q-fec
./bootstrap
./configure --prefix=/usr
make $1
sudo make install
popd

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

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

echo
echo -e "$GREEN Instalowanie ODR-AudioEnc $NORMAL"
echo
sleep 2
git clone https://github.com/Opendigitalradio/ODR-AudioEnc.git
pushd ODR-AudioEnc
./bootstrap
./configure --prefix=/usr --enable-jack --enable-alsa
make $1
sudo 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
sudo 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
sudo make install
popd

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

#echo
#echo -e "$GREEN Instalowanie mpg321 $NORMAL"
#echo
#sleep 2
#wget http://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

sleep 2
wget http://2pi.eu:411/soft/libusb-debian.tar.gz
tar -xf libusb-debian.tar.gz
pushd libusb-debian
./configure --prefix=/usr --disable-static
make $1
sudo make install
popd

sudo mkdir -p /usr/share/sdrtx/firmware

echo
echo -e "$GREEN Instalowanie SDR-TX $NORMAL"
echo
sleep 2
wget http://2pi.eu:411/soft/sdrtx2-lib.tar.gz
tar -xf sdrtx2-lib.tar.gz
pushd sdrtx2-lib
./configure --prefix=/usr
make $1
sudo make install
sudo install txS_1024.ihx /usr/share/sdrtx/firmware/txS_1024.ihx
sudo install host/apps/.libs/test_sdrtx_standard_tx /usr/bin/sdrtx
popd

#echo
#echo -e "$GREEN FFmpeg $NORMAL"
#echo
#sleep 2
#wget https://ffmpeg.org/releases/ffmpeg-4.2.2.tar.bz2
#tar -xf ffmpeg-4.2.2.tar.bz2
#pushd ffmpeg-4.2.2
#./configure --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-libjack \
#--enable-shared --enable-libmp3lame --enable-libfdk-aac --enable-version3 --enable-nonfree --enable-libopus
#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-$czas
#export CFLAGS="${CFLAGS/-march=x86-64/}"
#export CFLAGS="${CFLAGS/-mtune=generic/}"
#export LDFLAGS="${LDFLAGS/,O1/}"
#export LDFLAGS="${LDFLAGS/,--sort-common/}"
#./configure --prefix=/usr --disable-mpg123 --disable-lirc --disable-lircc \
#--disable-gui --disable-ffmpeg_a --confdir=/etc/mplayer
#make $1
#make install
#popd

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

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

