VirtualBox

source: vbox/trunk/src/VBox/Main/UnattendedTemplates/debian_postinstall.sh@ 68160

最後變更 在這個檔案從68160是 68160,由 vboxsync 提交於 8 年 前

Unattended: Working on fedora currently, want to use re-mastered VISO here too. Requires disabling checkisomd5 (rd.live.check).

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.1 KB
 
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#
26MY_TARGET="/target"
27MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
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 #
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#
111echo "******************************************************************************" >> "${MY_LOGFILE}"
112echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
113echo "** Date: `date -R`" >> "${MY_LOGFILE}"
114echo "** Started: $0 $*" >> "${MY_LOGFILE}"
115
116
117#
118# Setup the target jail ourselves since in-target steals all the output.
119#
120if [ -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
128else
129 MY_HAVE_CHROOT_SETUP=""
130fi
131
132
133#
134# We want the ISO available inside the target jail.
135#
136if [ -d "${MY_TARGET}/cdrom" ]; then
137 MY_RMDIR_TARGET_CDROM=
138else
139 MY_RMDIR_TARGET_CDROM="yes"
140 log_command mkdir -p ${MY_TARGET}/cdrom
141fi
142
143if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
144 MY_UNMOUNT_TARGET_CDROM=
145 echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
146else
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
157fi
158
159
160#
161# Debug
162#
163if [ "${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
174fi
175
176
177#
178# Packages needed for GAs.
179#
180echo "--------------------------------------------------" >> "${MY_LOGFILE}"
181echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
182log_command_in_target apt-get -y install build-essential
183log_command_in_target apt-get -y install linux-headers-$(uname -r)
184
185
186#
187# GAs
188#
189@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
190echo "--------------------------------------------------" >> "${MY_LOGFILE}"
191echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
192MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
193log_command_in_target /bin/bash /cdrom/vboxadditions/VBoxLinuxAdditions.run --nox11
194MY_IGNORE_EXITCODE=
195log_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@@
203echo "--------------------------------------------------" >> "${MY_LOGFILE}"
204echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
205log_command_in_target test "/cdrom/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
206log_command mkdir -p "${MY_TARGET}/root/validationkit" "${MY_TARGET}/target/cdrom"
207log_command cp -R /cdrom/vboxvalidationkit/* "${MY_TARGET}/root/validationkit/"
208log_command chmod -R u+rw,a+xr "${MY_TARGET}/root/validationkit/"
209
210# systemd service config:
211MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
212test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
213if [ -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...
219else
220 echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
221fi
222
223@@VBOX_COND_END@@
224
225
226#
227# Run user command.
228#
229@@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
230echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
231log_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#
238if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
239 echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
240 log_command umount "${MY_TARGET}/cdrom"
241fi
242
243if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
244 log_command rmdir "${MY_TARGET}/cdrom"
245fi
246
247if [ -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
253fi
254
255
256#
257# Log footer.
258#
259echo "******************************************************************************" >> "${MY_LOGFILE}"
260echo "** Date: `date -R`" >> "${MY_LOGFILE}"
261echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
262echo "******************************************************************************" >> "${MY_LOGFILE}"
263
264exit ${MY_EXITCODE}
265
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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