1 | #! /bin/bash
|
---|
2 | # InnoTek VirtualBox
|
---|
3 | # Linux Additions add/delete init script
|
---|
4 | #
|
---|
5 | # Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.virtualbox.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 as published by the Free Software Foundation,
|
---|
11 | # in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
12 | # distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
13 | # be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | #
|
---|
15 | # If you received this file as part of a commercial VirtualBox
|
---|
16 | # distribution, then only the terms of your commercial VirtualBox
|
---|
17 | # license agreement apply instead of the previous paragraph.
|
---|
18 |
|
---|
19 | runlevels=35
|
---|
20 |
|
---|
21 | system=unknown
|
---|
22 | if [ -f /etc/redhat-release ]; then
|
---|
23 | system=redhat
|
---|
24 | util=$(type -p /sbin/chkconfig)
|
---|
25 | elif [ -f /etc/SuSE-release ]; then
|
---|
26 | system=suse
|
---|
27 | util=$(type -p /sbin/chkconfig)
|
---|
28 | elif [ -f /etc/debian_version ]; then
|
---|
29 | system=debian
|
---|
30 | util=$(type -p update-rc.d)
|
---|
31 | elif [ -f /etc/gentoo-release ]; then
|
---|
32 | system=gentoo
|
---|
33 | util=$(type -p rc-update)
|
---|
34 | else
|
---|
35 | echo "$0: Unknown system" 1>&2
|
---|
36 | fi
|
---|
37 |
|
---|
38 | if [ -z $util ];then
|
---|
39 | echo Could not find add/remove init scripts to a runlevel utility 1>&2
|
---|
40 | echo This operation can not continue without it 1>&2
|
---|
41 | exit 1
|
---|
42 | fi
|
---|
43 |
|
---|
44 | fail() {
|
---|
45 | echo "$1"
|
---|
46 | exit 1
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | addrunlevel() {
|
---|
51 | if [ $system == "redhat" ] || [ $system == "suse" ]; then
|
---|
52 | $util --del $1 >&/dev/null
|
---|
53 |
|
---|
54 | if $util -v &>/dev/null; then
|
---|
55 | $util --level $runlevels $1 on || {
|
---|
56 | fail "Cannot add $1 to run levels: $runlevels"
|
---|
57 | }
|
---|
58 | else
|
---|
59 | $util $1 $runlevels || {
|
---|
60 | fail "Cannot add $1 to run levels: $runlevels"
|
---|
61 | }
|
---|
62 | fi
|
---|
63 | elif [ $system == "debian" ]; then
|
---|
64 | # Debian does not support dependencies currently -- use argument $2
|
---|
65 | # for start sequence number and argument $3 for stop sequence number
|
---|
66 | $util -f $1 remove >&/dev/null
|
---|
67 | $util $1 defaults $2 $3 >&/dev/null
|
---|
68 | elif [ $system == "gentoo" ]; then
|
---|
69 | $util del $1 >&/dev/null
|
---|
70 | $util add $1 default >&/dev/null
|
---|
71 | fi
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | delrunlevel() {
|
---|
76 | if [ $system == "redhat" ] || [ $system == "suse" ]; then
|
---|
77 | if $util --list $1 >& /dev/null; then
|
---|
78 | $util --del $1 >& /dev/null || {
|
---|
79 | fail "Cannot delete $1 from runlevels"
|
---|
80 | }
|
---|
81 | fi
|
---|
82 | elif [ $system == "debian" ]; then
|
---|
83 | $util -f $1 remove >&/dev/null
|
---|
84 | elif [ $system == "gentoo" ]; then
|
---|
85 | $util del $1 >&/dev/null
|
---|
86 | fi
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | usage() {
|
---|
91 | echo "Usage: $0 {add|del} script"
|
---|
92 | exit 1
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | # Test for second argument
|
---|
97 | test -z $2 && {
|
---|
98 | usage
|
---|
99 | }
|
---|
100 |
|
---|
101 | case "$1" in
|
---|
102 | add)
|
---|
103 | addrunlevel $2 $3 $4
|
---|
104 | ;;
|
---|
105 | del)
|
---|
106 | delrunlevel $2
|
---|
107 | ;;
|
---|
108 | *)
|
---|
109 | usage
|
---|
110 | esac
|
---|
111 |
|
---|
112 | exit
|
---|