VirtualBox

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

Last change on this file since 92839 was 88501, checked in by vboxsync, 4 years ago

bugref:9907. Removed cloud-init package installation for Debian systems. The package installation on Debian systems has some conflict with unattended installation.

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