VirtualBox

source: vbox/trunk/src/VBox/Main/UnattendedTemplates/debian_postinstall.sh@ 81916

Last change on this file since 81916 was 79469, checked in by vboxsync, 5 years ago

Main/UnattendedTemplates: Kick udev after GA installation as the installer doesn't seem to do that at the moment. bugref:9151

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1#!/bin/bash
2## @file
3# Post installation script template for debian-like distros.
4#
5# Note! This script expects to be running w/o chroot.
6# Note! When using ubiquity, this is run after installation logs have
7# been copied to /var/log/installation.
8#
9
10#
11# Copyright (C) 2017-2019 Oracle Corporation
12#
13# This file is part of VirtualBox Open Source Edition (OSE), as
14# available from http://www.virtualbox.org. This file is free software;
15# you can redistribute it and/or modify it under the terms of the GNU
16# General Public License (GPL) as published by the Free Software
17# Foundation, in version 2 as it comes in the "COPYING" file of the
18# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20#
21
22
23#
24# Globals.
25#
26MY_TARGET="/target"
27MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
28MY_CHROOT_CDROM="/cdrom"
29MY_CDROM_NOCHROOT="/cdrom"
30MY_EXITCODE=0
31MY_DEBUG="" # "yes"
32
33
34#
35# Do we need to exec using target bash? If so, we must do that early
36# or ash will bark 'bad substitution' and fail.
37#
38if [ "$1" = "--need-target-bash" ]; then
39 # Try figure out which directories we might need in the library path.
40 if [ -z "${LD_LIBRARY_PATH}" ]; then
41 LD_LIBRARY_PATH="${MY_TARGET}/lib"
42 fi
43 for x in \
44 ${MY_TARGET}/lib \
45 ${MY_TARGET}/usr/lib \
46 ${MY_TARGET}/lib/*linux-gnu/ \
47 ${MY_TARGET}/lib32/ \
48 ${MY_TARGET}/lib64/ \
49 ${MY_TARGET}/usr/lib/*linux-gnu/ \
50 ${MY_TARGET}/usr/lib32/ \
51 ${MY_TARGET}/usr/lib64/ \
52 ;
53 do
54 if [ -e "$x" ]; then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${x}"; fi;
55 done
56 export LD_LIBRARY_PATH
57
58 # Append target bin directories to the PATH as busybox may not have tee.
59 PATH="${PATH}:${MY_TARGET}/bin:${MY_TARGET}/usr/bin:${MY_TARGET}/sbin:${MY_TARGET}/usr/sbin"
60 export PATH
61
62 # Drop the --need-target-bash argument and re-exec.
63 shift
64 echo "******************************************************************************" >> "${MY_LOGFILE}"
65 echo "** Relaunching using ${MY_TARGET}/bin/bash $0 $*" >> "${MY_LOGFILE}"
66 echo "** LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> "${MY_LOGFILE}"
67 echo "** PATH=${PATH}" >> "${MY_LOGFILE}"
68 exec "${MY_TARGET}/bin/bash" "$0" "$@"
69fi
70
71
72#
73# Commands.
74#
75
76# Logs execution of a command.
77log_command()
78{
79 echo "--------------------------------------------------" >> "${MY_LOGFILE}"
80 echo "** Date: `date -R`" >> "${MY_LOGFILE}"
81 echo "** Executing: $*" >> "${MY_LOGFILE}"
82 "$@" 2>&1 | tee -a "${MY_LOGFILE}"
83 MY_TMP_EXITCODE="${PIPESTATUS[0]}"
84 if [ "${MY_TMP_EXITCODE}" != "0" ]; then
85 if [ "${MY_TMP_EXITCODE}" != "${MY_IGNORE_EXITCODE}" ]; then
86 echo "** exit code: ${MY_TMP_EXITCODE}" | tee -a "${MY_LOGFILE}"
87 MY_EXITCODE=1;
88 else
89 echo "** exit code: ${MY_TMP_EXITCODE} (ignored)" | tee -a "${MY_LOGFILE}"
90 fi
91 fi
92}
93
94# Logs execution of a command inside the target.
95log_command_in_target()
96{
97 #
98 # We should be using in-target here, however we don't get any stderr output
99 # from it because of log-output. We can get stdout by --pass-stdout, but
100 # that's not helpful for failures.
101 #
102 # So, we try do the chroot prepping that in-target does at the start of the
103 # script (see below) and just use chroot here.
104 #
105 log_command chroot "${MY_TARGET}" "$@"
106 # log_command in-target --pass-stdout "$@" # No stderr output... :-(
107}
108
109# Checks if $1 is a command on the PATH inside the target jail.
110chroot_which()
111{
112 for dir in /bin /usr/bin /sbin /usr/sbin;
113 do
114 if [ -x "${MY_TARGET}${dir}/$1" ]; then
115 return 0;
116 fi
117 done
118 return 1;
119}
120
121#
122# Log header.
123#
124echo "******************************************************************************" >> "${MY_LOGFILE}"
125echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
126echo "** Date: `date -R`" >> "${MY_LOGFILE}"
127echo "** Started: $0 $*" >> "${MY_LOGFILE}"
128
129
130#
131# Setup the target jail ourselves since in-target steals all the output.
132#
133if [ -f /lib/chroot-setup.sh ]; then
134 MY_HAVE_CHROOT_SETUP="yes"
135 . /lib/chroot-setup.sh
136 if chroot_setup; then
137 echo "** chroot_setup: done" | tee -a "${MY_LOGFILE}"
138 else
139 echo "** chroot_setup: failed $?" | tee -a "${MY_LOGFILE}"
140 fi
141else
142 MY_HAVE_CHROOT_SETUP=""
143fi
144
145
146#
147# We want the ISO available inside the target jail.
148#
149if [ -d "${MY_TARGET}${MY_CHROOT_CDROM}" ]; then
150 MY_RMDIR_TARGET_CDROM=
151else
152 MY_RMDIR_TARGET_CDROM="yes"
153 log_command mkdir -p ${MY_TARGET}${MY_CHROOT_CDROM}
154fi
155
156if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
157 MY_UNMOUNT_TARGET_CDROM=
158 echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
159else
160 MY_UNMOUNT_TARGET_CDROM="yes"
161 log_command mount -o bind "${MY_CDROM_NOCHROOT}" "${MY_TARGET}${MY_CHROOT_CDROM}"
162 if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
163 echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
164 else
165 echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
166 fi
167 if [ "${MY_DEBUG}" = "yes" ]; then
168 log_command find "${MY_TARGET}${MY_CHROOT_CDROM}"
169 fi
170fi
171
172
173#
174# Debug
175#
176if [ "${MY_DEBUG}" = "yes" ]; then
177 log_command id
178 log_command ps
179 log_command ps auxwwwf
180 log_command env
181 log_command df
182 log_command mount
183 log_command_in_target df
184 log_command_in_target mount
185 #log_command find /
186 MY_EXITCODE=0
187fi
188
189
190#
191# Packages needed for GAs.
192#
193echo "--------------------------------------------------" >> "${MY_LOGFILE}"
194echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
195log_command_in_target apt-get -y install build-essential
196log_command_in_target apt-get -y install linux-headers-$(uname -r)
197
198
199#
200# GAs
201#
202@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
203echo "--------------------------------------------------" >> "${MY_LOGFILE}"
204echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
205MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
206log_command_in_target /bin/bash "${MY_CHROOT_CDROM}/vboxadditions/VBoxLinuxAdditions.run" --nox11
207log_command_in_target /bin/bash -c "udevadm constrol --reload-rules" # GAs doesn't yet do this.
208log_command_in_target /bin/bash -c "udevadm trigger" # (ditto)
209MY_IGNORE_EXITCODE=
210log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
211@@VBOX_COND_END@@
212
213
214#
215# Test Execution Service.
216#
217@@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
218echo "--------------------------------------------------" >> "${MY_LOGFILE}"
219echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
220log_command_in_target test "${MY_CHROOT_CDROM}/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
221log_command mkdir -p "${MY_TARGET}/opt/validationkit" "${MY_TARGET}/media/cdrom"
222log_command cp -R ${MY_CDROM_NOCHROOT}/vboxvalidationkit/* "${MY_TARGET}/opt/validationkit/"
223log_command chmod -R u+rw,a+xr "${MY_TARGET}/opt/validationkit/"
224if [ -e "${MY_TARGET}/usr/bin/chcon" -o -e "${MY_TARGET}/bin/chcon" -o -e "${MY_TARGET}/usr/sbin/chcon" -o -e "${MY_TARGET}/sbin/chcon" ]; then
225 MY_IGNORE_EXITCODE=1
226 log_command_in_target chcon -R -t usr_t "/opt/validationkit/"
227 MY_IGNORE_EXITCODE=
228fi
229
230# systemd service config:
231MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
232test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
233if [ -d "${MY_UNIT_PATH}" ]; then
234 log_command cp "${MY_TARGET}/opt/validationkit/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
235 log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
236 log_command_in_target systemctl -q enable vboxtxs
237
238# System V like:
239elif [ -e "${MY_TARGET}/etc/init.d/" ]; then
240
241 # Install the script. On rhel6 scripts are under /etc/rc.d/ with /etc/init.d and /etc/rc?.d being symlinks.
242 if [ -d "${MY_TARGET}/etc/rc.d/init.d/" ]; then
243 MY_INIT_D_PARENT_PATH="${MY_TARGET}/etc/rc.d"
244 log_command ln -s "../../../opt/validationkit/linux/vboxtxs" "${MY_INIT_D_PARENT_PATH}/init.d/"
245 else
246 MY_INIT_D_PARENT_PATH="${MY_TARGET}/etc"
247 log_command ln -s "../../opt/validationkit/linux/vboxtxs" "${MY_INIT_D_PARENT_PATH}/init.d/"
248 fi
249
250 # Use runlevel management script if found.
251 if chroot_which chkconfig; then # Redhat based sysvinit systems
252 log_command_in_target chkconfig --add vboxtxs
253 elif chroot_which insserv; then # SUSE-based sysvinit systems
254 log_command_in_target insserv vboxtxs
255 elif chroot_which update-rc.d; then # Debian/Ubuntu-based systems
256 log_command_in_target update-rc.d vboxtxs defaults
257 elif chroot_which rc-update; then # Gentoo Linux
258 log_command_in_target rc-update add vboxtxs default
259 # Fall back on hardcoded symlinking.
260 else
261 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc0.d/K65vboxtxs"
262 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc1.d/K65vboxtxs"
263 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc6.d/K65vboxtxs"
264 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc2.d/S35vboxtxs"
265 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc3.d/S35vboxtxs"
266 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc4.d/S35vboxtxs"
267 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc5.d/S35vboxtxs"
268 fi
269else
270 echo "** error: Unknown init script system." | tee -a "${MY_LOGFILE}"
271fi
272
273@@VBOX_COND_END@@
274
275
276#
277# Run user command.
278#
279@@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
280echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
281log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
282@@VBOX_COND_END@@
283
284
285#
286# Unmount the cdrom if we bound it and clean up the chroot if we set it up.
287#
288if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
289 echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
290 log_command umount "${MY_TARGET}${MY_CHROOT_CDROM}"
291fi
292
293if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
294 log_command rmdir "${MY_TARGET}${MY_CHROOT_CDROM}"
295fi
296
297if [ -n "${MY_HAVE_CHROOT_SETUP}" ]; then
298 if chroot_cleanup; then
299 echo "** chroot_cleanup: done" | tee -a "${MY_LOGFILE}"
300 else
301 echo "** chroot_cleanup: failed $?" | tee -a "${MY_LOGFILE}"
302 fi
303fi
304
305
306#
307# Log footer.
308#
309echo "******************************************************************************" >> "${MY_LOGFILE}"
310echo "** Date: `date -R`" >> "${MY_LOGFILE}"
311echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
312echo "******************************************************************************" >> "${MY_LOGFILE}"
313
314exit ${MY_EXITCODE}
315
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