VirtualBox

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

Last change on this file since 60422 was 56295, checked in by vboxsync, 10 years ago

ValidationKit: Updated (C) year.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 KB
Line 
1# $Id: setup-routines.sh 56295 2015-06-09 14:29:55Z vboxsync $
2## @file
3# VirtualBox Validation Kit - TestBoxScript Service Setup on Solaris.
4#
5
6#
7# Copyright (C) 2006-2015 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}" -a -f "/opt/csw/etc/sudoers" ]; then
45 MY_ETC_SUDOERS=/opt/csw/etc/sudoers # Sudo isn't standard on S10.
46fi
47
48#
49# Solaris variables.
50#
51MY_SVC_TMP="/tmp/testboxscript.xml"
52MY_SVC_FMRI="svc:/system/virtualbox/testboxscript"
53MY_SVCCFG="/usr/sbin/svccfg"
54MY_SVCADM="/usr/sbin/svcadm"
55MY_TR="/usr/bin/tr"
56MY_TAB=`printf "\t"`
57if test "${MY_SOLARIS_VER}" -lt 11; then ## No gsed on S10?? ARG!
58 MY_SED="/usr/xpg4/bin/sed"
59else
60 MY_SED="/usr/bin/gsed"
61fi
62if test "${MY_SOLARIS_VER}" -lt 11; then
63 MY_SCREEN="/opt/csw/bin/screen"
64else
65 MY_SCREEN="screen"
66fi
67
68
69check_for_cifs() {
70 if [ ! -f /usr/kernel/fs/amd64/smbfs -a ! -f /usr/kernel/fs/smbfs -a "${MY_SOLARIS_VER}" -ge 11 ]; then
71 echo "error: smbfs client not installed?" >&2
72 echo "Please install smbfs client support:" >&2
73 echo " pkg install system/file-system/smb" >&2
74 echo " svcadm enable svc:/system/idmap" >&2
75 echo " svcadm enable svc:/network/smb/client" >&2
76 echo " svcs svc:/system/idmap" >&2
77 return 1;
78 fi
79 return 0;
80}
81
82##
83# Checks for a boolean option pair --$2/--no-$2 in the XMLARGS variable,
84# storing the result in the TESTBOXSCRIPT_XXX variable $1.
85solaris_check_for_option_bool() {
86 MY_TMP=`echo "${XMLARGS} " | ${MY_SED} -ne "s/^.*[ \"]--$2[ \"].*\$/yes/p"`
87 if [ -n "${MY_TMP}" ]; then
88 eval $1="yes";
89 fi
90 MY_TMP=`echo "${XMLARGS} " | ${MY_SED} -ne "s/^.*[ \"]--no-$2[ \"].*\$/yes/p"`
91 if [ -n "${MY_TMP}" ]; then
92 eval $1="no";
93 fi
94 return 0;
95}
96
97##
98# Checks for an option $2 taking an argument, storing the result in the
99# TESTBOXSCRIPT_XXX variable $1.
100solaris_check_for_option_arg() {
101 # ASSUMES no quoted option values nor any escaped spaces.
102 MY_TMP=`echo "${XMLARGS} " | ${MY_SED} -ne "s/^.*[ \"]--$2 *\([^ \"]*\)[ \"].*\$/\1/p"`
103 if [ -n "${MY_TMP}" ]; then
104 eval $1="\"${MY_TMP}\"";
105 fi
106 return 0;
107}
108
109##
110# Loads config values from the current installation.
111#
112os_load_config() {
113 #
114 # Adjust defaults.
115 #
116 # - Use NFS instead of CIFS because S10 doesn't have smbfs and S11 has
117 # problems getting the password.
118 # - Pass the PATH along so we'll find sudo and other stuff later.
119 #
120 TESTBOXSCRIPT_BUILDS_TYPE="nfs"
121 TESTBOXSCRIPT_TESTRSRC_TYPE="nfs"
122 TESTBOXSCRIPT_ENVVARS[${#TESTBOXSCRIPT_ENVVARS[@]}]="PATH=${PATH}";
123
124 # Load old current.
125 if "${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" > /dev/null 2>&1; then
126 # User. ASSUMES single quoted attribs.
127 MY_TMP=`"${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" \
128 | ${MY_TR} '\n' ' ' \
129 `;
130 MY_TMP=`echo "${MY_TMP} " \
131 | ${MY_SED} \
132 -e 's/> */> /g' \
133 -e 's/ *\/>/ \/>/g' \
134 -e 's/^.*<method_credential \([^>]*\) \/>.*$/\1/' \
135 -e "s/^.*user='\([^']*\)'.*\$/\1/" \
136 `;
137 if [ -n "${MY_TMP}" ]; then
138 TESTBOXSCRIPT_USER="${MY_TMP}";
139 fi
140
141 # Arguments. ASSUMES sub-elements. ASSUMES single quoted attribs.
142 XMLARGS=`"${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" \
143 | ${MY_TR} '\n' ' ' \
144 `;
145 XMLARGS=`echo "${XMLARGS} " \
146 | ${MY_SED} \
147 -e 's/> */> /g' \
148 -e 's/ *\/>/ \/>/g' \
149 -e "s/^.*<exec_method \([^>]*\)name='start'\([^>]*\)>.*\$/\1 \2/" \
150 -e "s/^.*exec='\([^']*\)'.*\$/\1/" \
151 -e 's/&quot;/"/g' \
152 -e 's/&lt;/</g' \
153 -e 's/&gt;/>/g' \
154 -e 's/&amp;/&/g' \
155 `;
156
157 solaris_check_for_option_arg TESTBOXSCRIPT_SYSTEM_UUID system-uuid
158 solaris_check_for_option_arg TESTBOXSCRIPT_SCRATCH_ROOT scratch-root
159 solaris_check_for_option_arg TESTBOXSCRIPT_TEST_MANAGER test-manager
160 solaris_check_for_option_bool TESTBOXSCRIPT_HWVIRT hwvirt
161 solaris_check_for_option_bool TESTBOXSCRIPT_NESTED_PAGING nested-paging
162 solaris_check_for_option_bool TESTBOXSCRIPT_IOMMU io-mmu
163 solaris_check_for_option_arg TESTBOXSCRIPT_BUILDS_PATH builds-path
164 solaris_check_for_option_arg TESTBOXSCRIPT_BUILDS_TYPE builds-server-type
165 solaris_check_for_option_arg TESTBOXSCRIPT_BUILDS_NAME builds-server-name
166 solaris_check_for_option_arg TESTBOXSCRIPT_BUILDS_SHARE builds-server-share
167 solaris_check_for_option_arg TESTBOXSCRIPT_BUILDS_USER builds-server-user
168 solaris_check_for_option_arg TESTBOXSCRIPT_BUILDS_PASSWD builds-server-passwd
169 solaris_check_for_option_arg TESTBOXSCRIPT_TESTRSRC_PATH testrsrc-path
170 solaris_check_for_option_arg TESTBOXSCRIPT_TESTRSRC_TYPE testrsrc-server-type
171 solaris_check_for_option_arg TESTBOXSCRIPT_TESTRSRC_NAME testrsrc-server-name
172 solaris_check_for_option_arg TESTBOXSCRIPT_TESTRSRC_SHARE testrsrc-server-share
173 solaris_check_for_option_arg TESTBOXSCRIPT_TESTRSRC_USER testrsrc-server-user
174 solaris_check_for_option_arg TESTBOXSCRIPT_TESTRSRC_PASSWD testrsrc-server-passwd
175
176 ## @TODO solaris_check_for_option_arg TESTBOXSCRIPT_PYTHON python
177 ## @TODO solaris_check_for_option_arg TESTBOXSCRIPT_ENVVARS putenv - Multiple occurences possible.
178 fi
179}
180
181##
182# Adds one or more arguments to MY_ARGV after checking them for conformity.
183#
184solaris_add_args() {
185 while [ $# -gt 0 ];
186 do
187 case "$1" in
188 *\ *)
189 echo "error: Space in option value is not allowed ($1)" >&2
190 exit 1;
191 ;;
192 *${MY_TAB}*)
193 echo "error: Tab in option value is not allowed ($1)" >&2
194 exit 1;
195 ;;
196 *\&*)
197 echo "error: Ampersand in option value is not allowed ($1)" >&2
198 exit 1;
199 ;;
200 *\<*)
201 echo "error: Greater-than in option value is not allowed ($1)" >&2
202 exit 1;
203 ;;
204 *\>*)
205 echo "error: Less-than in option value is not allowed ($1)" >&2
206 exit 1;
207 ;;
208 *)
209 MY_ARGV="${MY_ARGV} $1";
210 ;;
211 esac
212 shift;
213 done
214 return 0;
215}
216
217##
218# Installs, configures and starts the service.
219#
220os_install_service() {
221 # Only NFS for S10.
222 if [ "${MY_SOLARIS_VER}" -lt 11 ]; then
223 if [ "${TESTBOXSCRIPT_BUILDS_TYPE}" != "nfs" -o "${TESTBOXSCRIPT_TESTRSRC_TYPE}" != "nfs" ]; then
224 echo "On solaris 10 both share types must be 'nfs', cifs (smbfs) is not supported." >&2
225 return 1;
226 fi
227 fi
228
229 # Calc the command line.
230 MY_ARGV=""
231 if [ -n "${TESTBOXSCRIPT_PYTHON}" ]; then
232 solaris_add_args "${TESTBOXSCRIPT_PYTHON}"
233 fi
234 solaris_add_args "${TESTBOXSCRIPT_DIR}/testboxscript/testboxscript.py"
235
236 if [ "${TESTBOXSCRIPT_HWVIRT}" = "yes" ]; then solaris_add_args "--hwvirt"; fi
237 if [ "${TESTBOXSCRIPT_HWVIRT}" = "no" ]; then solaris_add_args "--no-hwvirt"; fi
238 if [ "${TESTBOXSCRIPT_NESTED_PAGING}" = "yes" ]; then solaris_add_args "--nested-paging"; fi
239 if [ "${TESTBOXSCRIPT_NESTED_PAGING}" = "no" ]; then solaris_add_args "--no-nested-paging"; fi
240 if [ "${TESTBOXSCRIPT_IOMMU}" = "yes" ]; then solaris_add_args "--io-mmu"; fi
241 if [ "${TESTBOXSCRIPT_IOMMU}" = "no" ]; then solaris_add_args "--no-io-mmu"; fi
242 if [ -n "${TESTBOXSCRIPT_SYSTEM_UUID}" ]; then solaris_add_args "--system-uuid" "${TESTBOXSCRIPT_SYSTEM_UUID}"; fi
243 if [ -n "${TESTBOXSCRIPT_TEST_MANAGER}" ]; then solaris_add_args "--test-manager" "${TESTBOXSCRIPT_TEST_MANAGER}"; fi
244 if [ -n "${TESTBOXSCRIPT_SCRATCH_ROOT}" ]; then solaris_add_args "--scratch-root" "${TESTBOXSCRIPT_SCRATCH_ROOT}"; fi
245
246 if [ -n "${TESTBOXSCRIPT_BUILDS_PATH}" ]; then solaris_add_args "--builds-path" "${TESTBOXSCRIPT_BUILDS_PATH}"; fi
247 if [ -n "${TESTBOXSCRIPT_BUILDS_TYPE}" ]; then solaris_add_args "--builds-server-type" "${TESTBOXSCRIPT_BUILDS_TYPE}"; fi
248 if [ -n "${TESTBOXSCRIPT_BUILDS_NAME}" ]; then solaris_add_args "--builds-server-name" "${TESTBOXSCRIPT_BUILDS_NAME}"; fi
249 if [ -n "${TESTBOXSCRIPT_BUILDS_SHARE}" ]; then solaris_add_args "--builds-server-share" "${TESTBOXSCRIPT_BUILDS_SHARE}"; fi
250 if [ -n "${TESTBOXSCRIPT_BUILDS_USER}" ]; then solaris_add_args "--builds-server-user" "${TESTBOXSCRIPT_BUILDS_USER}"; fi
251 if [ -n "${TESTBOXSCRIPT_BUILDS_PASSWD}" ]; then solaris_add_args "--builds-server-passwd" "${TESTBOXSCRIPT_BUILDS_PASSWD}"; fi
252 if [ -n "${TESTBOXSCRIPT_TESTRSRC_PATH}" ]; then solaris_add_args "--testrsrc-path" "${TESTBOXSCRIPT_PATH_TESTRSRC}"; fi
253 if [ -n "${TESTBOXSCRIPT_TESTRSRC_TYPE}" ]; then solaris_add_args "--testrsrc-server-type" "${TESTBOXSCRIPT_TESTRSRC_TYPE}"; fi
254 if [ -n "${TESTBOXSCRIPT_TESTRSRC_NAME}" ]; then solaris_add_args "--testrsrc-server-name" "${TESTBOXSCRIPT_TESTRSRC_NAME}"; fi
255 if [ -n "${TESTBOXSCRIPT_TESTRSRC_SHARE}" ]; then solaris_add_args "--testrsrc-server-share" "${TESTBOXSCRIPT_TESTRSRC_SHARE}"; fi
256 if [ -n "${TESTBOXSCRIPT_TESTRSRC_USER}" ]; then solaris_add_args "--testrsrc-server-user" "${TESTBOXSCRIPT_TESTRSRC_USER}"; fi
257 if [ -n "${TESTBOXSCRIPT_TESTRSRC_PASSWD}" ]; then solaris_add_args "--testrsrc-server-passwd" "${TESTBOXSCRIPT_TESTRSRC_PASSWD}"; fi
258 i=0
259 while [ "${i}" -lt "${#TESTBOXSCRIPT_ENVVARS[@]}" ];
260 do
261 solaris_add_args "--putenv" "${TESTBOXSCRIPT_ENVVARS[${i}]}"
262 i=$((${i} + 1))
263 done
264
265 # Create the service xml config file.
266 cat > "${MY_SVC_TMP}" <<EOF
267<?xml version='1.0'?>
268<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
269<service_bundle type='manifest' name='export'>
270 <service name='system/virtualbox/testboxscript' type='service' version='1'>
271 <create_default_instance enabled='false' />
272 <single_instance/>
273
274 <!-- Wait for the network to start up -->
275 <dependency name='milestone-network' grouping='require_all' restart_on='none' type='service'>
276 <service_fmri value='svc:/milestone/network:default' />
277 </dependency>
278
279 <!-- We wish to be started as late as possible... so go crazy with deps. -->
280 <dependency name='milestone-devices' grouping='require_all' restart_on='none' type='service'>
281 <service_fmri value='svc:/milestone/devices:default' />
282 </dependency>
283 <dependency name='multi-user' grouping='require_all' restart_on='none' type='service'>
284 <service_fmri value='svc:/milestone/multi-user:default' />
285 </dependency>
286 <dependency name='multi-user-server' grouping='require_all' restart_on='none' type='service'>
287 <service_fmri value='svc:/milestone/multi-user-server:default' />
288 </dependency>
289 <dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'>
290 <service_fmri value='svc:/system/filesystem/local:default' />
291 </dependency>
292 <dependency name='filesystem-autofs' grouping='require_all' restart_on='none' type='service'>
293 <service_fmri value='svc:/system/filesystem/autofs:default' />
294 </dependency>
295EOF
296 if [ "`uname -r`" = "5.10" ]; then # Seems to be gone in S11?
297 cat >> "${MY_SVC_TMP}" <<EOF
298 <dependency name='filesystem-volfs' grouping='require_all' restart_on='none' type='service'>
299 <service_fmri value='svc:/system/filesystem/volfs:default' />
300 </dependency>
301EOF
302 fi
303 cat >> "${MY_SVC_TMP}" <<EOF
304 <!-- start + stop methods -->
305 <exec_method type='method' name='start' exec='${MY_SCREEN} -S testboxscript -d -m ${MY_ARGV}'
306 timeout_seconds='30'>
307 <method_context working_directory='${TESTBOXSCRIPT_DIR}'>
308 <method_credential user='${TESTBOXSCRIPT_USER}' />
309 <method_environment>
310 <envvar name='PATH' value='${PATH}' />
311 </method_environment>
312 </method_context>
313 </exec_method>
314
315 <exec_method type='method' name='stop' exec=':kill' timeout_seconds='60' />
316
317 <property_group name='startd' type='framework'>
318 <!-- sub-process core dumps/signals should not restart session -->
319 <propval name='ignore_error' type='astring' value='core,signal' />
320 </property_group>
321
322 <!-- Description -->
323 <template>
324 <common_name>
325 <loctext xml:lang='C'>VirtualBox TestBox Script</loctext>
326 </common_name>
327 </template>
328 </service>
329</service_bundle>
330EOF
331
332 # Install the service, replacing old stuff.
333 if "${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" > /dev/null 2>&1; then
334 "${MY_SVCCFG}" "delete" "${MY_SVC_FMRI}"
335 fi
336 "${MY_SVCCFG}" "import" "${MY_SVC_TMP}"
337 rm -f "${MY_SVC_TMP}"
338 return 0;
339}
340
341os_enable_service() {
342 "${MY_SVCADM}" "enable" "${MY_SVC_FMRI}"
343 return 0;
344}
345
346os_disable_service() {
347 if "${MY_SVCCFG}" "export" "${MY_SVC_FMRI}" > /dev/null 2>&1; then
348 "${MY_SVCADM}" "disable" "${MY_SVC_FMRI}"
349 sleep 1
350 fi
351 return 0;
352}
353
354os_add_user() {
355 useradd -m -s /usr/bin/bash -G staff "${TESTBOXSCRIPT_USER}"
356 passwd "${TESTBOXSCRIPT_USER}" # This sucker prompts, seemingly no way around that.
357 return 0;
358}
359
360
361maybe_hush_up_root_login() {
362 # We don't want /etc/profile to display /etc/motd, quotas and mail status
363 # every time we do sudo -i... It may screw up serious if we parse the
364 # output of the command we sudid.
365 > ~root/.hushlogin
366 return 0;
367}
368
369os_final_message() {
370 cat <<EOF
371
372Additional things to do:"
373 1. Configure NTP:
374 a) echo "server wei01-time.de.oracle.com" > /etc/inet/ntp.conf
375 echo "driftfile /var/ntp/ntp.drift" >> /etc/inet/ntp.conf
376 b) Enable the service: svcadm enable ntp
377 c) Sync once in case of big diff: ntpdate wei01-time.de.oracle.com
378 d) Check that it works: ntpq -p
379
380Enjoy!
381EOF
382}
383
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