1# vim: filetype=sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)migration.kshlib	1.2	07/01/09 SMI"
30#
31
32#
33# This function creates the test archive for migration.
34#
35# Usage:
36# prepare srcdir cmd
37#
38# Return value: 0 on success
39#		1 on failure
40#
41# Where:
42#	srcdir: is the directory where the testfile is
43#	cmd:	is the command to be executed.
44#		E.g.
45#		$TAR cf $TESTDIR/tar${TESTCASE_ID}.tar
46#
47function prepare #srcdir cmd
48{
49	typeset srcdir=$1
50	typeset cmd=$2
51	typeset -i retval=0
52
53	cwd=$PWD
54	cd $srcdir
55	(( $? != 0 )) && return 1
56
57	$cmd
58	(( $? != 0 )) && return 1
59
60	cd $cwd
61	(( $? != 0 )) && return 1
62
63	return 0
64}
65
66#
67# This function executes a passed in command and then determines the chksum
68# of the resulting file.  The chksum components are checked against the ones
69# passed in to determine if they are equal.  If they are equal, 0 is returned
70# otherwise 1 is returned.
71#
72# Usage:
73# migrate destdir oldsuma oldsumb command_to_execute
74#
75# Return value: 0 on success
76#		1 on failure
77#
78# Where:
79#	destdir: is the directory where the command is to be executed on
80#	oldsuma: is the first part of the values returned by sum
81#	oldsumb: is the second part of the values returned by sum
82#	cmd: is the command to be executed;
83#		E.g.
84#		"$TAR xf $TESTDIR/tar${TESTCASE_ID}.tar"
85#
86function migrate #destdir oldsuma oldsumb cmd
87{
88	typeset destdir=$1
89	typeset oldsuma=$2
90	typeset oldsumb=$3
91	typeset cmd=$4
92	typeset -i retval=0
93
94	cwd=$PWD
95	cd $destdir
96	(( $? != 0 )) && return 1
97
98	$cmd
99	(( $? != 0 )) && return 1
100
101	sumy=`$SUM ./$BNAME`
102	suma=`$ECHO $sumy | $AWK '{print $1}'`
103	sumb=`$ECHO $sumy | $AWK '{print $2}'`
104
105	if (( $oldsuma != $suma )); then
106		log_note "$SUM values are not the same"
107		retval=1
108	fi
109
110	if (( $oldsumb != $sumb )); then
111		log_note "$SUM values are not the same"
112		retval=1
113	fi
114
115	cd $cwd
116	(( $? != 0 )) && return 1
117	return $retval
118}
119
120function migrate_cpio
121{
122	typeset destdir=$1
123	typeset archive=$2
124	typeset oldsuma=$3
125	typeset oldsumb=$4
126	typeset -i retval=0
127
128	cwd=$PWD
129	cd $destdir
130	(( $? != 0 )) && return 1
131
132	$CPIO -iv < $archive
133	(( $? != 0 )) && return 1
134
135	sumy=`$SUM ./$BNAME`
136	suma=`$ECHO $sumy | $AWK '{print $1}'`
137	sumb=`$ECHO $sumy | $AWK '{print $2}'`
138
139	if (( $oldsuma != $suma )); then
140		log_note "$SUM values are not the same"
141		retval=1
142	fi
143
144	if (( $oldsumb != $sumb )); then
145		log_note "$SUM values are not the same"
146		retval=1
147	fi
148
149	cd $cwd
150	(( $? != 0 )) && return 1
151	return $retval
152}
153