1#! /bin/sh
2#
3#	$NetBSD: netbsd-import.sh,v 1.3 2008/04/30 13:10:46 martin Exp $
4#
5# Copyright (c) 2000-2005 The NetBSD Foundation, Inc.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29# netbsd-import: prepare ipsec-tools distribution for import 
30# in the NetBSD tree, under src/crypto/dist/ipsec-tools
31# Based on bind2netbsd.
32#
33# Instructions for importing a newer ipsec-tools release:
34#
35#	$ tag=ipsec-tools-0_6-20050224
36#	$ cd /tmp
37#	$ cvs -danoncvs@cvs.sf.net:/cvsroot/ipsec-tools co -r $tag ipsec-tools
38#	$ cd ipsec-tools
39#	$ /usr/src/crypto/dist/ipsec-tools/netbsd-import.sh $tag `pwd` /usr/src
40#	$ cvs -d`whoami`@cvs.netbsd.org:/cvsroot import -m 	\
41#	  "Import ipsec-tools $tag" src/crypto/dist/ipsec-tools \
42#	  IPSEC_TOOLS $tag
43#	$ cd /usr/src/lib/libipsec
44#	$ cvs -d`whoami`@cvs.netbsd.org:/cvsroot commit -m 	\
45#	  "update ipsec-tools version" package_version.h 
46#
47
48test $# -ne 3 && 							\
49    echo "usage: netbsd-import.sh tag ipsec-tools-src netbsdsrc" &&	\
50    exit
51
52SCRIPTNAME=$0
53RELEASE=`echo $1|sed 's/^ipsec-tools-//; s/_/\./'`
54DISTSRC=$2
55NETBSDSRC=$3
56
57### Remove CVS directories and .cvsignore files
58find ${DISTSRC} -type d -name CVS -print | while read d ; do 		\
59    rm -R $d && echo "removed $d" ;					\
60done
61find ${DISTSRC} -type f -name .cvsignore -print | while read f ; do	\
62    rm $f && echo "removed $f" ;					\
63done
64
65### Remove the $'s around RCS tags
66find ${DISTSRC} -type f -print | 				\
67    xargs egrep -l '\$(Id|Created|Header)' | while read f; do
68	sed -e 's/\$\(Id.*\) \$/\1/' \
69	    -e 's/\$\(Created.*\) \$/\1/' \
70	    -e 's/\$\(Header.*\) \$/\1/' \
71	    < $f > /tmp/ipsec1f$$ && mv /tmp/ipsec1f$$ $f && \
72	echo "removed \$RCS tag from $f"
73done
74
75### Add our NetBSD RCS Id
76find ${DISTSRC}  -type f -name '*.[chly]' -print | while read c; do
77	sed 1q < $c | grep -q '\$NetBSD' || (
78echo "/*	\$NetBSD\$	*/" >/tmp/ipsec3n$$
79echo "" >>/tmp/ipsec3n$$
80cat $c  >> /tmp/ipsec3n$$
81mv /tmp/ipsec3n$$ $c && echo "added NetBSD RCS tag to $c"
82	)
83done
84
85find ${DISTSRC} -type f -name '*.[0-9]' -print | while read m; do
86	sed 1q < $m | grep -q '\$NetBSD' || (
87echo ".\\\"	\$NetBSD\$" >/tmp/ipsec2m$$
88echo ".\\\"" >>/tmp/ipsec2m$$
89cat $m >> /tmp/ipsec2m$$
90mv /tmp/ipsec2m$$ $m && echo "added NetBSD RCS tag to $m"
91	)
92done
93
94sed "									\
95    s/^\(#define TOP_PACKAGE_VERSION \).*/\1 \"${RELEASE}\"/;		\
96    s/^\(#define TOP_PACKAGE_STRING \).*/\1 \"ipsec-tools ${RELEASE}\"/;\
97" ${NETBSDSRC}/lib/libipsec/package_version.h > /tmp/ipsec5		
98mv /tmp/ipsec5 ${NETBSDSRC}/lib/libipsec/package_version.h &&		\
99    echo "Updated version in lib/libipsec/package_version.h"
100
101cp ${SCRIPTNAME} ${DISTSRC} && echo "copied ${SCRIPTNAME} to ${DISTSRC}" 
102
103echo "done, don't forget to cvs commit src/lib/libipsec/package_version.h"
104
105