VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/routines.sh@ 69007

Last change on this file since 69007 was 69007, checked in by vboxsync, 7 years ago

Additions: missing conflict with systemd-timesyncd.service for guest service.
bugref:3809: Linux installer maintenance

This change adds "Conflicts=systemd-timesyncd.service" to the systemd unit
file for the guest service. This prevents our time synchronisation service
and the systemd time synchronisation service from running at the same time.
See Debian bug 873263.
https://bugs.debian.org/873263
Thank you Gianfranco Costamagna <locutusofborg@…>.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1# Oracle VM VirtualBox
2# VirtualBox installer shell routines
3#
4
5# Copyright (C) 2007-2015 Oracle Corporation
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 (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
16ro_LOG_FILE=""
17ro_X11_AUTOSTART="/etc/xdg/autostart"
18ro_KDE_AUTOSTART="/usr/share/autostart"
19
20## Aborts the script and prints an error message to stderr.
21#
22# syntax: abort message
23
24abort()
25{
26 echo 1>&2 "$1"
27 exit 1
28}
29
30## Creates an empty log file and remembers the name for future logging
31# operations
32create_log()
33{
34 ## The path of the file to create.
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
49info()
50{
51 echo 1>&2 "$1"
52}
53
54## Writes text to the log file
55#
56# Syntax: log text
57log()
58{
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
69infolog()
70{
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
78module_loaded()
79{
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
88check_root()
89{
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
96check_running()
97{
98 VBOXSVC_PID=`pidof VBoxSVC 2> /dev/null`
99 if [ -n "$VBOXSVC_PID" ]; then
100 if [ -f /etc/init.d/vboxweb-service ]; then
101 kill -USR1 $VBOXSVC_PID
102 fi
103 sleep 1
104 if pidof VBoxSVC > /dev/null 2>&1; then
105 echo 1>&2 "A copy of VirtualBox is currently running. Please close it and try again."
106 abort "Please note that it can take up to ten seconds for VirtualBox to finish running."
107 fi
108 fi
109}
110
111## Creates a systemd wrapper in /lib for an LSB init script
112systemd_wrap_init_script()
113{
114 self="systemd_wrap_init_script"
115 ## The init script to be installed. The file may be copied or referenced.
116 script="$(readlink -f -- "${1}")"
117 ## Name for the service.
118 name="$2"
119 test -x "$script" && test ! "$name" = "" || \
120 { echo "$self: invalid arguments" >&2 && return 1; }
121 test -d /usr/lib/systemd/system && unit_path=/usr/lib/systemd/system
122 test -d /lib/systemd/system && unit_path=/lib/systemd/system
123 test -n "${unit_path}" || \
124 { echo "$self: systemd unit path not found" >&2 && return 1; }
125 conflicts=`sed -n 's/# *X-Conflicts-With: *\(.*\)/\1/p' "${script}" | sed 's/\$[a-z]*//'`
126 description=`sed -n 's/# *Short-Description: *\(.*\)/\1/p' "${script}"`
127 required=`sed -n 's/# *Required-Start: *\(.*\)/\1/p' "${script}" | sed 's/\$[a-z]*//'`
128 startbefore=`sed -n 's/# *X-Start-Before: *\(.*\)/\1/p' "${script}" | sed 's/\$[a-z]*//'`
129 runlevels=`sed -n 's/# *Default-Start: *\(.*\)/\1/p' "${script}"`
130 servicetype=`sed -n 's/# *X-Service-Type: *\(.*\)/\1/p' "${script}"`
131 test -z "${servicetype}" && servicetype="forking"
132 targets=`for i in ${runlevels}; do printf "runlevel${i}.target "; done`
133 before=`for i in ${startbefore}; do printf "${i}.service "; done`
134 after=`for i in ${required}; do printf "${i}.service "; done`
135 cat > "${unit_path}/${name}.service" << EOF
136[Unit]
137SourcePath=${script}
138Description=${description}
139Before=${targets}shutdown.target ${before}
140After=${after}
141Conflicts=shutdown.target ${conflicts}
142
143[Service]
144Type=${servicetype}
145Restart=no
146TimeoutSec=5min
147IgnoreSIGPIPE=no
148KillMode=process
149GuessMainPID=no
150RemainAfterExit=yes
151ExecStart=${script} start
152ExecStop=${script} stop
153
154[Install]
155WantedBy=multi-user.target
156EOF
157 systemctl daemon-reexec
158}
159
160## Installs a file containing a shell script as an init script
161install_init_script()
162{
163 self="install_init_script"
164 ## The init script to be installed. The file may be copied or referenced.
165 script="$1"
166 ## Name for the service.
167 name="$2"
168
169 test -x "${script}" && test ! "${name}" = "" ||
170 { echo "${self}: invalid arguments" >&2; return 1; }
171 # Do not unconditionally silence the following "ln".
172 test -L "/sbin/rc${name}" && rm "/sbin/rc${name}"
173 ln -s "${script}" "/sbin/rc${name}"
174 if test -x "`which systemctl 2>/dev/null`"; then
175 if ! test -f /sbin/init || ls -l /sbin/init | grep -q ">.*systemd"; then
176 { systemd_wrap_init_script "$script" "$name"; return; }
177 fi
178 fi
179 if test -d /etc/rc.d/init.d; then
180 cp "${script}" "/etc/rc.d/init.d/${name}" &&
181 chmod 755 "/etc/rc.d/init.d/${name}"
182 elif test -d /etc/init.d; then
183 cp "${script}" "/etc/init.d/${name}" &&
184 chmod 755 "/etc/init.d/${name}"
185 else
186 { echo "${self}: error: unknown init type" >&2; return 1; }
187 fi
188}
189
190## Remove the init script "name"
191remove_init_script()
192{
193 self="remove_init_script"
194 ## Name of the service to remove.
195 name="$1"
196
197 test -n "${name}" ||
198 { echo "$self: missing argument"; return 1; }
199 rm -f "/sbin/rc${name}"
200 rm -f /lib/systemd/system/"$name".service /usr/lib/systemd/system/"$name".service
201 rm -f "/etc/rc.d/init.d/$name"
202 rm -f "/etc/init.d/$name"
203}
204
205## Did we install a systemd service?
206systemd_service_installed()
207{
208 ## Name of service to test.
209 name="${1}"
210
211 test -f /lib/systemd/system/"${name}".service ||
212 test -f /usr/lib/systemd/system/"${name}".service
213}
214
215## Perform an action on a service
216do_sysvinit_action()
217{
218 self="do_sysvinit_action"
219 ## Name of service to start.
220 name="${1}"
221 ## The action to perform, normally "start", "stop" or "status".
222 action="${2}"
223
224 test ! -z "${name}" && test ! -z "${action}" ||
225 { echo "${self}: missing argument" >&2; return 1; }
226 if systemd_service_installed "${name}"; then
227 systemctl -q ${action} "${name}"
228 elif test -x "/etc/rc.d/init.d/${name}"; then
229 "/etc/rc.d/init.d/${name}" "${action}" quiet
230 elif test -x "/etc/init.d/${name}"; then
231 "/etc/init.d/${name}" "${action}" quiet
232 fi
233}
234
235## Start a service
236start_init_script()
237{
238 do_sysvinit_action "${1}" start
239}
240
241## Stop the init script "name"
242stop_init_script()
243{
244 do_sysvinit_action "${1}" stop
245}
246
247## Extract chkconfig information from a sysvinit script.
248get_chkconfig_info()
249{
250 ## The script to extract the information from.
251 script="${1}"
252
253 set `sed -n 's/# *chkconfig: *\([0-9]*\) *\(.*\)/\1 \2/p' "${script}"`
254 ## Which runlevels should we start in?
255 runlevels="${1}"
256 ## How soon in the boot process will we start, from 00 (first) to 99
257 start_order="${2}"
258 ## How soon in the shutdown process will we stop, from 99 (first) to 00
259 stop_order="${3}"
260 test ! -z "${name}" || \
261 { echo "${self}: missing name" >&2; return 1; }
262 expr "${start_order}" + 0 > /dev/null 2>&1 && \
263 expr 0 \<= "${start_order}" > /dev/null 2>&1 && \
264 test `expr length "${start_order}"` -eq 2 > /dev/null 2>&1 || \
265 { echo "${self}: start sequence number must be between 00 and 99" >&2;
266 return 1; }
267 expr "${stop_order}" + 0 > /dev/null 2>&1 && \
268 expr 0 \<= "${stop_order}" > /dev/null 2>&1 && \
269 test `expr length "${stop_order}"` -eq 2 > /dev/null 2>&1 || \
270 { echo "${self}: stop sequence number must be between 00 and 99" >&2;
271 return 1; }
272}
273
274## Add a service to its default runlevels (annotated inside the script, see get_chkconfig_info).
275addrunlevel()
276{
277 self="addrunlevel"
278 ## Service name.
279 name="${1}"
280
281 test -n "${name}" || \
282 { echo "${self}: missing argument" >&2; return 1; }
283 systemd_service_installed "${name}" && \
284 { systemctl -q enable "${name}"; return; }
285 if test -x "/etc/rc.d/init.d/${name}"; then
286 init_d_path=/etc/rc.d
287 elif test -x "/etc/init.d/${name}"; then
288 init_d_path=/etc
289 else
290 { echo "${self}: error: unknown init type" >&2; return 1; }
291 fi
292 get_chkconfig_info "${init_d_path}/init.d/${name}" || return 1
293 # Redhat based sysvinit systems
294 if test -x "`which chkconfig 2>/dev/null`"; then
295 chkconfig --add "${name}"
296 # SUSE-based sysvinit systems
297 elif test -x "`which insserv 2>/dev/null`"; then
298 insserv "${name}"
299 # Debian/Ubuntu-based systems
300 elif test -x "`which update-rc.d 2>/dev/null`"; then
301 # Old Debians did not support dependencies
302 update-rc.d "${name}" defaults "${start_order}" "${stop_order}"
303 # Gentoo Linux
304 elif test -x "`which rc-update 2>/dev/null`"; then
305 rc-update add "${name}" default
306 # Generic sysvinit
307 elif test -n "${init_d_path}/rc0.d"
308 then
309 for locali in 0 1 2 3 4 5 6
310 do
311 target="${init_d_path}/rc${locali}.d/K${stop_order}${name}"
312 expr "${runlevels}" : ".*${locali}" >/dev/null && \
313 target="${init_d_path}/rc${locali}.d/S${start_order}${name}"
314 test -e "${init_d_path}/rc${locali}.d/"[KS][0-9]*"${name}" || \
315 ln -fs "${init_d_path}/init.d/${name}" "${target}"
316 done
317 else
318 { echo "${self}: error: unknown init type" >&2; return 1; }
319 fi
320}
321
322
323## Delete a service from a runlevel
324delrunlevel()
325{
326 self="delrunlevel"
327 ## Service name.
328 name="${1}"
329
330 test -n "${name}" ||
331 { echo "${self}: missing argument" >&2; return 1; }
332 systemctl -q disable "${name}" >/dev/null 2>&1
333 # Redhat-based systems
334 chkconfig --del "${name}" >/dev/null 2>&1
335 # SUSE-based sysvinit systems
336 insserv -r "${name}" >/dev/null 2>&1
337 # Debian/Ubuntu-based systems
338 update-rc.d -f "${name}" remove >/dev/null 2>&1
339 # Gentoo Linux
340 rc-update del "${name}" >/dev/null 2>&1
341 # Generic sysvinit
342 rm -f /etc/rc.d/rc?.d/[SK]??"${name}"
343 rm -f /etc/rc?.d/[SK]??"${name}"
344}
345
346
347terminate_proc() {
348 PROC_NAME="${1}"
349 SERVER_PID=`pidof $PROC_NAME 2> /dev/null`
350 if [ "$SERVER_PID" != "" ]; then
351 killall -TERM $PROC_NAME > /dev/null 2>&1
352 sleep 2
353 fi
354}
355
356
357maybe_run_python_bindings_installer() {
358 VBOX_INSTALL_PATH="${1}"
359
360 PYTHON=python
361 if [ "`python -c 'import sys
362if sys.version_info >= (2, 6):
363 print \"test\"' 2> /dev/null`" != "test" ]; then
364 echo 1>&2 "Python 2.6 or later not available, skipping bindings installation."
365 return 1
366 fi
367
368 echo 1>&2 "Python found: $PYTHON, installing bindings..."
369 # Pass install path via environment
370 export VBOX_INSTALL_PATH
371 $SHELL -c "cd $VBOX_INSTALL_PATH/sdk/installer && $PYTHON vboxapisetup.py install \
372 --record $CONFIG_DIR/python-$CONFIG_FILES"
373 cat $CONFIG_DIR/python-$CONFIG_FILES >> $CONFIG_DIR/$CONFIG_FILES
374 rm $CONFIG_DIR/python-$CONFIG_FILES
375 # remove files created during build
376 rm -rf $VBOX_INSTALL_PATH/sdk/installer/build
377
378 return 0
379}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette