Magellan Linux

Contents of /trunk/virtualbox/virtualbox-config.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 860 - (show annotations) (download) (as text)
Wed Jul 1 18:02:28 2009 UTC (14 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 3009 byte(s)
-updated to work with newer udev
-newer vitualbox versions (>2.0.0) needs to modules: vboxdrv and vboxnetflt

1 #!/bin/bash
2 # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.9 2009-07-01 18:02:28 niro Exp $
3 # Configures virtualbox for Magellan-Linux
4
5 LIBDIR=/usr/lib
6 INSTDIR=${LIBDIR}/virtualbox
7 VBOXMODULE=vboxdrv.ko
8 VBOXNETMODULE=vboxnetflt.ko
9
10 COLRED="\033[1;6m\033[31m"
11 COLGREEN="\033[1;6m\033[32m"
12 COLDEFAULT="\033[0m"
13
14 if [[ ${NOCOLORS} = true ]]
15 then
16 COLRED=""
17 COLGREEN=""
18 COLDEFAULT=""
19 fi
20
21 die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; }
22 mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; }
23
24 # must be root
25 [[ $(id -u) != 0 ]] && die "You must be r00t!"
26
27 # check for given argvs
28 for i in $*
29 do
30 case $1 in
31 --kernel-version) shift; KERNEL_VERSION="$1" ;;
32 --kernel-sources) shift; KERNEL_SOURCES="$1" ;;
33 esac
34 shift
35 done
36
37 # some sane defaults
38 [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)"
39 [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source"
40
41 mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..."
42
43 if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ]
44 then
45 die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."
46 fi
47
48 for module in ${VBOXMODULE} ${VBOXNETMODULE}
49 do
50 if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module} ]]
51 then
52 mecho "Removing old ${module} module ..."
53 # try to unload the modules
54 if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]]
55 then
56 modprobe -r ${module/.ko/}
57 fi
58 rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}
59 fi
60 done
61
62 for module in ${VBOXMODULE} ${VBOXNETMODULE}
63 do
64 # compile the module
65 cd ${INSTDIR}/src/${module/.ko/}
66
67 make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean || die "mod-compile ${module}"
68
69 # need some symver from vboxmodule (must be run after clean!)
70 if [[ ${module} = ${VBOXNETMODULE} ]] && [[ -f ../${VBOXMODULE/.ko/}/Module.symvers ]]
71 then
72 cp ../${VBOXMODULE/.ko/}/Module.symvers .
73 fi
74
75 make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) modules || die "mod-compile ${module}"
76
77 # install the modules
78 install -d /lib/modules/${KERNEL_VERSION}/misc
79 install -m0644 ${module} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}"
80 done
81
82 # calc module dependencies
83 mecho "Calculating module dependencies ..."
84 depmod -ae ${KERNEL_VERSION}
85
86 # re-read udev rules to grant the right permissions
87 if [[ -x $(which udevadm) ]]
88 then
89 mecho "Reloading udev configuration ..."
90 $(which udevadm) control --reload-rules
91 fi
92
93 # load the module
94 if [[ x$(uname -r) = x${KERNEL_VERSION} ]]
95 then
96 for module in ${VBOXMODULE} ${VBOXNETMODULE}
97 do
98 mecho "Loading kernel-module ${module} ..."
99 modprobe $(basename ${module} .ko)
100 done
101 else
102 echo -e ${COLRED}
103 echo "Your current running kernel does not match the the module target."
104 echo "You must boot into your target kernel and load the modules manually,"
105 echo "before you can use virtual box."
106 echo -en ${COLDEFAULT}
107 fi
108
109 echo
110 mecho "Virtualbox is now configured for your system."
111 mecho "Do not forget to add your users to the 'virtualbox' group."
112 echo
113
114 exit 0