VirtualBox

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

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

debian_postinstall.sh: Implemented installing TXS. Fixed exitcode logging. Ignore GAs indicating reboot needed.

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.7 KB
 
1#!/bin/bash
2## @file
3# Post installation script template for debian-like distros.
4#
5# This script expects to be running w/o chroot.
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.alldomusa.eu.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#MY_DEBUG="yes"
21MY_DEBUG=""
22MY_TARGET="/target"
23MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
24MY_EXITCODE=0
25
26# Logs execution of a command.
27log_command()
28{
29 echo "--------------------------------------------------" >> "${MY_LOGFILE}"
30 echo "** Date: `date -R`" >> "${MY_LOGFILE}"
31 echo "** Executing: $*" >> "${MY_LOGFILE}"
32 "$@" 2>&1 | tee -a "${MY_LOGFILE}"
33 MY_TMP_EXITCODE="${PIPESTATUS[0]}"
34 if [ "${MY_TMP_EXITCODE}" != "0" ]; then
35 if [ "${MY_TMP_EXITCODE}" != "${MY_IGNORE_EXITCODE}" ]; then
36 echo "** exit code: ${MY_TMP_EXITCODE}" | tee -a "${MY_LOGFILE}"
37 MY_EXITCODE=1;
38 else
39 echo "** exit code: ${MY_TMP_EXITCODE} (ignored)" | tee -a "${MY_LOGFILE}"
40 fi
41 fi
42}
43
44log_command_in_target()
45{
46 #
47 # We should be using in-target here, however we don't get any stderr output
48 # from it because of log-output. We can get stdout by --pass-stdout, but
49 # that's not helpful for failures.
50 #
51 # So, we try do the chroot prepping that in-target does at the start of the
52 # script (see below) and just use chroot here.
53 #
54 log_command chroot "${MY_TARGET}" "$@"
55 # log_command in-target --pass-stdout "$@" # No stderr output... :-(
56}
57
58
59#
60# Header.
61#
62echo "******************************************************************************" >> "${MY_LOGFILE}"
63echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
64echo "** Date: `date -R`" >> "${MY_LOGFILE}"
65echo "** Started: $0 $*" >> "${MY_LOGFILE}"
66
67#
68# Setup the target jail ourselves since in-target steals all the output.
69#
70if [ -f /lib/chroot-setup.sh ]; then
71 MY_HAVE_CHROOT_SETUP="yes"
72 . /lib/chroot-setup.sh
73 if chroot_setup; then
74 echo "** chroot_setup: done" | tee -a "${MY_LOGFILE}"
75 else
76 echo "** chroot_setup: failed $?" | tee -a "${MY_LOGFILE}"
77 fi
78else
79 MY_HAVE_CHROOT_SETUP=""
80fi
81
82#
83# We want the ISO available inside the target jail.
84#
85if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
86 MY_UNMOUNT_TARGET_CDROM=
87 echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
88else
89 MY_UNMOUNT_TARGET_CDROM="yes"
90 log_command mount -o bind /cdrom "${MY_TARGET}/cdrom"
91 if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
92 echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
93 else
94 echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
95 fi
96 if [ "${MY_DEBUG}" = "yes" ]; then
97 log_command find "${MY_TARGET}/cdrom"
98 fi
99fi
100
101#
102# Debug
103#
104if [ "${MY_DEBUG}" = "yes" ]; then
105 log_command id
106 log_command df
107 log_command mount
108 log_command_in_target df
109 log_command_in_target mount
110 log_command find /
111 MY_EXITCODE=0
112fi
113
114#
115# Packages needed for GAs.
116#
117echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
118log_command_in_target apt-get -y install build-essential
119log_command_in_target apt-get -y install linux-headers-$(uname -r)
120
121#
122# GAs
123#
124@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
125echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
126MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
127log_command_in_target /bin/bash /cdrom/vboxadditions/VBoxLinuxAdditions.run --nox11
128MY_IGNORE_EXITCODE=
129log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
130@@VBOX_COND_END@@
131
132#
133# Test Execution Service.
134#
135@@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
136echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
137log_command_in_target test "/cdrom/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
138log_command mkdir -p "${MY_TARGET}/root/validationkit" "${MY_TARGET}/target/cdrom"
139log_command cp -R /cdrom/vboxvalidationkit/* "${MY_TARGET}/root/validationkit/"
140log_command chmod -R u+rw,a+xr "${MY_TARGET}/root/validationkit/"
141
142# systemd service config:
143MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
144test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
145if [ -d "${MY_UNIT_PATH}" ]; then
146 if [ -f "${MY_TARGET}/linux/vboxtxs.service" ]; then ## REMOVE AS SOON AS r117117 IS READY
147 log_command cp "${MY_TARGET}/linux/vboxtxs.service" "${MY_UNIT_PATH}/vboxtxs.service"
148 else ## REMOVE AS SOON AS r117117 IS READY
149 cat > "${MY_UNIT_PATH}/vboxtxs.service" <<EOF
150[Unit]
151Description=VirtualBox Test Execution Service
152SourcePath=/root/validationkit/linux/vboxtxs
153
154[Service]
155Type=forking
156Restart=no
157TimeoutSec=5min
158IgnoreSIGPIPE=no
159KillMode=process
160GuessMainPID=no
161RemainAfterExit=yes
162ExecStart=/root/validationkit/linux/vboxtxs start
163ExecStop=/root/validationkit/linux/vboxtxs stop
164
165[Install]
166WantedBy=multi-user.target
167EOF
168 fi
169 log_command chmod 755 "${MY_UNIT_PATH}/vboxtxs.service"
170 log_command_in_target systemctl -q enable vboxtxs
171
172# Not systemd. Add support for upstart later...
173else
174 echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
175fi
176
177@@VBOX_COND_END@@
178
179#
180# Run user command.
181#
182@@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
183echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
184log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
185@@VBOX_COND_END@@
186
187#
188# Unmount the cdrom if we bound it and clean up the chroot if we set it up.
189#
190if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
191 echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
192 log_command umount "${MY_TARGET}/cdrom"
193fi
194if [ -n "${MY_HAVE_CHROOT_SETUP}" ]; then
195 if chroot_cleanup; then
196 echo "** chroot_cleanup: done" | tee -a "${MY_LOGFILE}"
197 else
198 echo "** chroot_cleanup: failed $?" | tee -a "${MY_LOGFILE}"
199 fi
200fi
201
202#
203# Footer.
204#
205echo "******************************************************************************" >> "${MY_LOGFILE}"
206echo "** Date: `date -R`" >> "${MY_LOGFILE}"
207echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
208echo "******************************************************************************" >> "${MY_LOGFILE}"
209
210exit ${MY_EXITCODE}
211
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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