Magellan Linux

Annotation of /trunk/virtualbox/vboxvideo.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1070 - (hide annotations) (download) (as text)
Mon Aug 9 20:31:47 2010 UTC (14 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 2905 byte(s)
-added new files

1 niro 1070 #!/bin/bash
2     # $Header: /root/magellan-cvs/src/virtualbox/vboxvideo.sh,v 1.1 2010-08-09 20:31:47 niro Exp $
3     # Compiles vboxvideo drm module for given kernel
4    
5     die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; }
6     mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; }
7    
8     kernel_major_version()
9     {
10     local ksrc="$@"
11     local kv
12    
13     if [[ -z ${ksrc} ]]
14     then
15     kv="$(uname -r|cut -d. -f1-2)"
16     else
17     local version
18     local patchlevel
19    
20     # get version from makefile
21     version=$(grep "^VERSION[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
22     # get patchlevel from makefile
23     patchlevel=$(grep "^PATCHLEVEL[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
24     # kernelversion
25     kv="${version}.${patchlevel}"
26     fi
27    
28     echo "${kv}"
29     }
30    
31     mod_suffix()
32     {
33     local ksrc="$@"
34     local mod_suffix
35    
36     if [[ $(kernel_major_version ${ksrc}) = 2.6 ]]
37     then
38     mod_suffix="ko"
39     else
40     mod_suffix="o"
41     fi
42    
43     echo "${mod_suffix}"
44     }
45    
46     PVER="@@PVER@@"
47     BUILDROOT="$(mktemp -d)"
48     SRCTARBALL="/usr/src/vboxvideo/vboxvideo-${PVER}.tar.bz2"
49     SRCDIR="${BUILDROOT}/vboxvideo"
50     KERNEL_MODULE="vboxvideo"
51    
52     COLRED="\033[1;6m\033[31m"
53     COLGREEN="\033[1;6m\033[32m"
54     COLDEFAULT="\033[0m"
55    
56     if [[ ${NOCOLORS} = true ]]
57     then
58     COLRED=""
59     COLGREEN=""
60     COLDEFAULT=""
61     fi
62    
63     # must be root
64     [[ $(id -u) != 0 ]] && die "You must be r00t!"
65    
66     # check for given argvs
67     for i in $*
68     do
69     case $1 in
70     --kernel-version) shift; KERNEL_VERSION="$1" ;;
71     --kernel-sources) shift; KERNEL_SOURCES="$1" ;;
72     esac
73     shift
74     done
75    
76     # some sane defaults
77     [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)"
78     [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source"
79     KERNEL_MODULE_DEST="/lib/modules/${KERNEL_VERSION}/video"
80     KERNEL_MODULE_SUFFIX="$(mod_suffix ${KERNEL_SOURCES})"
81    
82     if [[ -f ${KERNEL_MODULE_DEST}/${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} ]]
83     then
84     mecho "Removing old ${KERNEL_MODULE}-module ..."
85     # try to unload the module
86     if [[ -n $(grep "${KERNEL_MODULE} " /proc/modules 2> /dev/null) ]]
87     then
88     modprobe -r ${KERNEL_MODULE}
89     fi
90     rm -f ${KERNEL_MODULE_DEST}/${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX}
91     fi
92    
93     # unpack src-tarball
94     mecho "Uncompressing src-tarball ..."
95     tar xjpf ${SRCTARBALL} -C ${BUILDROOT} || die
96     cd ${SRCDIR}
97    
98     mecho "Compiling ${KERNEL_MODULE}-module for kernel ${KERNEL_VERSION} ..."
99     gcc_major="$(gcc --version | grep gcc | cut -d' ' -f3|cut -d. -f1)"
100     export _POSIX2_VERSION="199209"
101     [[ $(kernel_major_version ${KERNEL_SOURCES}) = 2.6 ]] && cp 2.6.x/Makefile ${SRCDIR}
102     make -C ${KERNEL_SOURCES} V=0 M="$(pwd)" GCC_VER_MAJ="${gcc_major}" modules || die
103    
104     mecho "Installing ${KERNEL_MODULE}-module into ${KERNEL_MODULE_DEST} ..."
105     install -d ${KERNEL_MODULE_DEST} || die
106     install -m0644 ${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} ${KERNEL_MODULE_DEST} || die
107    
108     mecho "Calculating module dependencies ..."
109     depmod -ae ${KERNEL_VERSION}
110    
111     exit 0