1 | #!/bin/bash
|
---|
2 | ## @file
|
---|
3 | # Post installation script template for redhat- distros.
|
---|
4 | #
|
---|
5 | # Note! This script expects to be running chrooted (inside new sytem).
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2017 Oracle Corporation
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | # available from http://www.virtualbox.org. This file is free software;
|
---|
13 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | # General Public License (GPL) as published by the Free Software
|
---|
15 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | #
|
---|
19 |
|
---|
20 |
|
---|
21 | #
|
---|
22 | # Globals.
|
---|
23 | #
|
---|
24 | MY_TARGET="/mnt/sysimage"
|
---|
25 | MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
|
---|
26 | MY_CHROOT_CDROM="/cdrom"
|
---|
27 | MY_CDROM_NOCHROOT="/run/install/repo"
|
---|
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 | log_command chroot "${MY_TARGET}" "$@"
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | #
|
---|
100 | # Log header.
|
---|
101 | #
|
---|
102 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
103 | echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
|
---|
104 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
105 | echo "** Started: $0 $*" >> "${MY_LOGFILE}"
|
---|
106 |
|
---|
107 |
|
---|
108 | #
|
---|
109 | # We want the ISO available inside the target jail.
|
---|
110 | #
|
---|
111 | if [ -d "${MY_TARGET}${MY_CHROOT_CDROM}" ]; then
|
---|
112 | MY_RMDIR_TARGET_CDROM=
|
---|
113 | else
|
---|
114 | MY_RMDIR_TARGET_CDROM="yes"
|
---|
115 | log_command mkdir -p ${MY_TARGET}${MY_CHROOT_CDROM}
|
---|
116 | fi
|
---|
117 |
|
---|
118 | if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
|
---|
119 | MY_UNMOUNT_TARGET_CDROM=
|
---|
120 | echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
|
---|
121 | else
|
---|
122 | MY_UNMOUNT_TARGET_CDROM="yes"
|
---|
123 | log_command mount -o bind "${MY_CDROM_NOCHROOT}" "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
124 | if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
|
---|
125 | echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
|
---|
126 | else
|
---|
127 | echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
|
---|
128 | fi
|
---|
129 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
130 | log_command find "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
131 | fi
|
---|
132 | fi
|
---|
133 |
|
---|
134 |
|
---|
135 | #
|
---|
136 | # Debug
|
---|
137 | #
|
---|
138 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
139 | log_command id
|
---|
140 | log_command ps
|
---|
141 | log_command ps auxwwwf
|
---|
142 | log_command env
|
---|
143 | log_command df
|
---|
144 | log_command mount
|
---|
145 | log_command_in_target df
|
---|
146 | log_command_in_target mount
|
---|
147 | #log_command find /
|
---|
148 | MY_EXITCODE=0
|
---|
149 | fi
|
---|
150 |
|
---|
151 |
|
---|
152 | #
|
---|
153 | # Packages needed for GAs.
|
---|
154 | #
|
---|
155 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
156 | echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
|
---|
157 | log_command_in_target yum -y install "kernel-devel-$(uname -r)"
|
---|
158 | log_command_in_target yum -y install "kernel-headers-$(uname -r)"
|
---|
159 | log_command_in_target yum -y install gcc
|
---|
160 | log_command_in_target yum -y install binutils
|
---|
161 | log_command_in_target yum -y install make
|
---|
162 | log_command_in_target yum -y install dkms
|
---|
163 | log_command_in_target yum -y install make
|
---|
164 | log_command_in_target yum -y install bzip2
|
---|
165 | log_command_in_target yum -y install perl
|
---|
166 |
|
---|
167 |
|
---|
168 | #
|
---|
169 | # GAs
|
---|
170 | #
|
---|
171 | @@VBOX_COND_IS_INSTALLING_ADDITIONS@@
|
---|
172 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
173 | echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
|
---|
174 | MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
|
---|
175 | log_command_in_target /bin/bash "${MY_CHROOT_CDROM}/vboxadditions/VBoxLinuxAdditions.run" --nox11
|
---|
176 | MY_IGNORE_EXITCODE=
|
---|
177 | log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
|
---|
178 | @@VBOX_COND_END@@
|
---|
179 |
|
---|
180 |
|
---|
181 | #
|
---|
182 | # Test Execution Service.
|
---|
183 | #
|
---|
184 | @@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
|
---|
185 | echo "--------------------------------------------------" >> "${MY_LOGFILE}"
|
---|
186 | echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
|
---|
187 | log_command_in_target test "${MY_CHROOT_CDROM}/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
|
---|
188 | log_command mkdir -p "${MY_TARGET}/opt/validationkit" "${MY_TARGET}/media/cdrom"
|
---|
189 | log_command cp -R ${MY_CDROM_NOCHROOT}/vboxvalidationkit/* "${MY_TARGET}/opt/validationkit/"
|
---|
190 | log_command chmod -R u+rw,a+xr "${MY_TARGET}/opt/validationkit/"
|
---|
191 | if [ -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
|
---|
192 | MY_IGNORE_EXITCODE=1
|
---|
193 | log_command_in_target chcon -R -t usr_t "/opt/validationkit/"
|
---|
194 | MY_IGNORE_EXITCODE=
|
---|
195 | fi
|
---|
196 |
|
---|
197 | # systemd service config:
|
---|
198 | MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
|
---|
199 | test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
|
---|
200 | if [ -d "${MY_UNIT_PATH}" ]; then
|
---|
201 | log_command cp "${MY_TARGET}/opt/validationkit/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
|
---|
202 | log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
|
---|
203 | log_command_in_target systemctl -q enable vboxtxs
|
---|
204 |
|
---|
205 | # Not systemd: Add support for upstart later...
|
---|
206 | else
|
---|
207 | echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
|
---|
208 | fi
|
---|
209 |
|
---|
210 | @@VBOX_COND_END@@
|
---|
211 |
|
---|
212 |
|
---|
213 | #
|
---|
214 | # Run user command.
|
---|
215 | #
|
---|
216 | @@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
|
---|
217 | echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
|
---|
218 | log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
|
---|
219 | @@VBOX_COND_END@@
|
---|
220 |
|
---|
221 |
|
---|
222 | #
|
---|
223 | # Unmount the cdrom if we bound it and clean up the chroot if we set it up.
|
---|
224 | #
|
---|
225 | if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
|
---|
226 | echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
|
---|
227 | log_command umount "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
228 | fi
|
---|
229 |
|
---|
230 | if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
|
---|
231 | log_command rmdir "${MY_TARGET}${MY_CHROOT_CDROM}"
|
---|
232 | fi
|
---|
233 |
|
---|
234 |
|
---|
235 | #
|
---|
236 | # Log footer.
|
---|
237 | #
|
---|
238 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
239 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
240 | echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
|
---|
241 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
242 |
|
---|
243 | exit ${MY_EXITCODE}
|
---|
244 |
|
---|