1 | #!/bin/sh
|
---|
2 | # $Id: setup-routines.sh 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox Validation Kit - TestBoxScript Service Setup.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox base platform packages, as
|
---|
11 | # available from https://www.virtualbox.org.
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or
|
---|
14 | # modify it under the terms of the GNU General Public License
|
---|
15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
16 | # License.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful, but
|
---|
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | # General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | #
|
---|
26 | # The contents of this file may alternatively be used under the terms
|
---|
27 | # of the Common Development and Distribution License Version 1.0
|
---|
28 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
29 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
30 | # CDDL are applicable instead of those of the GPL.
|
---|
31 | #
|
---|
32 | # You may elect to license modified versions of this file under the
|
---|
33 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
34 | #
|
---|
35 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
36 | #
|
---|
37 |
|
---|
38 |
|
---|
39 | # Load the routines we share with the linux installer.
|
---|
40 | if test ! -r "${DIR}/linux/setup-installer-routines.sh" -a -r "${DIR}/../../Installer/linux/routines.sh"; then
|
---|
41 | . "${DIR}/../../Installer/linux/routines.sh"
|
---|
42 | else
|
---|
43 | . "${DIR}/linux/setup-installer-routines.sh"
|
---|
44 | fi
|
---|
45 |
|
---|
46 |
|
---|
47 | os_load_config() {
|
---|
48 | if [ -d /etc/conf.d/ ]; then
|
---|
49 | MY_CONFIG_FILE="/etc/conf.d/testboxscript"
|
---|
50 | elif [ -d /etc/default/ ]; then
|
---|
51 | MY_CONFIG_FILE="/etc/default/testboxscript"
|
---|
52 | else
|
---|
53 | echo "Port me!"
|
---|
54 | exit 1;
|
---|
55 | fi
|
---|
56 | if [ -r "${MY_CONFIG_FILE}" ]; then
|
---|
57 | . "${MY_CONFIG_FILE}"
|
---|
58 | fi
|
---|
59 | }
|
---|
60 |
|
---|
61 | os_install_service() {
|
---|
62 | #
|
---|
63 | # Install the runlevel script.
|
---|
64 | #
|
---|
65 | install_init_script "${TESTBOXSCRIPT_DIR}/testboxscript/linux/testboxscript-service.sh" "testboxscript-service"
|
---|
66 | set +e
|
---|
67 | delrunlevel "testboxscript-service" > /dev/null 2>&1
|
---|
68 | addrunlevel "testboxscript-service" 90 10
|
---|
69 | set -e
|
---|
70 |
|
---|
71 | #
|
---|
72 | # Install the configuration file.
|
---|
73 | #
|
---|
74 | echo "# Generated by $0." > "${MY_CONFIG_FILE}"
|
---|
75 | for var in ${TESTBOXSCRIPT_CFG_NAMES};
|
---|
76 | do
|
---|
77 | varcfg=TESTBOXSCRIPT_${var}
|
---|
78 | vardef=TESTBOXSCRIPT_DEFAULT_${var}
|
---|
79 | if [ "${!varcfg}" = "${!vardef}" ]; then
|
---|
80 | echo "# using default value: ${varcfg}=${!varcfg}" >> "${MY_CONFIG_FILE}"
|
---|
81 | else
|
---|
82 | echo "${varcfg}=${!varcfg}" >> "${MY_CONFIG_FILE}"
|
---|
83 | fi
|
---|
84 | done
|
---|
85 |
|
---|
86 | # Work around a bug with arrays in old bash versions.
|
---|
87 | if [ ${#TESTBOXSCRIPT_ENVVARS[@]} -ne 0 ]; then
|
---|
88 | set | sed -n -e '/^TESTBOXSCRIPT_ENVVARS=/p' >> "${MY_CONFIG_FILE}"
|
---|
89 | fi
|
---|
90 | return 0;
|
---|
91 | }
|
---|
92 |
|
---|
93 | os_enable_service() {
|
---|
94 | start_init_script testboxscript-service
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | os_disable_service() {
|
---|
99 | stop_init_script testboxscript-service 2>&1 || true # Ignore
|
---|
100 | return 0;
|
---|
101 | }
|
---|
102 |
|
---|
103 | os_add_user() {
|
---|
104 | ADD_GROUPS=""
|
---|
105 | if ! grep -q wheel /etc/group; then
|
---|
106 | ADD_GROUPS="-G wheel"
|
---|
107 | fi
|
---|
108 | set -e
|
---|
109 | useradd -m -U -p password -s /bin/bash ${ADD_GROUPS} "${TESTBOXSCRIPT_USER}"
|
---|
110 | set +e
|
---|
111 | return 0;
|
---|
112 | }
|
---|
113 |
|
---|
114 | check_for_cifs() {
|
---|
115 | test -x /sbin/mount.cifs -o -x /usr/sbin/mount.cifs
|
---|
116 | grep -wq cifs /proc/filesystems || modprobe cifs;
|
---|
117 | # Note! If modprobe doesn't work above, /sbin and /usr/sbin are probably missing from the search PATH.
|
---|
118 | return 0;
|
---|
119 | }
|
---|
120 |
|
---|
121 | ##
|
---|
122 | # Test if core dumps are enabled. See https://wiki.ubuntu.com/Apport!
|
---|
123 | #
|
---|
124 | test_coredumps() {
|
---|
125 | if test "`lsb_release -is`" = "Ubuntu"; then
|
---|
126 | if grep -q "apport" /proc/sys/kernel/core_pattern; then
|
---|
127 | if grep -q "#.*problem_types" /etc/apport/crashdb.conf; then
|
---|
128 | echo "It looks like core dumps are properly configured, good!"
|
---|
129 | else
|
---|
130 | echo "Warning: Core dumps will be not always generated!"
|
---|
131 | fi
|
---|
132 | else
|
---|
133 | echo "Warning: Apport not installed! This package is required for core dump handling!"
|
---|
134 | fi
|
---|
135 | fi
|
---|
136 | }
|
---|
137 |
|
---|
138 | ##
|
---|
139 | # Test if unattended updates are disabled. See
|
---|
140 | # http://ask.xmodulo.com/disable-automatic-updates-ubuntu.html
|
---|
141 | test_unattended_updates_disabled() {
|
---|
142 | if grep "APT::Periodic::Unattended-Upgrade.*1" /etc/apt/apt.conf.d/* 2>/dev/null; then
|
---|
143 | echo "Unattended updates enabled?"
|
---|
144 | return 1
|
---|
145 | fi
|
---|
146 | if grep "APT::Periodic::Update-Package-List.*1" /etc/apt/apt.conf.d/* 2>/dev/null; then
|
---|
147 | echo "Unattended package updates enabled?"
|
---|
148 | return 1
|
---|
149 | fi
|
---|
150 | }
|
---|
151 |
|
---|
152 | os_final_message() {
|
---|
153 | cat <<EOF
|
---|
154 |
|
---|
155 | Additional things to do:"
|
---|
156 | 1. Check if the proxy settings are appropriate for reaching the test
|
---|
157 | manager host. Python does not support domain matches starting with ".".
|
---|
158 |
|
---|
159 | For Debian and Ubuntu: check /etc/environment.
|
---|
160 | For EL: check /etc/profile and/or the files in /etc/profile.d/.
|
---|
161 |
|
---|
162 | 2. If the system should be doing RAM disk based testing, add the following
|
---|
163 | (or something similar, adapted to the system) to /etc/fstab:
|
---|
164 |
|
---|
165 | tmpfs /var/tmp/testbox-1000 tmpfs defaults,size=16G 0 0
|
---|
166 |
|
---|
167 | After making such adjustments, it's the easiest solution to reboot the testbox.
|
---|
168 |
|
---|
169 | Enjoy!
|
---|
170 | EOF
|
---|
171 | }
|
---|
172 |
|
---|