VirtualBox

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

Last change on this file since 98262 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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