VirtualBox

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

Last change on this file since 68075 was 68075, checked in by vboxsync, 7 years ago

Unattended: debian postinstall script updates.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
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"
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 if [ "${PIPESTATUS[0]}" != "0" ]; then
34 echo "exit code: ${PIPESTATUS[0]}"
35 MY_EXITCODE=1;
36 fi
37}
38
39log_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#
59echo "******************************************************************************" >> "${MY_LOGFILE}"
60echo "** VirtualBox Unattended Guest Installation - Late installation actions" >> "${MY_LOGFILE}"
61echo "** Date: `date -R`" >> "${MY_LOGFILE}"
62echo "** Started: $0 $*" >> "${MY_LOGFILE}"
63
64#
65# Setup the target jail ourselves since in-target steals all the output.
66#
67if [ -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
75else
76 MY_HAVE_CHROOT_SETUP=""
77fi
78
79#
80# Debug
81#
82if [ "${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
92fi
93
94# We want the ISO available inside the target jail.
95if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
96 MY_UNMOUNT_TARGET_CDROM=
97 echo "** binding cdrom into jail: already done" | tee -a "${MY_LOGFILE}"
98else
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
109fi
110
111#
112# Packages needed for GAs.
113#
114echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
115log_command_in_target apt-get -y install build-essential
116log_command_in_target apt-get -y install linux-headers-$(uname -r)
117
118#
119# GAs
120#
121@@VBOX_COND_IS_INSTALLING_ADDITIONS@@
122echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
123log_command_in_target /bin/bash /cdrom/vboxadditions/VBoxLinuxAdditions.run --nox11
124log_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@@
131echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
132log_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@@
140echo '** Running custom user command ...' | tee -a "${MY_LOGFILE}"
141log_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#
147if [ -n "${MY_UNMOUNT_TARGET_CDROM}" ]; then
148 echo "** unbinding cdrom from jail..." | tee -a "${MY_LOGFILE}"
149 log_command umount "${MY_TARGET}/cdrom"
150fi
151if [ -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
157fi
158
159#
160# Footer.
161#
162echo "******************************************************************************" >> "${MY_LOGFILE}"
163echo "** Date: `date -R`" >> "${MY_LOGFILE}"
164echo "** Final exit code: ${MY_EXITCODE}" >> "${MY_LOGFILE}"
165echo "******************************************************************************" >> "${MY_LOGFILE}"
166
167exit ${MY_EXITCODE}
168
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