Contents of /trunk/virtualbox/vboxsf.sh
Parent Directory | Revision Log
Revision 1639 -
(show annotations)
(download)
(as text)
Tue Feb 7 22:57:29 2012 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2901 byte(s)
Tue Feb 7 22:57:29 2012 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2901 byte(s)
-applied serveral fixes for systemd
1 | #!/bin/bash |
2 | # $Id$ |
3 | # Compiles vboxsf 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.4 ]] |
37 | then |
38 | mod_suffix="o" |
39 | else |
40 | mod_suffix="ko" |
41 | fi |
42 | |
43 | echo "${mod_suffix}" |
44 | } |
45 | |
46 | PVER="@@PVER@@" |
47 | BUILDROOT="$(mktemp -d)" |
48 | SRCTARBALL="/usr/src/vboxsf/vboxsf-${PVER}.tar.bz2" |
49 | SRCDIR="${BUILDROOT}/vboxsf" |
50 | KERNEL_MODULE="vboxsf" |
51 | MODULES_AUTOLOAD="/etc/modules-load.d" |
52 | |
53 | COLRED="\033[1;6m\033[31m" |
54 | COLGREEN="\033[1;6m\033[32m" |
55 | COLDEFAULT="\033[0m" |
56 | |
57 | if [[ ${NOCOLORS} = true ]] |
58 | then |
59 | COLRED="" |
60 | COLGREEN="" |
61 | COLDEFAULT="" |
62 | fi |
63 | |
64 | # must be root |
65 | [[ $(id -u) != 0 ]] && die "You must be r00t!" |
66 | |
67 | # check for given argvs |
68 | for i in $* |
69 | do |
70 | case $1 in |
71 | --kernel-version) shift; KERNEL_VERSION="$1" ;; |
72 | --kernel-sources) shift; KERNEL_SOURCES="$1" ;; |
73 | esac |
74 | shift |
75 | done |
76 | |
77 | # some sane defaults |
78 | [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)" |
79 | [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source" |
80 | KERNEL_MODULE_DEST="/lib/modules/${KERNEL_VERSION}/misc" |
81 | KERNEL_MODULE_SUFFIX="$(mod_suffix ${KERNEL_SOURCES})" |
82 | |
83 | if [[ -f ${KERNEL_MODULE_DEST}/${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} ]] |
84 | then |
85 | mecho "Removing old ${KERNEL_MODULE}-module ..." |
86 | # try to unload the module |
87 | if [[ -n $(grep "${KERNEL_MODULE} " /proc/modules 2> /dev/null) ]] |
88 | then |
89 | modprobe -r ${KERNEL_MODULE} |
90 | fi |
91 | rm -f ${KERNEL_MODULE_DEST}/${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} |
92 | fi |
93 | if [[ -f ${MODULES_AUTOLOAD}/${KERNEL_MODULE}.conf ]] |
94 | then |
95 | mecho "Removing old ${KERNEL_MODULE} autoload config ..." |
96 | rm -f ${MODULES_AUTOLOAD}/${KERNEL_MODULE}.conf |
97 | fi |
98 | |
99 | # unpack src-tarball |
100 | mecho "Uncompressing src-tarball ..." |
101 | tar xjpf ${SRCTARBALL} -C ${BUILDROOT} || die |
102 | cd ${SRCDIR} |
103 | |
104 | mecho "Compiling ${KERNEL_MODULE}-module for kernel ${KERNEL_VERSION} ..." |
105 | make -C ${KERNEL_SOURCES} V=0 M="$(pwd)" modules || die |
106 | |
107 | mecho "Installing ${KERNEL_MODULE}-module into ${KERNEL_MODULE_DEST} ..." |
108 | install -d ${KERNEL_MODULE_DEST} || die |
109 | install -m0644 ${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} ${KERNEL_MODULE_DEST} || die |
110 | if [[ -d ${MODULE_AUTOLOAD} ]] |
111 | then |
112 | echo "${KERNEL_MODULE}" > ${MODULES_AUTOLOAD}/${KERNEL_MODULE}.conf |
113 | fi |
114 | |
115 | mecho "Calculating module dependencies ..." |
116 | depmod -a ${KERNEL_VERSION} |
117 | |
118 | exit 0 |