VirtualBox

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

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

Unattended/*postinstall.sh: new validation kit location (linux)

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 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 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
110#
111# Log header.
112#
113echo "******************************************************************************" >> "${MY_LOGFILE}"
114echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
115echo "** Date: `date -R`" >> "${MY_LOGFILE}"
116echo "** Started: $0 $*" >> "${MY_LOGFILE}"
117
118
119#
120# Setup the target jail ourselves since in-target steals all the output.
121#
122if [ -f /lib/chroot-setup.sh ]; then
123 MY_HAVE_CHROOT_SETUP="yes"
124 . /lib/chroot-setup.sh
125 if chroot_setup; then
126 echo "** chroot_setup: done" | tee -a "${MY_LOGFILE}"
127 else
128 echo "** chroot_setup: failed $?" | tee -a "${MY_LOGFILE}"
129 fi
130else
131 MY_HAVE_CHROOT_SETUP=""
132fi
133
134
135#
136# We want the ISO available inside the target jail.
137#
138if [ -d "${MY_TARGET}${MY_CHROOT_CDROM}" ]; then
139 MY_RMDIR_TARGET_CDROM=
140else
141 MY_RMDIR_TARGET_CDROM="yes"
142 log_command mkdir -p ${MY_TARGET}${MY_CHROOT_CDROM}
143fi
144
145if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
146 MY_UNMOUNT_TARGET_CDROM=
147 echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
148else
149 MY_UNMOUNT_TARGET_CDROM="yes"
150 log_command mount -o bind "${MY_CDROM_NOCHROOT}" "${MY_TARGET}${MY_CHROOT_CDROM}"
151 if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
152 echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
153 else
154 echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
155 fi
156 if [ "${MY_DEBUG}" = "yes" ]; then
157 log_command find "${MY_TARGET}${MY_CHROOT_CDROM}"
158 fi
159fi
160
161
162#
163# Debug
164#
165if [ "${MY_DEBUG}" = "yes" ]; then
166 log_command id
167 log_command ps
168 log_command ps auxwwwf
169 log_command env
170 log_command df
171 log_command mount
172 log_command_in_target df
173 log_command_in_target mount
174 #log_command find /
175 MY_EXITCODE=0
176fi
177
178
179#
180# Packages needed for GAs.
181#
182echo "--------------------------------------------------" >> "${MY_LOGFILE}"
183echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
184log_command_in_target apt-get -y install build-essential
185log_command_in_target apt-get -y install linux-headers-$(uname -r)
186
187
188#
189# GAs
190#
191@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
192echo "--------------------------------------------------" >> "${MY_LOGFILE}"
193echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
194MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
195log_command_in_target /bin/bash "${MY_CHROOT_CDROM}/vboxadditions/VBoxLinuxAdditions.run" --nox11
196MY_IGNORE_EXITCODE=
197log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
198@@VBOX_COND_END@@
199
200
201#
202# Test Execution Service.
203#
204@@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
205echo "--------------------------------------------------" >> "${MY_LOGFILE}"
206echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
207log_command_in_target test "${MY_CHROOT_CDROM}/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
208log_command mkdir -p "${MY_TARGET}/opt/validationkit" "${MY_TARGET}/media/cdrom"
209log_command cp -R ${MY_CDROM_NOCHROOT}/vboxvalidationkit/* "${MY_TARGET}/opt/validationkit/"
210log_command chmod -R u+rw,a+xr "${MY_TARGET}/opt/validationkit/"
211if [ -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
212 MY_IGNORE_EXITCODE=1
213 log_command_in_target chcon -R -t usr_t "/opt/validationkit/"
214 MY_IGNORE_EXITCODE=
215fi
216
217# systemd service config:
218MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
219test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
220if [ -d "${MY_UNIT_PATH}" ]; then
221 log_command cp "${MY_TARGET}/opt/validationkit/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
222 log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
223 log_command_in_target systemctl -q enable vboxtxs
224
225# Not systemd: Add support for upstart later...
226else
227 echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
228fi
229
230@@VBOX_COND_END@@
231
232
233#
234# Run user command.
235#
236@@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
237echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
238log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
239@@VBOX_COND_END@@
240
241
242#
243# Unmount the cdrom if we bound it and clean up the chroot if we set it up.
244#
245if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
246 echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
247 log_command umount "${MY_TARGET}${MY_CHROOT_CDROM}"
248fi
249
250if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
251 log_command rmdir "${MY_TARGET}${MY_CHROOT_CDROM}"
252fi
253
254if [ -n "${MY_HAVE_CHROOT_SETUP}" ]; then
255 if chroot_cleanup; then
256 echo "** chroot_cleanup: done" | tee -a "${MY_LOGFILE}"
257 else
258 echo "** chroot_cleanup: failed $?" | tee -a "${MY_LOGFILE}"
259 fi
260fi
261
262
263#
264# Log footer.
265#
266echo "******************************************************************************" >> "${MY_LOGFILE}"
267echo "** Date: `date -R`" >> "${MY_LOGFILE}"
268echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
269echo "******************************************************************************" >> "${MY_LOGFILE}"
270
271exit ${MY_EXITCODE}
272
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