1 | # Oracle VM VirtualBox
|
---|
2 | # VirtualBox installer shell routines
|
---|
3 | #
|
---|
4 |
|
---|
5 | # Copyright (C) 2007-2010 Oracle Corporation
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.alldomusa.eu.org. This file is free software;
|
---|
9 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | # General Public License (GPL) as published by the Free Software
|
---|
11 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | #
|
---|
15 |
|
---|
16 | ro_LOG_FILE=""
|
---|
17 | ro_X11_AUTOSTART="/etc/xdg/autostart"
|
---|
18 | ro_KDE_AUTOSTART="/usr/share/autostart"
|
---|
19 |
|
---|
20 | # Aborts the script and prints an error message to stderr.
|
---|
21 | #
|
---|
22 | # syntax: abort message
|
---|
23 |
|
---|
24 | abort() {
|
---|
25 | echo 1>&2 "$1"
|
---|
26 | exit 1
|
---|
27 | }
|
---|
28 |
|
---|
29 | # Creates an empty log file and remembers the name for future logging
|
---|
30 | # operations
|
---|
31 | #
|
---|
32 | # syntax: create_log logfile
|
---|
33 |
|
---|
34 | create_log() {
|
---|
35 | ro_LOG_FILE="$1"
|
---|
36 | if [ "$ro_LOG_FILE" = "" ]; then
|
---|
37 | abort "create_log called without an argument! Aborting..."
|
---|
38 | fi
|
---|
39 | # Create an empty file
|
---|
40 | echo > "$ro_LOG_FILE" 2> /dev/null
|
---|
41 | if [ ! -f "$ro_LOG_FILE" -o "`cat "$ro_LOG_FILE"`" != "" ]; then
|
---|
42 | abort "Error creating log file! Aborting..."
|
---|
43 | fi
|
---|
44 | }
|
---|
45 |
|
---|
46 | # Writes text to standard error
|
---|
47 | #
|
---|
48 | # Syntax: info text
|
---|
49 |
|
---|
50 | info() {
|
---|
51 | echo 1>&2 "$1"
|
---|
52 | }
|
---|
53 |
|
---|
54 | # Writes text to the log file
|
---|
55 | #
|
---|
56 | # Syntax: log text
|
---|
57 |
|
---|
58 | log() {
|
---|
59 | if [ "$ro_LOG_FILE" = "" ]; then
|
---|
60 | abort "Error! Logging has not been set up yet! Aborting..."
|
---|
61 | fi
|
---|
62 | echo "$1" >> $ro_LOG_FILE
|
---|
63 | return 0
|
---|
64 | }
|
---|
65 |
|
---|
66 | # Writes test to standard output and to the log file
|
---|
67 | #
|
---|
68 | # Syntax: infolog text
|
---|
69 |
|
---|
70 | infolog() {
|
---|
71 | info "$1"
|
---|
72 | log "$1"
|
---|
73 | }
|
---|
74 |
|
---|
75 | # Checks whether a module is loaded with a given string in its name.
|
---|
76 | #
|
---|
77 | # syntax: module_loaded string
|
---|
78 |
|
---|
79 | module_loaded() {
|
---|
80 | if [ "$1" = "" ]; then
|
---|
81 | log "module_loaded called without an argument. Aborting..."
|
---|
82 | abort "Error in installer. Aborting..."
|
---|
83 | fi
|
---|
84 | lsmod | grep -q $1
|
---|
85 | }
|
---|
86 |
|
---|
87 | # Abort if we are not running as root
|
---|
88 |
|
---|
89 | check_root() {
|
---|
90 | if [ `id -u` -ne 0 ]; then
|
---|
91 | abort "This program must be run with administrator privileges. Aborting"
|
---|
92 | fi
|
---|
93 | }
|
---|
94 |
|
---|
95 | # Abort if a copy of VirtualBox is already running
|
---|
96 |
|
---|
97 | check_running() {
|
---|
98 | VBOXSVC_PID=`pidof VBoxSVC 2> /dev/null`
|
---|
99 | if [ -n "$VBOXSVC_PID" ]; then
|
---|
100 | kill -USR1 $VBOXSVC_PID
|
---|
101 | sleep 1
|
---|
102 | if pidof VBoxSVC > /dev/null 2>&1; then
|
---|
103 | echo 1>&2 "A copy of VirtualBox is currently running. Please close it and try again."
|
---|
104 | abort "Please note that it can take up to ten seconds for VirtualBox to finish running."
|
---|
105 | fi
|
---|
106 | fi
|
---|
107 | }
|
---|
108 |
|
---|
109 | # Do we have bzip2?
|
---|
110 |
|
---|
111 | check_bzip2() {
|
---|
112 | if ! ls /bin/bzip2 /usr/bin/bzip2 /usr/local/bin/bzip2 2> /dev/null | grep bzip2 > /dev/null; then
|
---|
113 | echo 1>&2 "Please install the bzip2 utility."
|
---|
114 | log "Please install bzip2."
|
---|
115 | return 1
|
---|
116 | fi
|
---|
117 | return 0
|
---|
118 | }
|
---|
119 |
|
---|
120 | # Do we have GNU make?
|
---|
121 |
|
---|
122 | check_gmake() {
|
---|
123 | make --version 2>&1 | grep GNU > /dev/null
|
---|
124 | if [ ! $? = 0 ]; then
|
---|
125 | echo 1>&2 "Please install GNU make."
|
---|
126 | log "Please install GNU make."
|
---|
127 | return 1
|
---|
128 | fi
|
---|
129 | return 0
|
---|
130 | }
|
---|
131 |
|
---|
132 | # Can we find the kernel source?
|
---|
133 |
|
---|
134 | check_ksource() {
|
---|
135 | ro_KBUILD_DIR=/lib/modules/`uname -r`/build
|
---|
136 | if [ ! -d $ro_KBUILD_DIR/include ]; then
|
---|
137 | ro_KBUILD_DIR=/usr/src/linux
|
---|
138 | if [ ! -d $ro_KBUILD_DIR/include ]; then
|
---|
139 | echo 1>&2 "Please install the build and header files for your current Linux kernel."
|
---|
140 | echo 1>&2 "The current kernel version is `uname -r`"
|
---|
141 | ro_KBUILD_DIR=""
|
---|
142 | log "Could not find the Linux kernel header files - the directories"
|
---|
143 | log " /lib/modules/`uname -r`/build/include and /usr/src/linux/include"
|
---|
144 | log " do not exist."
|
---|
145 | return 1
|
---|
146 | fi
|
---|
147 | fi
|
---|
148 | return 0
|
---|
149 | }
|
---|
150 |
|
---|
151 | # Is GCC installed?
|
---|
152 |
|
---|
153 | check_gcc() {
|
---|
154 | ro_gcc_version=`gcc --version 2> /dev/null | head -n 1`
|
---|
155 | if [ "$ro_gcc_version" = "" ]; then
|
---|
156 | echo 1>&2 "Please install the GNU compiler."
|
---|
157 | log "Please install the GNU compiler."
|
---|
158 | return 1
|
---|
159 | fi # GCC installed
|
---|
160 | return 0
|
---|
161 | }
|
---|
162 |
|
---|
163 | # Is bash installed? You never know...
|
---|
164 |
|
---|
165 | check_bash() {
|
---|
166 | if [ ! -x /bin/bash ]; then
|
---|
167 | echo 1>&2 "Please install GNU bash."
|
---|
168 | log "Please install GNU bash."
|
---|
169 | return 1
|
---|
170 | fi
|
---|
171 | return 0
|
---|
172 | }
|
---|
173 |
|
---|
174 | # Is perl installed?
|
---|
175 |
|
---|
176 | check_perl() {
|
---|
177 | if [ ! `perl -e 'print "test"' 2> /dev/null` = "test" ]; then
|
---|
178 | echo 1>&2 "Please install perl."
|
---|
179 | echo "Please install perl."
|
---|
180 | return 1
|
---|
181 | fi
|
---|
182 | return 0
|
---|
183 | }
|
---|
184 |
|
---|
185 | # What type of system are we running on?
|
---|
186 |
|
---|
187 | check_system_type() {
|
---|
188 | if [ ! "$ro_SYS_TYPE" = "" ]; then
|
---|
189 | return 0
|
---|
190 | elif [ -f /etc/debian_version ]; then
|
---|
191 | ro_SYS_TYPE=debian
|
---|
192 | ro_INIT_TYPE=sysv
|
---|
193 | elif [ -f /etc/gentoo-release ]; then
|
---|
194 | ro_SYS_TYPE=gentoo
|
---|
195 | ro_INIT_TYPE=sysv
|
---|
196 | elif [ -x /sbin/chkconfig ]; then
|
---|
197 | ro_SYS_TYPE=redhat
|
---|
198 | ro_INIT_TYPE=sysv
|
---|
199 | elif [ -x /sbin/insserv ]; then
|
---|
200 | ro_SYS_TYPE=suse
|
---|
201 | ro_INIT_TYPE=sysv
|
---|
202 | elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
|
---|
203 | ro_SYS_TYPE=lfs
|
---|
204 | ro_INIT_TYPE=lfs
|
---|
205 | elif [ -f /etc/pardus-release ]; then
|
---|
206 | ro_SYS_TYPE=pardus
|
---|
207 | ro_INIT_TYPE=pardus
|
---|
208 | elif [ -f /etc/rc.d/rc.local ]; then
|
---|
209 | ro_SYS_TYPE=unknown
|
---|
210 | ro_INIT_TYPE=bsd
|
---|
211 | ro_RC_LOCAL=/etc/rc.d/rc.local
|
---|
212 | elif [ -f /etc/rc.local ]; then
|
---|
213 | ro_SYS_TYPE=unknown
|
---|
214 | ro_INIT_TYPE=bsd
|
---|
215 | ro_RC_LOCAL=/etc/rc.local
|
---|
216 | elif [ -d /etc/init.d ]; then
|
---|
217 | ro_SYS_TYPE=unknown
|
---|
218 | ro_INIT_TYPE=sysv
|
---|
219 | else # Perhaps we can determine what we need to know anyway though?
|
---|
220 | echo 1>&2 "Unable to determine your Linux distribution"
|
---|
221 | log "Unable to determine the Linux distribution"
|
---|
222 | return 1
|
---|
223 | fi
|
---|
224 | return 0
|
---|
225 | }
|
---|
226 |
|
---|
227 | # Hack to handle Mandriva's speedboot runlevel
|
---|
228 | copy_install_script() {
|
---|
229 | if [ "$ro_INIT_TYPE" = "sysv" -a -r /etc/sysconfig/speedboot ]; then
|
---|
230 | cp "$1" "$2" 2>/dev/null
|
---|
231 | else
|
---|
232 | sed -e 's/^\(#\s*chkconfig:\s*[0-9]*\)7/\1/' "$1" > "$2"
|
---|
233 | fi
|
---|
234 | }
|
---|
235 |
|
---|
236 | # Installs a file containing a shell script as an init script
|
---|
237 | #
|
---|
238 | # syntax: install_init_script file name
|
---|
239 | #
|
---|
240 | # where file is the file to be installed and
|
---|
241 | # name is the name of the new init script
|
---|
242 |
|
---|
243 | install_init_script() {
|
---|
244 | self="install_init_script"
|
---|
245 | script=$1
|
---|
246 | name=$2
|
---|
247 | pardus_script=$name-pardus.py
|
---|
248 | check_system_type
|
---|
249 | test $? -ne 1 || return 1
|
---|
250 | test -r "$script" || return 1
|
---|
251 | test ! "$name" = "" || \
|
---|
252 | { log "$self: invalid arguments" && return 1; }
|
---|
253 | if [ "$ro_INIT_TYPE" = "pardus" ];then
|
---|
254 | test -r "$pardus_script" || \
|
---|
255 | { log "$self: Pardus service script missing" && return 1; }
|
---|
256 | fi
|
---|
257 | if [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
258 | copy_install_script "$script" "/etc/init.d/$name"
|
---|
259 | chmod 755 "/etc/init.d/$name" 2> /dev/null
|
---|
260 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
261 | copy_install_script "$script" "/etc/rc.d/rc.$name"
|
---|
262 | chmod 755 "/etc/rc.d/rc.$name" 2> /dev/null
|
---|
263 | elif [ "$ro_INIT_TYPE" = "lfs" ]; then
|
---|
264 | copy_install_script "$script" "/etc/rc.d/init.d/$name"
|
---|
265 | chmod 755 "/etc/rc.d/init.d/$name" 2> /dev/null
|
---|
266 | elif [ "$ro_INIT_TYPE" = "pardus" ]; then
|
---|
267 | copy_install_script "$script" "/usr/sbin/$name"
|
---|
268 | chmod 755 "/usr/sbin/$name" 2> /dev/null
|
---|
269 | hav register $name System.Service $pardus_script
|
---|
270 | else
|
---|
271 | log "install_init_script: error: unknown init type"
|
---|
272 | return 1
|
---|
273 | fi
|
---|
274 | return 0
|
---|
275 | }
|
---|
276 |
|
---|
277 | # Remove the init script "name"
|
---|
278 | #
|
---|
279 | # syntax: remove_init_script name
|
---|
280 |
|
---|
281 | remove_init_script() {
|
---|
282 | self="remove_init_script"
|
---|
283 | name=$1
|
---|
284 | check_system_type
|
---|
285 | test $? -ne 1 || return 1
|
---|
286 | test ! "$name" = "" || \
|
---|
287 | { log "$self: missing argument" && return 1; }
|
---|
288 | if [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
289 | rm -f "/etc/init.d/$name" > /dev/null 2>&1
|
---|
290 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
291 | rm -f "/etc/rc.d/rc.$name" > /dev/null 2>&1
|
---|
292 | elif [ "$ro_INIT_TYPE" = "lfs" ]; then
|
---|
293 | rm -f "/etc/rc.d/init.d/$name" > /dev/null 2>&1
|
---|
294 | elif [ "$ro_INIT_TYPE" = "pardus" ]; then
|
---|
295 | hav remove $name
|
---|
296 | rm -f "/usr/sbin/$name" > /dev/null 2>&1
|
---|
297 | else
|
---|
298 | log "remove_init_script: error: unknown init type"
|
---|
299 | return 1
|
---|
300 | fi
|
---|
301 | return 0
|
---|
302 | }
|
---|
303 |
|
---|
304 | # Start the init script "name"
|
---|
305 | #
|
---|
306 | # syntax: start_init_script name
|
---|
307 |
|
---|
308 | start_init_script() {
|
---|
309 | self="start_init_script"
|
---|
310 | name=$1
|
---|
311 | check_system_type
|
---|
312 | test $? -ne 1 || return 1
|
---|
313 | test ! -z "$name" || \
|
---|
314 | { log "$self: missing argument" && return 1; }
|
---|
315 | if [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
316 | "/etc/init.d/$name" start >> $ro_LOG_FILE 2>&1
|
---|
317 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
318 | "/etc/rc.d/rc.$name" start >> $ro_LOG_FILE 2>&1
|
---|
319 | elif [ "$ro_INIT_TYPE" = "lfs" ]; then
|
---|
320 | "/etc/rc.d/init.d/$name" start >> $ro_LOG_FILE 2>&1
|
---|
321 | elif [ "$ro_INIT_TYPE" = "pardus" ]; then
|
---|
322 | service $name on
|
---|
323 | else
|
---|
324 | log "$self: error: unknown init type"
|
---|
325 | return 1
|
---|
326 | fi
|
---|
327 | }
|
---|
328 |
|
---|
329 | # Stop the init script "name"
|
---|
330 | #
|
---|
331 | # syntax: start_init_script name
|
---|
332 |
|
---|
333 | stop_init_script() {
|
---|
334 | self=stop_init_script
|
---|
335 | name=$1
|
---|
336 | check_system_type
|
---|
337 | test $? -ne 1 || return 1
|
---|
338 | test ! -z "$name" || \
|
---|
339 | { log "$self: missing argument" && return 1; }
|
---|
340 | if [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
341 | "/etc/init.d/$name" stop >> $ro_LOG_FILE 2>&1
|
---|
342 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
343 | "/etc/rc.d/rc.$name" stop >> $ro_LOG_FILE 2>&1
|
---|
344 | elif [ "$ro_INIT_TYPE" = "lfs" ]; then
|
---|
345 | "/etc/rc.d/init.d/$name" stop >> $ro_LOG_FILE 2>&1
|
---|
346 | elif [ "$ro_INIT_TYPE" = "pardus" ]; then
|
---|
347 | service $name off
|
---|
348 | else
|
---|
349 | log "$self: error: unknown init type"
|
---|
350 | return 1
|
---|
351 | fi
|
---|
352 | return 0
|
---|
353 | }
|
---|
354 |
|
---|
355 | # Add a service to a runlevel
|
---|
356 | #
|
---|
357 | # syntax: addrunlevel name start_order stop_order
|
---|
358 |
|
---|
359 | addrunlevel() {
|
---|
360 | test ! -z "$1" || \
|
---|
361 | { log "addrunlevel: missing argument(s)" && return 1; }
|
---|
362 | check_system_type
|
---|
363 | # Redhat based systems
|
---|
364 | if [ "$ro_SYS_TYPE" = "redhat" ]
|
---|
365 | then
|
---|
366 | test -x "/sbin/chkconfig" || \
|
---|
367 | { log "addrunlevel: /sbin/chkconfig not found" && return 1; }
|
---|
368 | /sbin/chkconfig --del $1 > /dev/null 2>&1
|
---|
369 |
|
---|
370 | if /sbin/chkconfig -v > /dev/null 2>&1; then
|
---|
371 | /sbin/chkconfig --level 35 $1 on || {
|
---|
372 | log "Cannot add $1 to run levels: 35" && return 1
|
---|
373 | }
|
---|
374 | else
|
---|
375 | /sbin/chkconfig $1 35 || {
|
---|
376 | log "Cannot add $1 to run levels: 35" && return 1
|
---|
377 | }
|
---|
378 | fi
|
---|
379 | # SUSE-base systems
|
---|
380 | elif [ "$ro_SYS_TYPE" = "suse" ]
|
---|
381 | then
|
---|
382 | test -x /sbin/insserv || {
|
---|
383 | log "addrunlevel: insserv not found" && return 1;
|
---|
384 | }
|
---|
385 | /sbin/insserv -r $1 > /dev/null 2>&1
|
---|
386 | /sbin/insserv $1 > /dev/null
|
---|
387 | # Debian/Ubuntu-based systems
|
---|
388 | elif [ "$ro_SYS_TYPE" = "debian" ]; then
|
---|
389 | test -x `which update-rc.d` || \
|
---|
390 | { log "addrunlevel: update-rc.d not found" && return 1; }
|
---|
391 | test ! -z "$2" || \
|
---|
392 | { log "addrunlevel: missing second argument" && return 1; }
|
---|
393 | test ! -z "$3" || \
|
---|
394 | { log "addrunlevel: missing third argument" && return 1; }
|
---|
395 | # Debian does not support dependencies currently -- use argument $2
|
---|
396 | # for start sequence number and argument $3 for stop sequence number
|
---|
397 | update-rc.d -f $1 remove > /dev/null 2>&1
|
---|
398 | update-rc.d $1 defaults $2 $3 > /dev/null 2>&1
|
---|
399 | # Gentoo Linux
|
---|
400 | elif [ "$ro_SYS_TYPE" = "gentoo" ]; then
|
---|
401 | test -x `which rc-update` || \
|
---|
402 | { log "addrunlevel: update-rc.d not found" && return 1; }
|
---|
403 | rc-update del $1 > /dev/null 2>&1
|
---|
404 | rc-update add $1 default > /dev/null 2>&1
|
---|
405 | # Linux from scratch, by the book
|
---|
406 | elif [ "$ro_SYS_TYPE" = "lfs" ]; then
|
---|
407 | test -x /etc/rc.d/init.d/$1 || \
|
---|
408 | { log "addrunlevel: name argument must be a script in /etc/rc.d/init.d" && return 1; }
|
---|
409 | P2=$2
|
---|
410 | P3=$3
|
---|
411 | # add leading zero
|
---|
412 | if [ `expr length "$P2"` -eq 1 ]; then
|
---|
413 | P2=`expr 0$P2`
|
---|
414 | fi
|
---|
415 | if [ `expr length "$P3"` -eq 1 ]; then
|
---|
416 | P3=`expr 0$P3`
|
---|
417 | fi
|
---|
418 | expr "$P2" + 0 > /dev/null 2>&1 && expr 0 \<= "$P2" > /dev/null && \
|
---|
419 | [ `expr length "$P2"` -eq 2 ] || \
|
---|
420 | { log "addrunlevel: start sequence number must be between 00 and 99" && return 1; }
|
---|
421 | expr "$P3" + 0 > /dev/null 2>&1 && expr 0 \<= "$P3" > /dev/null && \
|
---|
422 | [ `expr length "$P3"` -eq 2 ] || \
|
---|
423 | { log "addrunlevel: stop sequence number must be between 00 and 99" && return 1; }
|
---|
424 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc0.d/K`expr $P3`$1" > /dev/null 2>&1
|
---|
425 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc1.d/K`expr $P3`$1" > /dev/null 2>&1
|
---|
426 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc2.d/S`expr $P2`$1" > /dev/null 2>&1
|
---|
427 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc3.d/S`expr $P2`$1" > /dev/null 2>&1
|
---|
428 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc4.d/S`expr $P2`$1" > /dev/null 2>&1
|
---|
429 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc5.d/S`expr $P2`$1" > /dev/null 2>&1
|
---|
430 | ln -fs "/etc/rc.d/init.d/$1" "/etc/rc.d/rc6.d/K`expr $P3`$1" > /dev/null 2>&1
|
---|
431 | # BSD-based systems require changing the rc.local file to start a new service.
|
---|
432 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
433 | if ! grep -q $1 $ro_RC_LOCAL
|
---|
434 | then
|
---|
435 | echo "# Start $1" >> $ro_RC_LOCAL
|
---|
436 | echo "# If you do not wish this to be executed here then comment it out," >> $ro_RC_LOCAL
|
---|
437 | echo "# and the installer will skip it next time." >> $ro_RC_LOCAL
|
---|
438 | echo "if [ -x /etc/rc.d/rc.$1 ]; then" >> $ro_RC_LOCAL
|
---|
439 | echo " /etc/rc.d/rc.$1 start" >> $ro_RC_LOCAL
|
---|
440 | echo "fi" >> $ro_RC_LOCAL
|
---|
441 | echo "" >> $ro_RC_LOCAL
|
---|
442 | fi
|
---|
443 | # Probably most unknown Linux systems will be sysv type ones. These can theoretically
|
---|
444 | # be handled automatically if people give us information about them.
|
---|
445 | elif [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
446 | echo 1>&2 "As our installer does not recognize your Linux distribution, we were unable to"
|
---|
447 | echo 1>&2 "set up the initialization script $1 correctly. The script has been copied"
|
---|
448 | echo 1>&2 "copied to the /etc/init.d directory. You should set up your system to start"
|
---|
449 | echo 1>&2 "it at system start, or start it manually before using VirtualBox."
|
---|
450 | echo 1>&2 ""
|
---|
451 | echo 1>&2 "If you would like to help us add support for your distribution, please open a"
|
---|
452 | echo 1>&2 "new ticket on http://www.alldomusa.eu.org/wiki/Bugtracker."
|
---|
453 | fi
|
---|
454 | return 0
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | # Delete a service from a runlevel
|
---|
459 | #
|
---|
460 | # syntax: delrunlevel name
|
---|
461 |
|
---|
462 | delrunlevel() {
|
---|
463 | test ! -z "$1" || \
|
---|
464 | { log "delrunlevel: missing argument" && return 1; }
|
---|
465 | check_system_type
|
---|
466 | # Redhat-based systems
|
---|
467 | if [ "$ro_SYS_TYPE" = "redhat" ]
|
---|
468 | then
|
---|
469 | test -x "/sbin/chkconfig" || \
|
---|
470 | { log "addrunlevel: /sbin/chkconfig not found" && return 1; }
|
---|
471 | if /sbin/chkconfig --list $1 > /dev/null 2>&1; then
|
---|
472 | /sbin/chkconfig --del $1 > /dev/null 2>&1 || {
|
---|
473 | log "Cannot delete $1 from runlevels" && return 1
|
---|
474 | }
|
---|
475 | fi
|
---|
476 | # SUSE-based systems
|
---|
477 | elif [ "$ro_SYS_TYPE" = "suse" ]
|
---|
478 | then
|
---|
479 | test -x /sbin/insserv || {
|
---|
480 | log "addrunlevel: insserv not found" && return 1;
|
---|
481 | }
|
---|
482 | /sbin/insserv -r $1 > /dev/null 2>&1
|
---|
483 | # Debian/Ubuntu-based systems
|
---|
484 | elif [ "$ro_SYS_TYPE" = "debian" ]; then
|
---|
485 | test -x `which update-rc.d` || \
|
---|
486 | { log "addrunlevel: update-rc.d not found" && return 1; }
|
---|
487 | update-rc.d -f $1 remove > /dev/null 2>&1
|
---|
488 | # Gentoo Linux
|
---|
489 | elif [ "$ro_SYS_TYPE" = "gentoo" ]; then
|
---|
490 | test -x `which rc-update` || \
|
---|
491 | { log "addrunlevel: update-rc.d not found" && return 1; }
|
---|
492 | rc-update del "$1" > /dev/null 2>&1
|
---|
493 | # Linux from scratch, by the book
|
---|
494 | elif [ "$ro_SYS_TYPE" = "lfs" ]; then
|
---|
495 | rm "/etc/rc0.d/K??$1" > /dev/null 2>&1
|
---|
496 | rm "/etc/rc1.d/K??$1" > /dev/null 2>&1
|
---|
497 | rm "/etc/rc2.d/S??$1" > /dev/null 2>&1
|
---|
498 | rm "/etc/rc3.d/S??$1" > /dev/null 2>&1
|
---|
499 | rm "/etc/rc4.d/S??$1" > /dev/null 2>&1
|
---|
500 | rm "/etc/rc5.d/S??$1" > /dev/null 2>&1
|
---|
501 | rm "/etc/rc6.d/K??$1" > /dev/null 2>&1
|
---|
502 | # Unknown sysv-type system
|
---|
503 | elif [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
504 | echo 1>&2 "Please remove remove references to the initialization script"
|
---|
505 | echo 1>&2 "/etc/init.d/$1 to complete the uninstallation."
|
---|
506 | fi
|
---|
507 | # BSD-type systems will just not start the script if it is not there.
|
---|
508 | # Assume that BSD users understand their system.
|
---|
509 | return 0
|
---|
510 | }
|
---|
511 |
|
---|
512 | # Do initial setup of an installed service
|
---|
513 | #
|
---|
514 | # syntax: setup_init_script name
|
---|
515 |
|
---|
516 | setup_init_script()
|
---|
517 | {
|
---|
518 | self=setup_init_script
|
---|
519 | name=$1
|
---|
520 | spaces=`printf " %b" "\t"`
|
---|
521 | check_system_type
|
---|
522 | test $? -ne 1 || return 1
|
---|
523 | test ! -z "$name" ||
|
---|
524 | { log "$self: missing argument" && return 1; }
|
---|
525 | if [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
526 | scriptname="/etc/init.d/$name"
|
---|
527 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
528 | scriptname="/etc/rc.d/rc.$name"
|
---|
529 | elif [ "$ro_INIT_TYPE" = "lfs" ]; then
|
---|
530 | scriptname="/etc/rc.d/init.d/$name"
|
---|
531 | elif [ "$ro_INIT_TYPE" = "pardus" ]; then
|
---|
532 | scriptname="/usr/sbin/$name"
|
---|
533 | else
|
---|
534 | log "$self: error: unknown init type"
|
---|
535 | return 1
|
---|
536 | fi
|
---|
537 | # Add the init script to the default runlevel
|
---|
538 | # This is complicated by the fact that we need to pass older Debian-based
|
---|
539 | # systems the start and stop order numbers, which we extract from the
|
---|
540 | # Redhat chkconfig information.
|
---|
541 | if test "$ro_INIT_TYPE" = "sysv" -a -r "$scriptname"; then
|
---|
542 | orders=`grep '^#['"$spaces"']*chkconfig:' "$scriptname" |
|
---|
543 | sed -e 's/^#['"$spaces"']*chkconfig:\s*[0-9]*['"$spaces"']*//'`
|
---|
544 | expr "$orders" : '[0-9]*['"$spaces"']*[0-9]*$' > /dev/null ||
|
---|
545 | {
|
---|
546 | log "$self: bad or missing chkconfig line in init script $scriptname"
|
---|
547 | return 1
|
---|
548 | }
|
---|
549 | # $orders is deliberately not quoted here
|
---|
550 | addrunlevel "$name" $orders
|
---|
551 | else
|
---|
552 | addrunlevel "$name"
|
---|
553 | fi
|
---|
554 | test -r "$scriptname" &&
|
---|
555 | grep -q '^#['"$spaces"']*setup_script['"$spaces"']*$' "$scriptname" &&
|
---|
556 | "$scriptname" setup
|
---|
557 | return 0
|
---|
558 | }
|
---|
559 |
|
---|
560 | # Do pre-removal cleanup of an installed service
|
---|
561 | #
|
---|
562 | # syntax: cleanup_init_script name
|
---|
563 |
|
---|
564 | cleanup_init()
|
---|
565 | {
|
---|
566 | self=cleanup_init_script
|
---|
567 | name=$1
|
---|
568 | spaces=`printf " %b" "\t"`
|
---|
569 | check_system_type
|
---|
570 | test $? -ne 1 || return 1
|
---|
571 | test ! -z "$name" || \
|
---|
572 | { log "$self: missing argument" && return 1; }
|
---|
573 | if [ "$ro_INIT_TYPE" = "sysv" ]; then
|
---|
574 | scriptname="/etc/init.d/$name"
|
---|
575 | elif [ "$ro_INIT_TYPE" = "bsd" ]; then
|
---|
576 | scriptname="/etc/rc.d/rc.$name"
|
---|
577 | elif [ "$ro_INIT_TYPE" = "lfs" ]; then
|
---|
578 | scriptname="/etc/rc.d/init.d/$name"
|
---|
579 | elif [ "$ro_INIT_TYPE" = "pardus" ]; then
|
---|
580 | scriptname="/usr/sbin/$name"
|
---|
581 | else
|
---|
582 | log "$self: error: unknown init type"
|
---|
583 | return 1
|
---|
584 | fi
|
---|
585 | test -r "$scriptname" &&
|
---|
586 | grep -q '^#['"$spaces"']*cleanup_script['"$spaces"']*$' "$scriptname" &&
|
---|
587 | "$scriptname" cleanup >> $ro_LOG_FILE 2>&1
|
---|
588 | delrunlevel "$name"
|
---|
589 | return 0
|
---|
590 | }
|
---|
591 |
|
---|
592 |
|
---|
593 | terminate_proc() {
|
---|
594 | PROC_NAME=$1
|
---|
595 | SERVER_PID=`pidof $PROC_NAME 2> /dev/null`
|
---|
596 | if [ "$SERVER_PID" != "" ]; then
|
---|
597 | killall -TERM $PROC_NAME > /dev/null 2>&1
|
---|
598 | sleep 2
|
---|
599 | fi
|
---|
600 | }
|
---|
601 |
|
---|
602 |
|
---|
603 | maybe_run_python_bindings_installer() {
|
---|
604 | VBOX_INSTALL_PATH=$1
|
---|
605 |
|
---|
606 | PYTHON=python
|
---|
607 | if [ ! `python -c 'print "test"' 2> /dev/null` = "test" ]; then
|
---|
608 | echo 1>&2 "Python not available, skipping bindings installation."
|
---|
609 | return 1
|
---|
610 | fi
|
---|
611 |
|
---|
612 | echo 1>&2 "Python found: $PYTHON, installing bindings..."
|
---|
613 | # Pass install path via environment
|
---|
614 | export VBOX_INSTALL_PATH
|
---|
615 | $SHELL -c "cd $VBOX_INSTALL_PATH/sdk/installer && $PYTHON vboxapisetup.py install"
|
---|
616 | # remove files created during build
|
---|
617 | rm -rf $VBOX_INSTALL_PATH/sdk/installer/build
|
---|
618 |
|
---|
619 | return 0
|
---|
620 | }
|
---|