#!/bin/bash # Be root to run this if ! echo "$(whoami)" | grep "root" > /dev/null 2>&1; then echo -en " \E[1;33;44m You need root privs to run this Running Ubuntu, 'sudo su' will get you there. Aborting... \E[0m " exit 0 fi confirmyes(){ # call with a prompt string or use a default read -r -p "${1:-Are you sure? [Y/n]} " response case $response in [yY][eE][sS]|[yY]) true ;; [nN][oO]|[nN]) false ;; *) true ;; esac } TBSDriverLoaded() { grep -qse saa716x_tbs_dvb /proc/modules } # Load saa716x_tbs_dvb TBSLoadDriver() { echo -e "" echo -e "Loading TBS driver modules. \n" modprobe saa716x_tbs_dvb sleep 2 } # Unload saa716x_tbs_dvb TBSUnloadDriver() { rmmod saa716x_tbs_dvb } # Show failure message die_unknown(){ echo -en " \E[1;33;44m Unknown option \"$1\". \E[0m " sleep 2 ./tbsinstall --help exit 1 } # Show help message show_help(){ echo " " echo " Usage: ./tbsinstall --opt1= --opt2=" echo " " echo " Options: [default], if any, in brackets after option." echo " " echo " --help Print this message" echo " " echo " --version= [140819] Set version to download." echo " " echo " --adapters= [8] Set max number of adapters" echo " " echo " --dvbc= [no] yes: Set the multistandard adapters to DVB-C." echo " " echo " --ffdecsabuild= [yes] no: Don't build FFdecsawrapper" echo " " echo " --dvbdev= [yes] no: Don't patch dvbdev.c." echo " no also sets --ffdecsabuild to no" echo " " echo " --ffdecsaconf= Use own FFdecsawrapper options" echo " Don't use this option unless you" echo " exactly know what you are doing." echo " " exit 0 } # Set default options version_opt="140819" adapters_opt="8" dvbc_opt="no" ffdecsa_build="yes" dvbdev_opt="yes" ffdecsa_conf="" MAKEOPTS="-j 5" ARCHIVES="/root/archives" # Set options from command line for opt do optval="${opt#*=}" case "$opt" in --version=*) version_opt="$optval" ;; --adapters=*) adapters_opt="$optval" ;; --dvbc=*) dvbc_opt="$optval" ;; --ffdecsabuild=*) ffdecsa_build="$optval" ;; --dvbdev=*) ffdecsa_build="no"; dvbdev_opt="$optval" ;; --ffdecsaconf=*) ffdecsa_conf="$optval" ;; --help) show_help ;; *) die_unknown $opt ;; esac done # Check for incorrect use of options. if test "x$dvbc_opt" = "xno" || test "x$dvbc_opt" = "xyes"; then if ! [ "$?" -eq 0 ]; then echo " Bad option to --dvbc '$dvbc_opt'. Should be 'yes or no'" exit 1 fi fi if test "x$ffdecsa_build" = "xno" || test "x$ffdecsa_build" = "xyes"; then if ! [ "$?" -eq 0 ]; then echo " Bad option to --ffdecsabuild '$ffdecsa_build'. Should be 'yes' or 'no'" exit 1 fi fi if test "x$dvbdev_opt" = "xno" || test "x$dvbdev_opt" = "xyes"; then if ! [ "$?" -eq 0 ]; then echo " Bad option to --dvbdev '$dvbdev_opt'. Should be 'yes' or 'no'" exit 1 fi fi # Check if FFdecsawrapper is running # If it is, offer to stop it if ps -C ffdecsawrapper > /dev/null 2>&1; then echo " It seems that FFdecsawrapper is running. It must be stopped before proceeding. " confirmyes "Do you want to stop FFdecsawrapper now? [Y/n]" if [ "$?" -eq 0 ]; then if test -e /etc/init.d/ffdecsawrapper; then /etc/init.d/ffdecsawrapper stop sleep 3 rmmod dvbloopback > /dev/null 2>&1 else killall -9 ffdecsawrapper sleep 3 rmmod dvbloopback > /dev/null 2>&1 fi else echo " Cannot continue with FFdecsawrapper running. " exit 0 fi fi rm -rf tbs mkdir tbs cd tbs if [ -e $ARCHIVES/tbs-linux-drivers_v$version_opt.zip ]; then cp -a $ARCHIVES/tbs-linux-drivers_v$version_opt.zip . echo "Found existing TBS drivers archive, not downloading new copy" else wget www.tbsdtv.com/download/document/common/tbs-linux-drivers_v$version_opt.zip fi if ! [ "$?" -eq 0 ]; then echo " Failed to download tbs-linux-drivers_v$version_opt.zip Aborting... " exit 1 fi if ![ -e $ARCHIVES/tbs-linux-drivers_v$version_opt.zip ]; then cp -a tbs-linux-drivers_v$version_opt.zip $ARCHIVES fi unzip tbs-linux-drivers_v$version_opt.zip tar -xjf linux-tbs-drivers.tar.bz2 && cd linux-tbs-drivers find -type d -print0 | xargs -0 chmod 755 find -type f -print0 | xargs -0 chmod 644 chmod 755 v4l/*.sh chmod 755 v4l/scripts/* make $MAKEOPTS distclean if [ `getconf LONG_BIT` = "64" ] then echo " Setting up TBS drivers for an amd64 system " sh v4l/tbs-x86_64.sh if ! [ "$?" -eq 0 ]; then echo -en " \E[1;33;44m Faild to setup TBS drivers for amd64 system. Aborting... \E[0m " exit 1 fi if test "x$dvbc_opt" = "xyes"; then sh v4l/tbs-dvbc-x86_64.sh if ! [ "$?" -eq 0 ]; then echo -en " \E[1;33;44m Faild to setup TBS drivers for DVB-C on amd64 system. Aborting... \E[0m " exit 1 fi fi else echo " Setting up TBS drivers for a i386 system " sh v4l/tbs-x86_r3.sh if ! [ "$?" -eq 0 ]; then echo -en " \E[1;33;44m Faild to setup TBS drivers for i386 system. Aborting... \E[0m " exit 1 fi if test "x$dvbc_opt" = "xyes"; then sh v4l/tbs-dvbc-x86_r3.sh if ! [ "$?" -eq 0 ]; then echo -en " \E[1;33;44m Faild to setup TBS drivers for DVB-C on i386 system. Aborting... \E[0m " exit 1 fi fi fi if test "x$dvbdev_opt" = "xyes"; then patch -p1 < ../../dvb-mutex-patch if ! [ "$?" -eq 0 ]; then echo -en " \E[1;33;44m Faild to patch dvbdev.c Aborting... \E[0m " exit 1 fi fi make $MAKEOPTS allyesconfig if test "x$adapters_opt" = "x"; then sed -i "s/CONFIG_DVB_MAX_ADAPTERS=64/CONFIG_DVB_MAX_ADAPTERS=8/" v4l/.config else sed -i "s/CONFIG_DVB_MAX_ADAPTERS=64/CONFIG_DVB_MAX_ADAPTERS=$adapters_opt/" v4l/.config fi make $MAKEOPTS if ! [ "$?" -eq 0 ]; then echo " Something went wrong while compiling TBS drivers. Did you install the headers for your kernel? Are the build deps all in place? Aborting... " exit 1 fi PREVIOUSDRIVER="0" if TBSDriverLoaded; then PREVIOUSDRIVER="1" TBSUnloadDriver sleep 2 if ! [ "$?" -eq 0 ]; then echo " Could not unload TBS drivers. It is probably safe to continue, but you have to reboot your machine when done! " sleep 5 fi fi echo " Installing TBS drivers now... " MEDIA="0" if [ -d /lib/modules/`uname -r`/updates/media ]; then MEDIA="1" rm -rf /lib/modules/`uname -r`/updates/media depmod -a fi # Ensure compatability with older versions of this script if [ -d /lib/modules/`uname -r`/updates/tbs ]; then MEDIA="1" rm -rf /lib/modules/`uname -r`/updates/tbs depmod -a fi mkdir -p /lib/modules/`uname -r`/updates/media cp -f ./v4l/*.ko /lib/modules/`uname -r`/updates/media/ cp -f ../*.fw /lib/firmware/ depmod -a if [ "$PREVIOUSDRIVER" -eq "0" ]; then if [ "$MEDIA" -eq "0" ]; then TBSLoadDriver if TBSDriverLoaded; then echo -e "\nsaa716x_tbs_dvb succesfully loaded. \n" else echo -e "Could not load saa716x_tbs_dvb driver module. \n" echo -e "You are probably using an usb device, or a pcie device that does not use the saa716x_tbs_dvb driver module. Rebooting your machine when done should load the correct module" sleep 5 fi fi fi if [ "$PREVIOUSDRIVER" -eq "1" ] || [ "$MEDIA" -eq "1" ]; then echo -en " \E[1;33;44m You have just replaced the existing TBS driver modules and/or the existing /lib/modules/`uname -r`/updates/media dir. That is not a problem, but you have to reboot when done!!! \E[0m " sleep 5 fi # Pull in FFdecsawrapper, configure and compile it if test "x$ffdecsa_build" = "xyes"; then echo " Do you want to compile and install FFdecsawrapper now? " confirmyes "Go ahead! [Y/n]" if ! [ "$?" -eq 0 ]; then echo " You have chosen not to install FFdecsawrapper. " exit 0 else cd .. && rm -rf ffdecsawrapper && git clone https://github.com/bas-t/ffdecsawrapper.git if ! [ "$?" -eq 0 ]; then echo " Failed to clone FFdecsawrapper repo Aborting... " exit 1 fi cd ffdecsawrapper git checkout 2bd9a7e820eb2aaf10209c6a876fa5d8365c94eb if ! [ "$?" -eq 0 ]; then echo " Failed to cheout specific FFdecsawrapper commit Aborting... " exit 1 fi ./configure --dvb_dir=../linux-tbs-drivers/linux --v4l=yes $ffdecsa_conf fi fi echo -en " \E[1;33;44m Reboot now? \E[0m " confirmyes "Yes, shutdown nfdump & nfsen and poweroff now! [Y/n]" if [ "$?" -eq 0 ]; then /etc/init.d/nfdump stop /etc/init.d/nfsen stop /sbin/poweroff fi