Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 126 by niro, Fri Apr 13 21:55:56 2007 UTC revision 860 by niro, Wed Jul 1 18:02:28 2009 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.1 2007-04-13 21:55:56 niro Exp $  # $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  # Configures virtualbox for Magellan-Linux
4    
5  LIBDIR=/usr/lib  LIBDIR=/usr/lib
6  INSTDIR=${LIBDIR}/virtualbox  INSTDIR=${LIBDIR}/virtualbox
7  VBOXMODULE=vboxdrv.ko  VBOXMODULE=vboxdrv.ko
8    VBOXNETMODULE=vboxnetflt.ko
9    
10  echo "Running $(basename $0) for kernelversion $(uname -r) ..."  COLRED="\033[1;6m\033[31m"
11    COLGREEN="\033[1;6m\033[32m"
12    COLDEFAULT="\033[0m"
13    
14  if [ ! -f /lib/modules/$(uname -r)/source/include/linux/version.h ]  if [[ ${NOCOLORS} = true ]]
15  then  then
16   echo "No includes for $(uname -r) found! Aborting."   COLRED=""
17   exit 1   COLGREEN=""
18     COLDEFAULT=""
19  fi  fi
20    
21  if [[ -f /lib/modules/$(uname -r)/misc/${VBOXMODULE} ]]  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  then
45   echo "Removing old module ..."   die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."
  rm -f /lib/modules/$(uname -r)/misc/${VBOXMODULE}  
46  fi  fi
47    
48  # compile the module  for module in ${VBOXMODULE} ${VBOXNETMODULE}
49  cd ${INSTDIR}/src  do
50  make -C /lib/modules/$(uname -r)/source SUBDIRS=$(pwd) SRCROOT=$(pwd) clean modules   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module} ]]
51     then
52  # install the module   mecho "Removing old ${module} module ..."
53  install -d /lib/modules/$(uname -r)/misc   # try to unload the modules
54  install -m0644 ${VBOXMODULE} /lib/modules/$(uname -r)/misc   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  # calc module dependencies
83  depmod -ae  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  # load the module
94  echo "Loading module ${VBOXMODULE} ..."  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]
95  modprobe $(basename ${VBOXMODULE} .ko)  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  echo
110  echo "Virtualbox is now configured for your system."  mecho "Virtualbox is now configured for your system."
111  echo "Do not forget to add you users to the 'virtualbox' group."  mecho "Do not forget to add your users to the 'virtualbox' group."
112  echo  echo
113    
114  exit 0  exit 0

Legend:
Removed from v.126  
changed lines
  Added in v.860