VirtualBox

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

Last change on this file since 103147 was 102982, checked in by vboxsync, 11 months ago

Main/UnattendedTemplates/debian_postinstall.sh: Don't install packages for building the guest additions if the guest additions are not going to be installed, should fix Ubuntu 23.10 unattended install if the package server is not reachable, bugref:10551

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