#!/bin/bash

if [ "$EUID" -ne 0 ]
  then echo "Please run as root!"
  exit
fi

echo 'Prepare system'

if [ -n "`which apt-get`" ]; then
  apt-get -y install \
    mercurial \
    build-essential \
    patchutils \
    libproc-processtable-perl \
    linux-headers-$(uname -r) \
    git

  systemctl disable apt-daily.service
  systemctl disable apt-daily.timer
fi

cd /tmp
wget https://github.com/DigitalDevices/dddvb/archive/0.9.41.tar.gz
tar xvzf /tmp/0.9.41.tar.gz
cd /tmp/dddvb-0.9.41

sed -i -e 's/^#if defined(CONFIG_DVB_MAX_ADAPTERS).*$/#if 0/g' include/linux/media/dvbdev.h
sed -i -e 's/DVB_MAX_ADAPTERS 64/DVB_MAX_ADAPTERS 256/g' include/linux/media/dvbdev.h
#sed -i -e 's/^\(#define MAX_DVB_MINORS*\).*/\1 512/g' dvb-core/dvbdev.c

make -j 5
make install

mkdir -p /etc/depmod.d
echo 'search extra updates built-in' >/etc/depmod.d/extra.conf
depmod -a

modprobe ddbridge
modinfo ddbridge | grep 'version:'

echo 'Done! Please reboot the server'
