VirtualBox

source: vbox/trunk/src/VBox/Main/UnattendedTemplates/redhat_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: 7.8 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 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="/run/install/repo"
28MY_EXITCODE=0
29MY_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#
36if [ "$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" "$@"
67fi
68
69
70#
71# Commands.
72#
73
74# Logs execution of a command.
75log_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.
93log_command_in_target()
94{
95 log_command chroot "${MY_TARGET}" "$@"
96}
97
98
99#
100# Log header.
101#
102echo "******************************************************************************" >> "${MY_LOGFILE}"
103echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
104echo "** Date: `date -R`" >> "${MY_LOGFILE}"
105echo "** Started: $0 $*" >> "${MY_LOGFILE}"
106
107
108#
109# We want the ISO available inside the target jail.
110#
111if [ -d "${MY_TARGET}${MY_CHROOT_CDROM}" ]; then
112 MY_RMDIR_TARGET_CDROM=
113else
114 MY_RMDIR_TARGET_CDROM="yes"
115 log_command mkdir -p ${MY_TARGET}${MY_CHROOT_CDROM}
116fi
117
118if [ -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}"
121else
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
132fi
133
134
135#
136# Debug
137#
138if [ "${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
149fi
150
151
152#
153# Packages needed for GAs.
154#
155echo "--------------------------------------------------" >> "${MY_LOGFILE}"
156echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
157log_command_in_target yum -y install "kernel-devel-$(uname -r)"
158log_command_in_target yum -y install "kernel-headers-$(uname -r)"
159log_command_in_target yum -y install gcc
160log_command_in_target yum -y install binutils
161log_command_in_target yum -y install make
162log_command_in_target yum -y install dkms
163log_command_in_target yum -y install make
164log_command_in_target yum -y install bzip2
165log_command_in_target yum -y install perl
166
167
168#
169# GAs
170#
171@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
172echo "--------------------------------------------------" >> "${MY_LOGFILE}"
173echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
174MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
175log_command_in_target /bin/bash "${MY_CHROOT_CDROM}/vboxadditions/VBoxLinuxAdditions.run" --nox11
176MY_IGNORE_EXITCODE=
177log_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@@
185echo "--------------------------------------------------" >> "${MY_LOGFILE}"
186echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
187log_command_in_target test "${MY_CHROOT_CDROM}/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
188log_command mkdir -p "${MY_TARGET}/opt/validationkit" "${MY_TARGET}/media/cdrom"
189log_command cp -R ${MY_CDROM_NOCHROOT}/vboxvalidationkit/* "${MY_TARGET}/opt/validationkit/"
190log_command chmod -R u+rw,a+xr "${MY_TARGET}/opt/validationkit/"
191if [ -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=
195fi
196
197# systemd service config:
198MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
199test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
200if [ -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...
206else
207 echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
208fi
209
210@@VBOX_COND_END@@
211
212
213#
214# Run user command.
215#
216@@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
217echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
218log_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#
225if [ -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}"
228fi
229
230if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
231 log_command rmdir "${MY_TARGET}${MY_CHROOT_CDROM}"
232fi
233
234
235#
236# Log footer.
237#
238echo "******************************************************************************" >> "${MY_LOGFILE}"
239echo "** Date: `date -R`" >> "${MY_LOGFILE}"
240echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
241echo "******************************************************************************" >> "${MY_LOGFILE}"
242
243exit ${MY_EXITCODE}
244
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