A bash script to rebuild the TBS tuner drivers after Linux kernel updates

Something that seems to annoy many TBS tuner card owners is that the TBS drivers need to be rebuilt and reinstalled EVERY SINGLE TIME there is a Linux kernel update, and although it’s not a particularly difficult process, it is time-consuming (it can take several minutes).  And, there a bit of typing or cutting and pasting involved, plus it’s possible to miss a step or introduce a typo and create a bad build. So, here is a bash script that you can install and run that will attempt to rebuild and install your TBS drivers. It came from a thread on Reddit so I cannot vouch for it in any way, but it looks pretty solid.

This script probably should not be relied upon for a first time installation of the drivers, since it does not appear to do any checks for any necessary dependencies, and also it does not check to make sure that your TBS cards aren’t using a shared IRQ (which is generally a bad thing – see this article for the fix). But, once you know your TBS cards work you could perhaps use this script after those kernel updates to keep them working.  As far as I know this script is not endorsed or supported by TBS, in fact they probably don’t even know about it.

If it is your first time installing the TBS drivers and you are running some version of Ubuntu or Debian, then at least do this prior to running this script for the first time:

sudo apt-get update
sudo apt-get install linux-headers-`uname -r`
sudo apt-get install make gcc

You should only need to do that once, and don’t be surprised if some or all of those are already installed. If you are not running some version of Ubuntu or Debian then you may still need to install Linux headers, make, and gcc using your OS’s package management tool, if any of those are not already installed.

Caveats (things not mentioned in the original Reddit thread but observed by reading the script):

  1. You must create a directory called “Drivers” in your home directory (enter mkdir ~/Drivers at the command prompt), this is where it will store the current driver version. The script as written does not appear to create the Drivers directory if it doesn’t already exist.  If you want to change the name or location of this directory then change the line “cd ~/Drivers” in the script accordingly. EDIT: This line has been modified so that if the directory does not exist, the script will no longer just blindly forge ahead in whatever directory you happen to be running it from; instead it will advise you to create the directory and exit.
  2. You must make the script executable.
  3. As written it appears it must be run as root or using sudo (sudo ./scriptname)
  4. It appears that as written it is dependent on the current TBS practice of showing the latest Linux version on the page at http://www.tbsdtv.com/download/ and actually providing the driver file at http://www.tbsdtv.com/download/document/common/tbs-linux-drivers_vyymmdd.zip where yymmdd are replaced by the file date.
  5. It seems that as written, the script is intended for use with modern 64-bit versions of Linux, as indicated by the “./v4l/tbs-x86_64.sh” – if you are running a 32-bit Linux (is anyone still doing this?) then you’ll need to use either “./v4l/tbs-x86_r3.sh” (for x86 32 bit installations of kernel 3.x) or if you are really living in the past, “./v4l/tbs-x86.sh” (for x86 32 bit installations of kernel 2.6.x) instead.
  6. After it runs to completion it will ask if you want to reboot the system, which will be necessary before the rebuilt drivers can be used.

I don’t guarantee this script will work for you.  Use is entirely at your own risk! I’m just passing it along. Feel free to comment on whether it works for you or not.

#! /bin/bash
(( UID != 0 )) && { echo "Error: needs root"; exit 1; } #Use this to check for root
cd ~/Drivers || { echo "Error: ~/Drivers directory does not exist - run 'mkdir ~/Drivers' (without the quotes) from the command prompt"; exit 1; }
rm -rf linux-tbs-drivers #Remove previous linux-tbs-drivers directory if it exists
wget -nc "http://www.tbsdtv.com/$(wget -q -O - 'http://www.tbsdtv.com/download/' | sed -n 's@.*href="\([^"]*common/tbs-linux-drivers_v[0-9]*.zip\)".*@\1@; T; p; q')" #The $() part returns only the first occurrence of "common/tbs-linux-drivers_v[0-9]*.zip". Downloading it with -nc (no clobber) will not overwrite a currently existing archive.
for latest in tbs-linux-drivers_v*zip; do :; done #This loops over all versions and $latest will become the alphanumerically last one.
if unzip -o "$latest"; then
    tar xjvf linux-tbs-drivers.tar.bz2
else
    echo "Error: Unzip failed"
    exit 1
fi
cd linux-tbs-drivers
./v4l/tbs-x86_64.sh || { echo "Error running ./v4l/tbs-x86_64.sh"; exit 1; }
make || { echo "Error running make"; exit 1; }
make install || { echo "Error running make install"; exit 1; }
read -p "Reboot (y/N)? "
[[ "$REPLY" == y ]] && reboot

If you found this article useful you may also like:
Do you run one or more TBS PCIe cards under Linux? Check your IRQs…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s