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.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 | #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 | if [ "${PIPESTATUS[0]}" != "0" ]; then
|
---|
34 | echo "exit code: ${PIPESTATUS[0]}"
|
---|
35 | MY_EXITCODE=1;
|
---|
36 | fi
|
---|
37 | }
|
---|
38 |
|
---|
39 | log_command_in_target()
|
---|
40 | {
|
---|
41 | #
|
---|
42 | # We should be using in-target here, however we don't get any stderr output
|
---|
43 | # from it because of log-output. We can get stdout by --pass-stdout, but
|
---|
44 | # that's not helpful for failures.
|
---|
45 | #
|
---|
46 | # So, we try do the chroot prepping that in-target does at the start of the
|
---|
47 | # script (see below) and just use chroot here.
|
---|
48 | #
|
---|
49 | # Also, GA installer and in-root/log-output doesn't seem to get along.
|
---|
50 | #
|
---|
51 | log_command chroot "${MY_TARGET}" "$@"
|
---|
52 | # log_command in-target --pass-stdout "$@" # No stderr output... :-(
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | #
|
---|
57 | # Header.
|
---|
58 | #
|
---|
59 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
60 | echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
|
---|
61 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
62 | echo "** Started: $0 $*" >> "${MY_LOGFILE}"
|
---|
63 |
|
---|
64 | #
|
---|
65 | # Setup the target jail ourselves since in-target steals all the output.
|
---|
66 | #
|
---|
67 | if [ -f /lib/chroot-setup.sh ]; then
|
---|
68 | MY_HAVE_CHROOT_SETUP="yes"
|
---|
69 | . /lib/chroot-setup.sh
|
---|
70 | if chroot_setup; then
|
---|
71 | echo "** chroot_setup: done" | tee -a "${MY_LOGFILE}"
|
---|
72 | else
|
---|
73 | echo "** chroot_setup: failed $?" | tee -a "${MY_LOGFILE}"
|
---|
74 | fi
|
---|
75 | else
|
---|
76 | MY_HAVE_CHROOT_SETUP=""
|
---|
77 | fi
|
---|
78 |
|
---|
79 | #
|
---|
80 | # Debug
|
---|
81 | #
|
---|
82 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
83 | log_command id
|
---|
84 | log_command df
|
---|
85 | log_command mount
|
---|
86 | log_command_in_target df
|
---|
87 | log_command_in_target mount
|
---|
88 | log_command_in_target ls -Rla /cdrom
|
---|
89 | log_command_in_target ls -Rla /media
|
---|
90 | log_command find /
|
---|
91 | MY_EXITCODE=0
|
---|
92 | fi
|
---|
93 |
|
---|
94 | # We want the ISO available inside the target jail.
|
---|
95 | if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
|
---|
96 | MY_UNMOUNT_TARGET_CDROM=
|
---|
97 | echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
|
---|
98 | else
|
---|
99 | MY_UNMOUNT_TARGET_CDROM="yes"
|
---|
100 | log_command mount -o bind /cdrom "${MY_TARGET}/cdrom"
|
---|
101 | if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
|
---|
102 | echo "** binding cdrom into jail: success" | tee -a "${MY_LOGFILE}"
|
---|
103 | else
|
---|
104 | echo "** binding cdrom into jail: failed" | tee -a "${MY_LOGFILE}"
|
---|
105 | fi
|
---|
106 | if [ "${MY_DEBUG}" = "yes" ]; then
|
---|
107 | log_command find "${MY_TARGET}/cdrom"
|
---|
108 | fi
|
---|
109 | fi
|
---|
110 |
|
---|
111 | #
|
---|
112 | # Packages needed for GAs.
|
---|
113 | #
|
---|
114 | echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
|
---|
115 | log_command_in_target apt-get -y install build-essential
|
---|
116 | log_command_in_target apt-get -y install linux-headers-$(uname -r)
|
---|
117 |
|
---|
118 | #
|
---|
119 | # GAs
|
---|
120 | #
|
---|
121 | @@VBOX_COND_IS_INSTALLING_ADDITIONS@@
|
---|
122 | echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
|
---|
123 | log_command_in_target /bin/bash /cdrom/vboxadditions/VBoxLinuxAdditions.run --nox11
|
---|
124 | log_command_in_target usermod -a -G vboxsf "@@VBOX_INSERT_USER_LOGIN@@"
|
---|
125 | @@VBOX_COND_END@@
|
---|
126 |
|
---|
127 | #
|
---|
128 | # Testing.
|
---|
129 | #
|
---|
130 | @@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
|
---|
131 | echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
|
---|
132 | log_command_in_target test "/cdrom/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
|
---|
133 | ## @todo fix this
|
---|
134 | @@VBOX_COND_END@@
|
---|
135 |
|
---|
136 | #
|
---|
137 | # Run user command.
|
---|
138 | #
|
---|
139 | @@VBOX_COND_HAS_POST_INSTALL_COMMAND@@
|
---|
140 | echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
|
---|
141 | log_command @@VBOX_INSERT_POST_INSTALL_COMMAND@@
|
---|
142 | @@VBOX_COND_END@@
|
---|
143 |
|
---|
144 | #
|
---|
145 | # Unmount the cdrom if we bound it and clean up the chroot if we set it up.
|
---|
146 | #
|
---|
147 | if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
|
---|
148 | echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
|
---|
149 | log_command umount "${MY_TARGET}/cdrom"
|
---|
150 | fi
|
---|
151 | if [ -n "${MY_HAVE_CHROOT_SETUP}" ]; then
|
---|
152 | if chroot_cleanup; then
|
---|
153 | echo "** chroot_cleanup: done" | tee -a "${MY_LOGFILE}"
|
---|
154 | else
|
---|
155 | echo "** chroot_cleanup: failed $?" | tee -a "${MY_LOGFILE}"
|
---|
156 | fi
|
---|
157 | fi
|
---|
158 |
|
---|
159 | #
|
---|
160 | # Footer.
|
---|
161 | #
|
---|
162 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
163 | echo "** Date: `date -R`" >> "${MY_LOGFILE}"
|
---|
164 | echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
|
---|
165 | echo "******************************************************************************" >> "${MY_LOGFILE}"
|
---|
166 |
|
---|
167 | exit ${MY_EXITCODE}
|
---|
168 |
|
---|