VirtualBox

source: vbox/trunk/src/VBox/Main/UnattendedTemplates/redhat_postinstall.sh@ 86714

Last change on this file since 86714 was 86659, checked in by vboxsync, 4 years ago

bugref:9781. Added the placeholder @@VBOX_COND_GUEST_VERSION[>(required version)]@@. Updated the templates. Removed the obsolete function getGuestOSConditional().

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