1#! /bin/sh
2#
3#	$NetBSD: openpam2netbsd,v 1.1 2011/12/25 23:18:56 christos Exp $
4#
5# Copyright (c) 2011 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# openpam2netbsd:  convert an openpam source tree into a
30# netbsd openp source tree, under src/dist,
31#
32# Rough instructions for importing new openp release:
33#
34#	$ cd /some/where/temporary
35#	$ tar xpfz /new/openpam/release/tar/file
36#	$ sh /usr/src/external/bsd/openpam/openp2netbsd openpam-YYYYMMDD
37#	$ cd openpam-YYYYMMDD
38#	$ cvs -d cvs.netbsd.org:/cvsroot import -m "Import openpam-YYYYMMDD" src/external/bsd/openpam/dist OPENPAM flower-YYYYMMDD
39#	$ cd ../../../am-utils-6.x.y
40#	$ run ./configure
41# merge newly generated config.h with /usr/src/usr.sbin/openp/include/config.h
42# very carefully, since autoconfig seems to be broken (at least in 6.0.4)
43#	$ cd ..
44#	$ rm -r src am-utils-6.x.y
45#	$ cd /usr/src/usr.sbin/openp
46#	$ cvs commit -m "Updated autoconf generated files for am-utils 6.x.y."
47#
48#	- check makefiles to see if any extra sources have been added.
49#	- update distrib/sets if necessary.
50
51if [ $# -ne 1 ]; then echo "openp2netbsd src"; exit 1; fi
52
53r=$1
54case "$r" in
55	/*)
56		;;
57	*)
58		r=`/bin/pwd`/$r
59		;;
60esac
61
62cd $r
63
64### Remove the $'s around RCS tags
65cleantags $r
66
67### Add our NetBSD RCS Id
68find $r -type f -name '*.[chly]' -print | while read c; do
69	sed 1q < $c | grep -q '\$NetBSD' || (
70echo "/*	\$NetBSD\$	*/" >/tmp/openp3n$$
71echo "" >>/tmp/openp3n$$
72cat $c  >> /tmp/openp3n$$
73mv /tmp/openp3n$$ $c && echo added NetBSD RCS tag to $c
74	)
75done
76
77find $r -type f -name '*.[0-9]' -print | while read m; do
78	sed 1q < $m | grep -q '\$NetBSD' || (
79echo ".\\\"	\$NetBSD\$" >/tmp/openp2m$$
80echo ".\\\"" >>/tmp/openp2m$$
81cat $m >> /tmp/openp2m$$
82mv /tmp/openp2m$$ $m && echo added NetBSD RCS tag to $m
83	)
84done
85
86find $r -type f -name '*.texi' -print | while read t; do
87        sed "2 s/^/@c \$NetBSD\$\\
88/" < $t > /tmp/openp4t$$
89	mv /tmp/openp4t$$ $t && echo added NetBSD RCS tag to $t
90done
91
92echo done
93
94### Clean up any CVS directories that might be around.
95echo "cleaning up CVS residue."
96find $r -type d -name "CVS" -print | xargs rm -r
97echo done
98
99### Fixing file and directory permissions.
100echo "Fixing file/directory permissions."
101(
102	find $r -type f -print | xargs chmod u+rw,go+r
103	find $r -type d -print | xargs chmod u+rwx,go+rx
104)
105echo done
106
107exit 0
108