[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A script to automate the error-prone kernel module build



I've written a simple script that configures the kernel source tree (if needed) and builds the fglrx module for you; it will also instruct you to install any missing pieces. This should completely automate the error-prone kernel module build.

Save this script in a directory of your choice, run it with
  sh fglrx-build.sh
and enjoy.

The script should NOT touch your kernel source tree without asking, but if you have customized it make a backup just in case.

As soon as I get some feedback about this script, I will upgrade the instructions on my page. For now, if you are at all unsure, please DON'T use this script and follow the usual instructions.

--
Ciao, Flavio

#!/bin/sh

set -e

if [ $UID -eq 0 ]; then
  echo "*** DO NOT run this script as root ***"
  exit 1
fi

MODULES=$(find /usr/src/modules -name "fglrx-*" -type d -maxdepth 1 -printf "%f," | sed 's/,$//g')

if [ -z "$MODULES" ]; then
  echo "Please install and unpack the sources for the fglrx kernel module"
  exit 1
fi

if [ -z "$KSRC" ]; then
  if [ ! -d "/lib/modules/$(uname -r)" ]; then
    echo "Directory /lib/modules/$(uname -r) does not exist (or is not a directory)"
    exit 1
  fi
  if [ ! -L "/lib/modules/$(uname -r)/build" ]; then
    echo "Link /lib/modules/$(uname -r)/build does not exist (or is not a link)"
    exit 1
  fi
  KSRC=$(readlink "/lib/modules/$(uname -r)/build")
  if [ ! -d "$KSRC" ]; then
    echo "Please install the sources for kernel version $(uname -r)"
    echo "and unpack them into directory $KSRC"
    exit 1
  fi
fi

echo "Kernel source in $KSRC"
cd "$KSRC"

function get_kernel_version ()
{
  if [ -f "version.Debian" ]; then
    cat "version.Debian"
  else
    VERSION=$(grep "^VERSION " Makefile | sed 's/^[A-Z]* = //')
    PATCHLEVEL=$(grep "^PATCHLEVEL " Makefile | sed 's/^[A-Z]* = //')
    SUBLEVEL=$(grep "^SUBLEVEL " Makefile | sed 's/^[A-Z]* = //')
    echo "$VERSION.$PATCHLEVEL.$SUBLEVEL"
  fi
}

KVERS=$(get_kernel_version)

FLAVOUR=$(uname -r | sed 's/[0-9]*\.[0-9]*\.[0-9]*//')

if [ ! -f .config -o ! -f stamp-configure ]; then
  echo -n "Kernel source not configured; configure it? [y/N] "
  read -n1 answer
  if [ "$answer" = "y" ]; then
    echo ""
    # copy /boot/config
    test -f .config || cp "/boot/config-$(uname -r)" .config

    test -z "$(echo $KVERS | sed 's/[^-]//g')" || \
      echo "*** Please ignore warning about a hyphen in the revision number ***"
    make-kpkg --append-to-version "$FLAVOUR" --revision "$KVERS" \
      --config old configure
  else
    echo "Please configure your kernel with make-kpkg"
    exit 1
  fi
fi

# load kernel configuration
. .config

# test kernel configuration
if [ -z "$CONFIG_MODULES" ]; then
  echo "CONFIG_MODULES is not set; this is required, please set it and rebuild your kernel"
  exit 1
fi

if [ -z "$CONFIG_AGP" ]; then
  echo "CONFIG_AGP is not set; make sure this is what you want"
  echo -n "Press RETURN to continue... "
  read dummy
fi

# modules usually don't like --rootcmd
fakeroot make-kpkg --append-to-version "$FLAVOUR" \
  --added-modules=${MODULES} modules_image

echo ""
echo "Please install the Debian package just created and enjoy"

# $Id: msg00032.html,v 1.1 2007-02-26 20:08:38 flavio Exp $