1#! /bin/sh
2#
3#         $NetBSD: heimdal2netbsd,v 1.9 2019/12/15 22:50:43 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# heimdal2netbsd:  convert a heimdal source tree into a
30# netbsd heimdal source tree, under src/crypto/external/bsd/heimdal/dist
31# based on bind2netbsd by Bernd Ernesti and changes by Simon Burge
32#
33# Rough instructions for importing new heimdal release from their git
34# repository:
35#
36#         $ export SRCDIR=/usr/src
37#         $ export HEIMDAL_SRCDIR=src/crypto/external/bsd/heimdal
38#         $ cd /some/where/temporary
39#         For HEAD:
40#                   $ git clone git://github.com/heimdal/heimdal.git
41#                   $ sh $SRCDIR/../$HEIMDAL_SRCDIR/heimdal2netbsd heimdal .
42#                   $ cd $HEIMDAL_SRCDIR/dist
43#                   $ cvs -d ... import $HEIMDAL_SRCDIR/dist HEIMDAL head-20110317
44#                   $ cd /some/where/temporary/heimdal
45#                   $ autoreconf -f -i
46#         For release:
47#                   $ ftp https://github.com/heimdal/heimdal/releases/download/\
48#                             heimdal-X.Y.Z/heimdal-X.Y.Z.tar.gz
49#                   $ tar -xzf heimdal-X.Y.Z.tar.gz
50#                   $ sh $SRCDIR/../$HEIMDAL_SRCDIR/heimdal2netbsd heimdal-X-Y-Z .
51#                   $ cd $HEIMDAL_SRCDIR/dist
52#                   $ cvs -d ... import $HEIMDAL_SRCDIR/dist HEIMDAL heimdal-X-Y-Z
53#                   $ cd /some/where/temporary/heimdal
54#         >>> if any conflicts, merge, fix and commit them.
55#         $ ./configure
56#         $ make
57#         >>> merge newly generated config.h
58#         >>> with $HEIMDAL_SRCDIR/include/config.h
59#         >>> and check out diffs in generated headers
60#         >>> and C files.
61#         $ cd ..
62#         $ rm -r src heimdal
63#         $ cd $SRCDIR/$HEIMDAL_SRCDIR
64#         $ cvs commit -m "Updated generated files for Heimdal head-20110317"
65#
66#         - check makefiles to see if any extra sources have been added.
67#         - update distrib/sets if necessary.
68
69prog="$(basename "$0")"
70r=$1
71d=$2/src/crypto/external/bsd/heimdal/dist
72
73if [ $# -ne 2 ]; then echo "${prog} src dest"; exit 1; fi
74
75
76case "$d" in
77          /*)
78                    ;;
79          *)
80                    d="$(pwd)/$d"
81                    ;;
82esac
83
84case "$r" in
85          /*)
86                    ;;
87          *)
88                    r=$(pwd)/$r
89                    ;;
90esac
91
92echo preparing directory $d
93rm -rf $d
94mkdir -p $d
95
96### Copy the files and directories
97echo copying $r to $d
98cd $r
99pax -rw * $d
100
101### Remove unneeded files
102#echo removing unneeded directories and files
103#find $d/po -name '*[0-9] XXX:
104find $d -name '*.cat[0-9]' | xargs rm -f && echo removed catman pages
105find $d -name '*.info' | xargs rm -f     && echo removed info pages
106rm -rf $d/appl                                     && echo removed appl
107rm -rf $d/lib/libedit                              && echo removed lib/libedit
108rm -rf $d/lib/sqlite                               && echo removed lib/sqlite
109rm -rf $d/doc/standardisation            && echo removed doc/standardisation
110
111# Fix man pages
112find $d -type f -name '*.[1358]' -print | while read f; do
113          sed \
114              -e 's,\.Os HEIMDAL,.Os,' \
115              -e 's,\.Pa krb5.h,.Pa krb5/krb5.h,' \
116              -e 's,\.In krb5.h,.In krb5/krb5.h,' \
117              -e 's,\.Pa gssapi.h,.Pa gssapi/gssapi.h,' \
118              -e 's,\.In gssapi.h,.In gssapi/gssapi.h,' \
119              -e 's,#include <krb5.h>,#include <krb5/krb5.h>,' \
120              < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
121          echo fixing man page $f
122done
123
124# Fix include usage
125
126KRB5_INCRE="asn1-common|asn1_err"
127KRB5_INCRE="$KRB5_INCRE|base64"
128KRB5_INCRE="$KRB5_INCRE|cms_asn1"
129KRB5_INCRE="$KRB5_INCRE|com_err"
130KRB5_INCRE="$KRB5_INCRE|com_right"
131KRB5_INCRE="$KRB5_INCRE|crmf_asn1"
132KRB5_INCRE="$KRB5_INCRE|der|der-protos"
133KRB5_INCRE="$KRB5_INCRE|digest_asn1"
134KRB5_INCRE="$KRB5_INCRE|getarg"
135KRB5_INCRE="$KRB5_INCRE|hdb|hdb_err|hdb-protos|hdb_asn1"
136KRB5_INCRE="$KRB5_INCRE|heim_asn1|heim_err"
137KRB5_INCRE="$KRB5_INCRE|heimbase"
138KRB5_INCRE="$KRB5_INCRE|heimntlm|heimntlm-protos"
139KRB5_INCRE="$KRB5_INCRE|hex"
140KRB5_INCRE="$KRB5_INCRE|hx509|hx509-protos|hx509_err"
141KRB5_INCRE="$KRB5_INCRE|k524_err"
142KRB5_INCRE="$KRB5_INCRE|kafs"
143KRB5_INCRE="$KRB5_INCRE|kcm|kcm-protos"
144KRB5_INCRE="$KRB5_INCRE|kdc|kdc-protos"
145KRB5_INCRE="$KRB5_INCRE|krb5|krb5-private|krb5-protos|krb5-types"
146KRB5_INCRE="$KRB5_INCRE|krb5_asn1|krb5_err|krb5_ccapi"
147KRB5_INCRE="$KRB5_INCRE|krb5-v4compat"
148KRB5_INCRE="$KRB5_INCRE|krb_err"
149KRB5_INCRE="$KRB5_INCRE|kx509_asn1"
150KRB5_INCRE="$KRB5_INCRE|ntlm_err"
151KRB5_INCRE="$KRB5_INCRE|ocsp_asn1"
152KRB5_INCRE="$KRB5_INCRE|parse_bytes|parse_time|parse_units"
153KRB5_INCRE="$KRB5_INCRE|pkcs8_asn1|pkcs9_asn1|pkcs10_asn1|pkcs12_asn1"
154KRB5_INCRE="$KRB5_INCRE|pkinit_asn1"
155KRB5_INCRE="$KRB5_INCRE|resolve"
156KRB5_INCRE="$KRB5_INCRE|rfc2459_asn1"
157KRB5_INCRE="$KRB5_INCRE|roken|roken-common"
158KRB5_INCRE="$KRB5_INCRE|rtbl"
159KRB5_INCRE="$KRB5_INCRE|sl|ss"
160KRB5_INCRE="$KRB5_INCRE|wind|wind_err"
161KRB5_INCRE="$KRB5_INCRE|xdbm"
162
163GSS_INCRE="gssapi|gssapi_krb5|gssapi_spnego|gssapi_ntlm|gssapi_oid"
164
165KADM5_INCRE="admin|kadm5-protos|kadm5-pwcheck|kadm5_err"
166
167find $d -type f -name '*.[ch]' -a ! -name compile_et.? -print | while read f; do
168          sed -E \
169              -e "s,#include <($GSS_INCRE)\\.h>,#include <gssapi/\\1.h>,"          \
170              -e "s,#include \"($KRB5_INCRE)\\.h\",#include <krb5/\\1.h>,"   \
171              -e "s,#include <($KRB5_INCRE)\\.h>,#include <krb5/\\1.h>,"           \
172              -e "s,#include <($KADM5_INCRE)\\.h>,#include <kadm5/\\1.h>,"   \
173              < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
174          echo fixing include paths in $f
175done
176
177#
178# In these files, we want only to fix the paths in the generated files, not
179# in the file itself.  To do this, we search for "#include meaning that
180# it can't be on the left column.
181
182for f in $d/lib/sl/slc-gram.y $d/lib/com_err/compile_et.c; do
183          sed -E -e "s,(.#include <)($KRB5_INCRE)\\.h>,\\1krb5/\\2.h>," \
184              < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
185          echo fixing include paths in $f
186done
187
188# Freeze imported NetBSD RCSID's.
189find $d -type f -print | xargs egrep -l '\$NetBSD:' | while read f; do
190          sed \
191              -e 's/\$\(NetBSD.*\) \$/\1/' \
192              < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
193          echo froze NetBSD RCSID for $f
194done
195
196### Remove the $'s around RCS tags
197cleantags $d
198
199# Convert unexpanded RCSID's to the NetBSD way.
200find $d -type f -print | xargs egrep -l 'RCSID\("Id"\)' | while read f; do
201          sed -e 's/RCSID("Id")/__RCSID("\$NetBSD\$")/' \
202              < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
203          echo converted RCSID to NetBSD for $f
204done
205
206### Add our NetBSD RCS Id
207find $d -type f -name '*.[chly]' -print | while read c; do
208          sed 1q < $c | grep -q '\$NetBSD' || (
209echo "/*  \$NetBSD\$          */" >/tmp/${prog}3n$$
210echo "" >>/tmp/${prog}3n$$
211cat $c  >> /tmp/${prog}3n$$
212mv /tmp/${prog}3n$$ $c && echo added NetBSD RCS tag to $c
213          )
214done
215
216find $d -type f -name '*.[0-9]' -print | while read m; do
217          sed 1q < $m | grep -q '\$NetBSD' || (
218echo ".\\\"         \$NetBSD\$" >/tmp/${prog}2m$$
219echo ".\\\"" >>/tmp/${prog}2m$$
220cat $m >> /tmp/${prog}2m$$
221mv /tmp/${prog}2m$$ $m && echo added NetBSD RCS tag to $m
222          )
223done
224
225find $d -type f -name '*.texi' -print | while read t; do
226        sed "2 s/^/@c \$NetBSD\$\\
227/" < $t > /tmp/${prog}4t$$
228          mv /tmp/${prog}4t$$ $t && echo added NetBSD RCS tag to $t
229done
230
231echo done
232
233### Clean up any CVS directories that might be around.
234echo "cleaning up CVS residue."
235(
236          cd $d
237          find . -type d -name "CVS" -print | xargs rm -r
238)
239echo done
240
241echo "cleaning up git residue."
242rm -rf $d/.git
243
244### Fixing file and directory permissions.
245echo "Fixing file/directory permissions."
246(
247          cd $d
248          find . -type f -print | xargs chmod u+rw,go+r
249          find . -type d -print | xargs chmod u+rwx,go+rx
250)
251echo done
252
253exit 0
254