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"
|
---|
21 | MY_DEBUG=""
|
---|
22 | MY_TARGET="/target"
|
---|
23 | MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
|
---|
24 | MY_EXITCODE=0
|
---|
25 |
|
---|
26 | # Logs execution of a command.
|
---|
27 | log_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 |
|
---|
44 | log_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 | #
|
---|
62 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
63 | echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
|
---|
64 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
65 | echo "** Started: $0 $*" >> "${MY_LOGFILE}"
|
---|
66 |
|
---|
67 | #
|
---|
68 | # Setup the target jail ourselves since in-target steals all the output.
|
---|
69 | #
|
---|
70 | if [ -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
|
---|
78 | else
|
---|
79 | MY_HAVE_CHROOT_SETUP=""
|
---|
80 | fi
|
---|
81 |
|
---|
82 | #
|
---|
83 | # We want the ISO available inside the target jail.
|
---|
84 | #
|
---|
85 | if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
|
---|
86 | MY_UNMOUNT_TARGET_CDROM=
|
---|
87 | echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
|
---|
88 | else
|
---|
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
|
---|
99 | fi
|
---|
100 |
|
---|
101 | #
|
---|
102 | # Debug
|
---|
103 | #
|
---|
104 | if [ "${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
|
---|
112 | fi
|
---|
113 |
|
---|
114 | #
|
---|
115 | # Packages needed for GAs.
|
---|
116 | #
|
---|
117 | echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
|
---|
118 | log_command_in_target apt-get -y install build-essential
|
---|
119 | log_command_in_target apt-get -y install linux-headers-$(uname -r)
|
---|
120 |
|
---|
121 | #
|
---|
122 | # GAs
|
---|
123 | #
|
---|
124 | @@VBOX_COND_IS_INSTALLING_ADDITIONS@@
|
---|
125 | echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
|
---|
126 | MY_IGNORE_EXITCODE=2 # returned if modules already loaded and reboot required.
|
---|
127 | log_command_in_target /bin/bash /cdrom/vboxadditions/VBoxLinuxAdditions.run --nox11
|
---|
128 | MY_IGNORE_EXITCODE=
|
---|
129 | log_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@@
|
---|
136 | echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
|
---|
137 | log_command_in_target test "/cdrom/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
|
---|
138 | log_command mkdir -p "${MY_TARGET}/root/validationkit" "${MY_TARGET}/target/cdrom"
|
---|
139 | log_command cp -R /cdrom/vboxvalidationkit/* "${MY_TARGET}/root/validationkit/"
|
---|
140 | log_command chmod -R u+rw,a+xr "${MY_TARGET}/root/validationkit/"
|
---|
141 |
|
---|
142 | # systemd service config:
|
---|
143 | MY_UNIT_PATH="${MY_TARGET}/lib/systemd/system"
|
---|
144 | test -d "${MY_TARGET}/usr/lib/systemd/system" && MY_UNIT_PATH="${MY_TARGET}/usr/lib/systemd/system"
|
---|
145 | if [ -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]
|
---|
151 | Description=VirtualBox Test Execution Service
|
---|
152 | SourcePath=/root/validationkit/linux/vboxtxs
|
---|
153 |
|
---|
154 | [Service]
|
---|
155 | Type=forking
|
---|
156 | Restart=no
|
---|
157 | TimeoutSec=5min
|
---|
158 | IgnoreSIGPIPE=no
|
---|
159 | KillMode=process
|
---|
160 | GuessMainPID=no
|
---|
161 | RemainAfterExit=yes
|
---|
162 | ExecStart=/root/validationkit/linux/vboxtxs start
|
---|
163 | ExecStop=/root/validationkit/linux/vboxtxs stop
|
---|
164 |
|
---|
165 | [Install]
|
---|
166 | WantedBy=multi-user.target
|
---|
167 | EOF
|
---|
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...
|
---|
173 | else
|
---|
174 | echo "** error: No systemd unit dir found. Using upstart or something?" | tee -a "${MY_LOGFILE}"
|
---|
175 | fi
|
---|
176 |
|
---|
177 | @@VBOX_COND_END@@
|
---|
178 |
|
---|
179 | #
|
---|
180 | # Run user command.
|
---|
181 | #
|
---|
182 | @@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
|
---|
183 | echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
|
---|
184 | log_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 | #
|
---|
190 | if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
|
---|
191 | echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
|
---|
192 | log_command umount "${MY_TARGET}/cdrom"
|
---|
193 | fi
|
---|
194 | if [ -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
|
---|
200 | fi
|
---|
201 |
|
---|
202 | #
|
---|
203 | # Footer.
|
---|
204 | #
|
---|
205 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
206 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
207 | echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
|
---|
208 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
209 |
|
---|
210 | exit ${MY_EXITCODE}
|
---|
211 |
|
---|