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.alldomusa.eu.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 | #
|
---|
26 | MY_TARGET="/target"
|
---|
27 | MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
|
---|
28 | MY_EXITCODE=0
|
---|
29 | MY_DEBUG="" # "yes"
|
---|
30 |
|
---|
31 |
|
---|
32 | #
|
---|
33 | # Do we need to exec using target bash? If so, we must do that early
|
---|
34 | # or ash will bark 'bad substitution' and fail.
|
---|
35 | #
|
---|
36 | if [ "$1" = "--need-target-bash" ]; then
|
---|
37 | # Try figure out which directories we might need in the library path.
|
---|
38 | if [ -z "${LD_LIBRARY_PATH}" ]; then
|
---|
39 | LD_LIBRARY_PATH="${MY_TARGET}/lib"
|
---|
40 | fi
|
---|
41 | for x in \
|
---|
42 | ${MY_TARGET}/lib \
|
---|
43 | ${MY_TARGET}/usr/lib \
|
---|
44 | ${MY_TARGET}/lib/*linux-gnu/ \
|
---|
45 | ${MY_TARGET}/lib32/ \
|
---|
46 | ${MY_TARGET}/lib64/ \
|
---|
47 | ${MY_TARGET}/usr/lib/*linux-gnu/ \
|
---|
48 | ${MY_TARGET}/usr/lib32/ \
|
---|
49 | ${MY_TARGET}/usr/lib64/ \
|
---|
50 | ;
|
---|
51 | do
|
---|
52 | if [ -e "$x" ]; then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${x}"; fi;
|
---|
53 | done
|
---|
54 | export LD_LIBRARY_PATH
|
---|
55 |
|
---|
56 | # Append target bin directories to the PATH as busybox may not have tee.
|
---|
57 | PATH="${PATH}:${MY_TARGET}/bin:${MY_TARGET}/usr/bin:${MY_TARGET}/sbin:${MY_TARGET}/usr/sbin"
|
---|
58 | export PATH
|
---|
59 |
|
---|
60 | # Drop the --need-target-bash argument and re-exec.
|
---|
61 | shift
|
---|
62 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
63 | echo "** Relaunching using ${MY_TARGET}/bin/bash $0 $*" >> "${MY_LOGFILE}"
|
---|
64 | echo "** LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> "${MY_LOGFILE}"
|
---|
65 | echo "** PATH=${PATH}" >> "${MY_LOGFILE}"
|
---|
66 | exec "${MY_TARGET}/bin/bash" "$0" "$@"
|
---|
67 | fi
|
---|
68 |
|
---|
69 |
|
---|
70 | #
|
---|
71 | # Commands.
|
---|
72 | #
|
---|
73 |
|
---|
74 | # Logs execution of a command.
|
---|
75 | log_command()
|
---|
76 | {
|
---|
77 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
78 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
79 | echo "** Executing: $*" >> "${MY_LOGFILE}"
|
---|
80 | "$@" 2>&1 | tee -a "${MY_LOGFILE}"
|
---|
81 | MY_TMP_EXITCODE="${PIPESTATUS[0]}"
|
---|
82 | if [ "${MY_TMP_EXITCODE}" != "0" ]; then
|
---|
83 | if [ "${MY_TMP_EXITCODE}" != "${MY_IGNORE_EXITCODE}" ]; then
|
---|
84 | echo "** exit code: ${MY_TMP_EXITCODE}" | tee -a "${MY_LOGFILE}"
|
---|
85 | MY_EXITCODE=1;
|
---|
86 | else
|
---|
87 | echo "** exit code: ${MY_TMP_EXITCODE} (ignored)" | tee -a "${MY_LOGFILE}"
|
---|
88 | fi
|
---|
89 | fi
|
---|
90 | }
|
---|
91 |
|
---|
92 | # Logs execution of a command inside the target.
|
---|
93 | log_command_in_target()
|
---|
94 | {
|
---|
95 | #
|
---|
96 | # We should be using in-target here, however we don't get any stderr output
|
---|
97 | # from it because of log-output. We can get stdout by --pass-stdout, but
|
---|
98 | # that's not helpful for failures.
|
---|
99 | #
|
---|
100 | # So, we try do the chroot prepping that in-target does at the start of the
|
---|
101 | # script (see below) and just use chroot here.
|
---|
102 | #
|
---|
103 | log_command chroot "${MY_TARGET}" "$@"
|
---|
104 | # log_command in-target --pass-stdout "$@" # No stderr output... :-(
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | #
|
---|
109 | # Log header.
|
---|
110 | #
|
---|
111 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
112 | echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
|
---|
113 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
114 | echo "** Started: $0 $*" >> "${MY_LOGFILE}"
|
---|
115 |
|
---|
116 |
|
---|
117 | #
|
---|
118 | # Setup the target jail ourselves since in-target steals all the output.
|
---|
119 | #
|
---|
120 | if [ -f /lib/chroot-setup.sh ]; then
|
---|
121 | MY_HAVE_CHROOT_SETUP="yes"
|
---|
122 | . /lib/chroot-setup.sh
|
---|
123 | if chroot_setup; then
|
---|
124 | echo "** chroot_setup: done" | tee -a "${MY_LOGFILE}"
|
---|
125 | else
|
---|
126 | echo "** chroot_setup: failed $?" | tee -a "${MY_LOGFILE}"
|
---|
127 | fi
|
---|
128 | else
|
---|
129 | MY_HAVE_CHROOT_SETUP=""
|
---|
130 | fi
|
---|
131 |
|
---|
132 |
|
---|
133 | #
|
---|
134 | # We want the ISO available inside the target jail.
|
---|
135 | #
|
---|
136 | if [ -d "${MY_TARGET}/cdrom" ]; then
|
---|
137 | MY_RMDIR_TARGET_CDROM=
|
---|
138 | else
|
---|
139 | MY_RMDIR_TARGET_CDROM="yes"
|
---|
140 | log_command mkdir -p ${MY_TARGET}/cdrom
|
---|
141 | fi
|
---|
142 |
|
---|
143 | if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
|
---|
144 | MY_UNMOUNT_TARGET_CDROM=
|
---|
145 | echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
|
---|
146 | else
|
---|
147 | MY_UNMOUNT_TARGET_CDROM="yes"
|
---|
148 | log_command mount -o bind /cdrom "${MY_TARGET}/cdrom"
|
---|
149 | if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
|
---|
150 | echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
|
---|
151 | else
|
---|
152 | echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
|
---|
153 | fi
|
---|
154 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
155 | log_command find "${MY_TARGET}/cdrom"
|
---|
156 | fi
|
---|
157 | fi
|
---|
158 |
|
---|
159 |
|
---|
160 | #
|
---|
161 | # Debug
|
---|
162 | #
|
---|
163 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
164 | log_command id
|
---|
165 | log_command ps
|
---|
166 | log_command ps auxwwwf
|
---|
167 | log_command env
|
---|
168 | log_command df
|
---|
169 | log_command mount
|
---|
170 | log_command_in_target df
|
---|
171 | log_command_in_target mount
|
---|
172 | #log_command find /
|
---|
173 | MY_EXITCODE=0
|
---|
174 | fi
|
---|
175 |
|
---|
176 |
|
---|
177 | #
|
---|
178 | # Packages needed for GAs.
|
---|
179 | #
|
---|
180 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
181 | echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
|
---|
182 | log_command_in_target apt-get -y install build-essential
|
---|
183 | log_command_in_target apt-get -y install linux-headers-$(uname -r)
|
---|
184 |
|
---|
185 |
|
---|
186 | #
|
---|
187 | # GAs
|
---|
188 | #
|
---|
189 | @@VBOX_COND_IS_INSTALLING_ADDITIONS@@
|
---|
190 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
191 | echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
|
---|
192 | MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
|
---|
193 | log_command_in_target /bin/bash /cdrom/vboxadditions/VBoxLinuxAdditions.run --nox11
|
---|
194 | MY_IGNORE_EXITCODE=
|
---|
195 | log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
|
---|
196 | @@VBOX_COND_END@@
|
---|
197 |
|
---|
198 |
|
---|
199 | #
|
---|
200 | # Test Execution Service.
|
---|
201 | #
|
---|
202 | @@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
|
---|
203 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
204 | echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
|
---|
205 | log_command_in_target test "/cdrom/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
|
---|
206 | log_command mkdir -p "${MY_TARGET}/root/validationkit" "${MY_TARGET}/target/cdrom"
|
---|
207 | log_command cp -R /cdrom/vboxvalidationkit/* "${MY_TARGET}/root/validationkit/"
|
---|
208 | log_command chmod -R u+rw,a+xr "${MY_TARGET}/root/validationkit/"
|
---|
209 |
|
---|
210 | # systemd service config:
|
---|
211 | MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
|
---|
212 | test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
|
---|
213 | if [ -d "${MY_UNIT_PATH}" ]; then
|
---|
214 | log_command cp "${MY_TARGET}/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
|
---|
215 | log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
|
---|
216 | log_command_in_target systemctl -q enable vboxtxs
|
---|
217 |
|
---|
218 | # Not systemd: Add support for upstart later...
|
---|
219 | else
|
---|
220 | echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
|
---|
221 | fi
|
---|
222 |
|
---|
223 | @@VBOX_COND_END@@
|
---|
224 |
|
---|
225 |
|
---|
226 | #
|
---|
227 | # Run user command.
|
---|
228 | #
|
---|
229 | @@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
|
---|
230 | echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
|
---|
231 | log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
|
---|
232 | @@VBOX_COND_END@@
|
---|
233 |
|
---|
234 |
|
---|
235 | #
|
---|
236 | # Unmount the cdrom if we bound it and clean up the chroot if we set it up.
|
---|
237 | #
|
---|
238 | if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
|
---|
239 | echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
|
---|
240 | log_command umount "${MY_TARGET}/cdrom"
|
---|
241 | fi
|
---|
242 |
|
---|
243 | if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
|
---|
244 | log_command rmdir "${MY_TARGET}/cdrom"
|
---|
245 | fi
|
---|
246 |
|
---|
247 | if [ -n "${MY_HAVE_CHROOT_SETUP}" ]; then
|
---|
248 | if chroot_cleanup; then
|
---|
249 | echo "** chroot_cleanup: done" | tee -a "${MY_LOGFILE}"
|
---|
250 | else
|
---|
251 | echo "** chroot_cleanup: failed $?" | tee -a "${MY_LOGFILE}"
|
---|
252 | fi
|
---|
253 | fi
|
---|
254 |
|
---|
255 |
|
---|
256 | #
|
---|
257 | # Log footer.
|
---|
258 | #
|
---|
259 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
260 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
261 | echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
|
---|
262 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
263 |
|
---|
264 | exit ${MY_EXITCODE}
|
---|
265 |
|
---|