VirtualBox

source: vbox/trunk/src/VBox/Main/UnattendedTemplates/ol_postinstall.sh

最後變更 在這個檔案是 107906,由 vboxsync 提交於 7 週 前

Main/Unattended: Add AVOID_UPDATES_OVER_NETWORK variable for expressions and disable any fetching of packages from remote repositories in the OL post install script if indicated to avoid network updates (hopefully fixes unattened testcases timing out during the post install phase because the host proxies are not set up correctly)

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.0 KB
 
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-2024 Oracle and/or its affiliates.
10#
11# This file is part of VirtualBox base platform packages, as
12# available from https://www.alldomusa.eu.org.
13#
14# This program is free software; you can redistribute it and/or
15# modify it under the terms of the GNU General Public License
16# as published by the Free Software Foundation, in version 3 of the
17# License.
18#
19# This program is distributed in the hope that it will be useful, but
20# WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22# General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, see <https://www.gnu.org/licenses>.
26#
27# SPDX-License-Identifier: GPL-3.0-only
28#
29
30
31#
32# Globals.
33#
34MY_TARGET="/mnt/sysimage"
35MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
36MY_CHROOT_CDROM="/cdrom"
37MY_CDROM_NOCHROOT="/tmp/vboxcdrom"
38MY_EXITCODE=0
39MY_DEBUG="" # "yes"
40GUEST_VERSION=@@VBOX_INSERT_GUEST_OS_VERSION@@
41GUEST_MAJOR_VERSION=@@VBOX_INSERT_GUEST_OS_MAJOR_VERSION@@
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]}" # bashism - whatever.
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 log_command chroot "${MY_TARGET}" "$@"
115}
116
117# Checks if $1 is a command on the PATH inside the target jail.
118chroot_which()
119{
120 for dir in /bin /usr/bin /sbin /usr/sbin;
121 do
122 if [ -x "${MY_TARGET}${dir}/$1" ]; then
123 return 0;
124 fi
125 done
126 return 1;
127}
128
129#
130# Log header.
131#
132echo "******************************************************************************" >> "${MY_LOGFILE}"
133echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
134echo "** Date: `date -R`" >> "${MY_LOGFILE}"
135echo "** Started: $0 $*" >> "${MY_LOGFILE}"
136
137
138#
139# We want the ISO available inside the target jail.
140#
141if [ -d "${MY_TARGET}${MY_CHROOT_CDROM}" ]; then
142 MY_RMDIR_TARGET_CDROM=
143else
144 MY_RMDIR_TARGET_CDROM="yes"
145 log_command mkdir -p ${MY_TARGET}${MY_CHROOT_CDROM}
146fi
147
148if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
149 MY_UNMOUNT_TARGET_CDROM=
150 echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
151else
152 MY_UNMOUNT_TARGET_CDROM="yes"
153 log_command mount -o bind "${MY_CDROM_NOCHROOT}" "${MY_TARGET}${MY_CHROOT_CDROM}"
154 if [ -f "${MY_TARGET}${MY_CHROOT_CDROM}/vboxpostinstall.sh" ]; then
155 echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
156 else
157 echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
158 fi
159 if [ "${MY_DEBUG}" = "yes" ]; then
160 log_command find "${MY_TARGET}${MY_CHROOT_CDROM}"
161 fi
162fi
163
164
165#
166# Debug
167#
168if [ "${MY_DEBUG}" = "yes" ]; then
169 log_command id
170 log_command ps
171 log_command ps auxwwwf
172 log_command env
173 log_command df
174 log_command mount
175 log_command_in_target df
176 log_command_in_target mount
177 #log_command find /
178 MY_EXITCODE=0
179fi
180
181
182@@VBOX_COND[${AVOID_UPDATES_OVER_NETWORK} == false]@@
183#
184# Add EPEL repository
185#
186EPEL_REPOSITORY="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${GUEST_MAJOR_VERSION}.noarch.rpm"
187log_command_in_target wget ${EPEL_REPOSITORY}
188log_command_in_target yum localinstall -y "epel-release-latest-${GUEST_MAJOR_VERSION}.noarch.rpm"
189log_command_in_target rpm -q "oraclelinux-release-el${GUEST_MAJOR_VERSION}"
190log_command_in_target yum install -y yum-utils
191log_command_in_target yum-config-manager --enable epel
192
193
194#
195# Packages needed for GAs.
196#
197echo "--------------------------------------------------" >> "${MY_LOGFILE}"
198echo '** Finding UEK kernel...' | tee -a "${MY_LOGFILE}"
199UEK=$(find ${MY_TARGET}/boot/ -name "vmlinuz*"| grep uek | awk -F"-" 'BEGIN{OFS="-"} \
200{ kernel=$2; for (i = 3; i <= NF; i++) { kernel=sprintf("%s-%s",kernel,$i)}} END{print kernel}')
201CURRENT_KERNEL=$(uname -r)
202
203if [ -n $UEK ]; then
204 echo "UEK kernel was found - ${UEK}" | tee -a "${MY_LOGFILE}"
205 log_command_in_target yum -y install "kernel-uek-devel-${UEK}"
206fi
207echo "Installation uses kernel ${CURRENT_KERNEL}" | tee -a "${MY_LOGFILE}"
208
209echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
210log_command_in_target yum -y install "kernel-devel-$(uname -r)"
211log_command_in_target yum -y install "kernel-headers-$(uname -r)"
212log_command_in_target yum -y install gcc
213log_command_in_target yum -y install binutils
214log_command_in_target yum -y install make
215@@VBOX_COND[${GUEST_OS_VERSION} vgt 8.0.0]@@
216log_command_in_target yum -y install elfutils-libelf-devel
217@@VBOX_COND_END@@
218log_command_in_target yum -y install dkms
219log_command_in_target yum -y install make
220log_command_in_target yum -y install bzip2
221log_command_in_target yum -y install perl
222
223
224#
225#Package cloud-init is needed for possible automation the initial setup of virtual machine
226#
227log_command_in_target yum -y install cloud-init
228@@VBOX_COND_END@@
229
230log_command_in_target systemctl enable cloud-init-local.service
231log_command_in_target systemctl enable cloud-init.service
232log_command_in_target systemctl enable cloud-config.service
233log_command_in_target systemctl enable cloud-final.service
234
235
236#
237# GAs
238#
239@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
240echo "--------------------------------------------------" >> "${MY_LOGFILE}"
241echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
242MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
243log_command_in_target /bin/bash "${MY_CHROOT_CDROM}/vboxadditions/@@VBOX_INSERT_ADDITIONS_INSTALL_PACKAGE_NAME@@" --nox11
244log_command_in_target /bin/bash -c "udevadm control --reload-rules" # GAs doesn't yet do this.
245log_command_in_target /bin/bash -c "udevadm trigger" # (ditto)
246MY_IGNORE_EXITCODE=
247log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
248@@VBOX_COND_END@@
249
250
251#
252# Test Execution Service.
253#
254@@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
255echo "--------------------------------------------------" >> "${MY_LOGFILE}"
256echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
257log_command_in_target test "${MY_CHROOT_CDROM}/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
258log_command mkdir -p "${MY_TARGET}/opt/validationkit" "${MY_TARGET}/media/cdrom"
259log_command cp -R ${MY_CDROM_NOCHROOT}/vboxvalidationkit/* "${MY_TARGET}/opt/validationkit/"
260log_command chmod -R u+rw,a+xr "${MY_TARGET}/opt/validationkit/"
261if [ -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
262 MY_IGNORE_EXITCODE=1
263 log_command_in_target chcon -R -t usr_t "/opt/validationkit/"
264 MY_IGNORE_EXITCODE=
265fi
266
267# systemd service config:
268MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
269test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
270if [ -d "${MY_UNIT_PATH}" ]; then
271 log_command cp "${MY_TARGET}/opt/validationkit/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
272 log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
273 log_command_in_target systemctl -q enable vboxtxs
274
275# System V like:
276elif [ -e "${MY_TARGET}/etc/init.d/" ]; then
277
278 # Install the script. On rhel6 scripts are under /etc/rc.d/ with /etc/init.d and /etc/rc?.d being symlinks.
279 if [ -d "${MY_TARGET}/etc/rc.d/init.d/" ]; then
280 MY_INIT_D_PARENT_PATH="${MY_TARGET}/etc/rc.d"
281 log_command ln -s "../../../opt/validationkit/linux/vboxtxs" "${MY_INIT_D_PARENT_PATH}/init.d/"
282 else
283 MY_INIT_D_PARENT_PATH="${MY_TARGET}/etc"
284 log_command ln -s "../../opt/validationkit/linux/vboxtxs" "${MY_INIT_D_PARENT_PATH}/init.d/"
285 fi
286
287 # Use runlevel management script if found.
288 if chroot_which chkconfig; then # Redhat based sysvinit systems
289 log_command_in_target chkconfig --add vboxtxs
290 elif chroot_which insserv; then # SUSE-based sysvinit systems
291 log_command_in_target insserv vboxtxs
292 elif chroot_which update-rc.d; then # Debian/Ubuntu-based systems
293 log_command_in_target update-rc.d vboxtxs defaults
294 elif chroot_which rc-update; then # Gentoo Linux
295 log_command_in_target rc-update add vboxtxs default
296 # Fall back on hardcoded symlinking.
297 else
298 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc0.d/K65vboxtxs"
299 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc1.d/K65vboxtxs"
300 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc6.d/K65vboxtxs"
301 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc2.d/S35vboxtxs"
302 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc3.d/S35vboxtxs"
303 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc4.d/S35vboxtxs"
304 log_command ln -s "../init.d/vboxtxs" "${MY_INIT_D_PARENT_PATH}/rc5.d/S35vboxtxs"
305 fi
306else
307 echo "** error: Unknown init script system." | tee -a "${MY_LOGFILE}"
308fi
309
310@@VBOX_COND_END@@
311
312
313#
314# Run user command.
315#
316@@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
317echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
318log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
319@@VBOX_COND_END@@
320
321
322#
323# Unmount the cdrom if we bound it and clean up the chroot if we set it up.
324#
325if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
326 echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
327 log_command umount "${MY_TARGET}${MY_CHROOT_CDROM}"
328fi
329
330if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
331 log_command rmdir "${MY_TARGET}${MY_CHROOT_CDROM}"
332fi
333
334
335#
336# Log footer.
337#
338echo "******************************************************************************" >> "${MY_LOGFILE}"
339echo "** Date: `date -R`" >> "${MY_LOGFILE}"
340echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
341echo "******************************************************************************" >> "${MY_LOGFILE}"
342
343exit ${MY_EXITCODE}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette