VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testboxscript/solaris/setup-routines.sh@ 91485

Last change on this file since 91485 was 88632, checked in by vboxsync, 4 years ago

testboxscript.xml service manifest has to be located permanent in /lib/svc/manifest/system for non solaris 10 versions. In solaris 11, the new service described in the manifest, will be added automatically by the command svcadm restart manifest-import

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1# $Id: setup-routines.sh 88632 2021-04-21 12:27:22Z vboxsync $
2## @file
3# VirtualBox Validation Kit - TestBoxScript Service Setup on Solaris.
4#
5
6#
7# Copyright (C) 2006-2020 Oracle Corporation
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.virtualbox.org. This file is free software;
11# you can redistribute it and/or modify it under the terms of the GNU
12# General Public License (GPL) as published by the Free Software
13# Foundation, in version 2 as it comes in the "COPYING" file of the
14# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16#
17# The contents of this file may alternatively be used under the terms
18# of the Common Development and Distribution License Version 1.0
19# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20# VirtualBox OSE distribution, in which case the provisions of the
21# CDDL are applicable instead of those of the GPL.
22#
23# You may elect to license modified versions of this file under the
24# terms and conditions of either the GPL or the CDDL or both.
25#
26
27#
28# Detect solaris version.
29#
30MY_SOLARIS_VER=`uname -r`
31case "${MY_SOLARIS_VER}" in
32 5.10) MY_SOLARIS_VER=10;;
33 5.11) MY_SOLARIS_VER=11;;
34 5.12) MY_SOLARIS_VER=12;;
35 *)
36 echo "Your solaris version (${MY_SOLARIS_VER}) is not supported." >&2
37 exit 1;;
38esac
39
40#
41# Overriding setup.sh bits.
42#
43MY_FGREP="/usr/xpg4/bin/fgrep" # The other one does grok -q.
44if [ ! -f "${MY_ETC_SUDOERS}" ]; then # sudo isn't standard on S10.
45 if [ -f "/opt/csw/etc/sudoers" ]; then
46 MY_ETC_SUDOERS=/opt/csw/etc/sudoers
47 fi
48 if [ -f "/etc/opt/csw/sudoers" ]; then
49 MY_ETC_SUDOERS=/etc/opt/csw/sudoers
50 fi
51fi
52
53#
54# Solaris variables.
55#
56MY_SVC_FMRI="svc:/system/virtualbox/testboxscript"
57MY_SVCCFG="/usr/sbin/svccfg"
58MY_SVCADM="/usr/sbin/svcadm"
59MY_CHGRP="/usr/bin/chgrp"
60MY_TR="/usr/bin/tr"
61MY_TAB=`printf "\t"`
62
63if test "${MY_SOLARIS_VER}" -lt 11; then
64 # solaris 10 service import
65 MY_SVC="/tmp/testboxscript.xml"
66else
67 # use propper manifest directory
68 # /lib/svc/manifest/system for solaris 11 and higher for testboxscript.xml file
69
70 # Since sol 11.4 the solaris testboxscript service
71 # generates Warnings in /var/svc/log/system-manifest-import:default.log
72 # -------- Warning!!
73 # Configuring services...
74 # * Warning!! Importing Zone access service ...FAILED.
75
76 MY_SVC="/lib/svc/manifest/system/testboxscript.xml"
77fi
78if test "${MY_SOLARIS_VER}" -lt 11; then ## No gsed on S10?? ARG!
79 MY_SED="/usr/xpg4/bin/sed"
80else
81 MY_SED="/usr/bin/gsed"
82fi
83if test "${MY_SOLARIS_VER}" -lt 11; then
84 MY_SCREEN="/opt/csw/bin/screen"
85else
86 MY_SCREEN="screen"
87fi
88
89
90check_for_cifs() {
91 if [ ! -f /usr/kernel/fs/amd64/smbfs -a ! -f /usr/kernel/fs/smbfs -a "${MY_SOLARIS_VER}" -ge 11 ]; then
92 echo "error: smbfs client not installed?" >&2
93 echo "Please install smbfs client support:" >&2
94 echo " pkg install system/file-system/smb" >&2
95 echo " svcadm enable svc:/system/idmap" >&2
96 echo " svcadm enable svc:/network/smb/client" >&2
97 echo " svcs svc:/system/idmap" >&2
98 return 1;
99 fi
100 return 0;
101}
102
103##
104# Loads config values from the current installation.
105#
106os_load_config() {
107 #
108 # Adjust defaults.
109 #
110 # - Use NFS instead of CIFS because S10 doesn't have smbfs and S11 has
111 # problems getting the password.
112 # - Pass the PATH along so we'll find sudo and other stuff later.
113 #
114 TESTBOXSCRIPT_BUILDS_TYPE="nfs"
115 TESTBOXSCRIPT_TESTRSRC_TYPE="nfs"
116 TESTBOXSCRIPT_DEFAULT_BUILDS_TYPE="nfs"
117 TESTBOXSCRIPT_DEFAULT_TESTRSRC_TYPE="nfs"
118 TESTBOXSCRIPT_ENVVARS[${#TESTBOXSCRIPT_ENVVARS[@]}]="PATH=${PATH}";
119
120 # Load old current.
121 if "${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" > /dev/null 2>&1; then
122 # User. ASSUMES single quoted attribs.
123 MY_TMP=`"${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" \
124 | ${MY_TR} '\n' ' ' \
125 `;
126 MY_TMP=`echo "${MY_TMP} " \
127 | ${MY_SED} \
128 -e 's/> */> /g' \
129 -e 's/ *\/>/ \/>/g' \
130 -e 's/^.*<method_credential \([^>]*\) \/>.*$/\1/' \
131 -e "s/^.*user='\([^']*\)'.*\$/\1/" \
132 `;
133 if [ -n "${MY_TMP}" ]; then
134 TESTBOXSCRIPT_USER="${MY_TMP}";
135 fi
136
137 # Arguments. ASSUMES sub-elements. ASSUMES single quoted attribs.
138 XMLARGS=`"${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" \
139 | ${MY_TR} '\n' ' ' \
140 `;
141 case "${XMLARGS}" in
142 *exec_method*)
143 XMLARGS=`echo "${XMLARGS} " \
144 | ${MY_SED} \
145 -e 's/> */> /g' \
146 -e 's/ *\/>/ \/>/g' \
147 -e "s/^.*<exec_method \([^>]*\)name='start'\([^>]*\)>.*\$/\1 \2/" \
148 -e "s/^.*exec='\([^']*\)'.*\$/\1/" \
149 -e 's/&quot;/"/g' \
150 -e 's/&lt;/</g' \
151 -e 's/&gt;/>/g' \
152 -e 's/&amp;/&/g' \
153 | ${MY_SED} \
154 -e 's/^.*testboxscript -d -m *//' \
155 `;
156 eval common_testboxscript_args_to_config ${XMLARGS}
157 ;;
158 *)
159 echo "error: ${MY_SVCCFG}" "export" "${MY_SVC_FMRI} contains no exec_method element." >&2
160 echo " Please delete the service manually and restart setup.sh" >&2
161 exit 2
162 ;;
163 esac
164 fi
165}
166
167##
168# Adds one or more arguments to MY_ARGV after checking them for conformity.
169#
170os_add_args() {
171 while [ $# -gt 0 ];
172 do
173 case "$1" in
174 *\ *)
175 echo "error: Space in option value is not allowed ($1)" >&2
176 exit 1;
177 ;;
178 *${MY_TAB}*)
179 echo "error: Tab in option value is not allowed ($1)" >&2
180 exit 1;
181 ;;
182 *\&*)
183 echo "error: Ampersand in option value is not allowed ($1)" >&2
184 exit 1;
185 ;;
186 *\<*)
187 echo "error: Greater-than in option value is not allowed ($1)" >&2
188 exit 1;
189 ;;
190 *\>*)
191 echo "error: Less-than in option value is not allowed ($1)" >&2
192 exit 1;
193 ;;
194 *)
195 MY_ARGV="${MY_ARGV} $1";
196 ;;
197 esac
198 shift;
199 done
200 return 0;
201}
202
203##
204# Installs, configures and starts the service.
205#
206os_install_service() {
207 # Only NFS for S10.
208 if [ "${MY_SOLARIS_VER}" -lt 11 ]; then
209 if [ "${TESTBOXSCRIPT_BUILDS_TYPE}" != "nfs" -o "${TESTBOXSCRIPT_TESTRSRC_TYPE}" != "nfs" ]; then
210 echo "On solaris 10 both share types must be 'nfs', cifs (smbfs) is not supported." >&2
211 return 1;
212 fi
213 fi
214
215 # Calc the command line.
216 MY_ARGV=""
217 common_compile_testboxscript_command_line
218
219 # Create the service xml config file.
220 cat > "${MY_SVC}" <<EOF
221<?xml version='1.0'?>
222<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
223<service_bundle type='manifest' name='export'>
224 <service name='system/virtualbox/testboxscript' type='service' version='1'>
225 <create_default_instance enabled='false' />
226 <single_instance/>
227
228 <!-- Wait for the network to start up -->
229 <dependency name='milestone-network' grouping='require_all' restart_on='none' type='service'>
230 <service_fmri value='svc:/milestone/network:default' />
231 </dependency>
232
233 <!-- We wish to be started as late as possible... so go crazy with deps. -->
234 <dependency name='milestone-devices' grouping='require_all' restart_on='none' type='service'>
235 <service_fmri value='svc:/milestone/devices:default' />
236 </dependency>
237 <dependency name='multi-user' grouping='require_all' restart_on='none' type='service'>
238 <service_fmri value='svc:/milestone/multi-user:default' />
239 </dependency>
240 <dependency name='multi-user-server' grouping='require_all' restart_on='none' type='service'>
241 <service_fmri value='svc:/milestone/multi-user-server:default' />
242 </dependency>
243 <dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'>
244 <service_fmri value='svc:/system/filesystem/local:default' />
245 </dependency>
246 <dependency name='filesystem-autofs' grouping='require_all' restart_on='none' type='service'>
247 <service_fmri value='svc:/system/filesystem/autofs:default' />
248 </dependency>
249EOF
250 if [ "`uname -r`" = "5.10" ]; then # Seems to be gone in S11?
251 cat >> "${MY_SVC}" <<EOF
252 <dependency name='filesystem-volfs' grouping='require_all' restart_on='none' type='service'>
253 <service_fmri value='svc:/system/filesystem/volfs:default' />
254 </dependency>
255EOF
256 fi
257 cat >> "${MY_SVC}" <<EOF
258 <!-- start + stop methods -->
259 <exec_method type='method' name='start' exec='${MY_SCREEN} -S testboxscript -d -m ${MY_ARGV}'
260 timeout_seconds='30'>
261 <method_context working_directory='${TESTBOXSCRIPT_DIR}'>
262 <method_credential user='${TESTBOXSCRIPT_USER}' />
263 <method_environment>
264 <envvar name='PATH' value='${PATH}' />
265 </method_environment>
266 </method_context>
267 </exec_method>
268
269 <exec_method type='method' name='stop' exec=':kill' timeout_seconds='60' />
270
271 <property_group name='startd' type='framework'>
272 <!-- sub-process core dumps/signals should not restart session -->
273 <propval name='ignore_error' type='astring' value='core,signal' />
274 </property_group>
275
276 <!-- Description -->
277 <template>
278 <common_name>
279 <loctext xml:lang='C'>VirtualBox TestBox Script</loctext>
280 </common_name>
281 </template>
282 </service>
283</service_bundle>
284EOF
285
286 if test "${MY_SOLARIS_VER}" -lt 11; then
287 # Install the service, replacing old stuff.
288 if "${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" > /dev/null 2>&1; then
289 "${MY_SVCCFG}" "delete" "${MY_SVC_FMRI}"
290 fi
291 "${MY_SVCCFG}" "import" "${MY_SVC}"
292
293 # only for solaris version less than 11
294 rm -f "${MY_SVC}"
295 else
296 "${MY_CHGRP}" "sys" "${MY_SVC}"
297 "${MY_SVCADM}" "restart" "manifest-import"
298
299 # Do not remove the xml file in Solaris versions 11 and higher.
300 # The service will be removed automatically, if the command
301 # svcadm restart manifest-import
302 # will be executed
303
304 fi
305 return 0;
306}
307
308os_enable_service() {
309 "${MY_SVCADM}" "enable" "${MY_SVC_FMRI}"
310 return 0;
311}
312
313os_disable_service() {
314 if "${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" > /dev/null 2>&1; then
315 "${MY_SVCADM}" "disable" "${MY_SVC_FMRI}"
316 sleep 1
317 fi
318 return 0;
319}
320
321os_add_user() {
322 useradd -m -s /usr/bin/bash -G staff "${TESTBOXSCRIPT_USER}"
323 passwd "${TESTBOXSCRIPT_USER}" # This sucker prompts, seemingly no way around that.
324 return 0;
325}
326
327
328maybe_hush_up_root_login() {
329 # We don't want /etc/profile to display /etc/motd, quotas and mail status
330 # every time we do sudo -i... It may screw up serious if we parse the
331 # output of the command we sudid.
332 > ~root/.hushlogin
333 return 0;
334}
335
336os_final_message() {
337 cat <<EOF
338
339Additional things to do:"
340 1. Configure NTP:
341 a) echo "server wei01-time.de.oracle.com" > /etc/inet/ntp.conf
342 echo "driftfile /var/ntp/ntp.drift" >> /etc/inet/ntp.conf
343 b) Enable the service: svcadm enable ntp
344 c) Sync once in case of big diff: ntpdate wei01-time.de.oracle.com
345 d) Check that it works: ntpq -p
346
347Enjoy!
348EOF
349}
350
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