11.1Sdholland#!/bin/sh 21.1Sdholland# nfs2netbsd - arrange bits of (FreeBSD's) newnfs code for importing 31.1Sdholland# usage: nfs2netbsd FREEBSDSYSDIR 41.1Sdholland# 51.1Sdholland# Caution: unlike most of the *2netbsd scripts in the tree, this copies 61.1Sdholland# from another dir (which should be the sys/ dir from a FreeBSD checkout) 71.1Sdholland# rather than operating on a tree already in the current directory. 81.1Sdholland# 91.1Sdholland# The current directory should be empty. 101.1Sdholland# 111.1Sdholland# $NetBSD: nfs2netbsd.sh,v 1.1 2013/09/30 07:23:37 dholland Exp $ 121.1Sdholland 131.1SdhollandFTOP="$1" 141.1Sdholland 151.1Sdhollandif [ $# != 1 ]; then 161.1Sdholland echo "$0: usage: $0 freebsdsysdir" 1>&2 171.1Sdholland exit 1 181.1Sdhollandfi 191.1Sdholland 201.1Sdhollandif [ ! -d "$FTOP" ]; then 211.1Sdholland echo "$0: $FTOP: not found" 1>&2 221.1Sdholland exit 1 231.1Sdhollandfi 241.1Sdholland 251.1Sdholland############################################################ 261.1Sdholland# 1. Get the list of files. 271.1Sdholland 281.1Sdholland# Note that we don't (for now anyway) take rpc/* and xdr/*. 291.1Sdholland 301.1SdhollandFILES=$(egrep -w 'nfscl|nfsd' "$FTOP"/conf/files | awk '{ print $1 }' |\ 311.1Sdholland sed '/^rpc\//d;/^xdr\//d') 321.1Sdholland 331.1SdhollandDIRS=$(echo "$FILES" | sed 's,/[^/*]*$,,' | sort -u) 341.1Sdholland 351.1SdhollandMOREFILES=$(cd "$FTOP" && find $DIRS -name '*.h' -print) 361.1Sdholland 371.1SdhollandFILES="$FILES $MOREFILES" 381.1Sdholland 391.1Sdholland############################################################ 401.1Sdholland# 2. Create the directories to copy into. 411.1Sdholland 421.1SdhollandALLDIRS=$(echo "$DIRS" | awk -F/ ' 431.1Sdholland { 441.1Sdholland path = sep = ""; 451.1Sdholland for (i=1;i<=NF;i++) { 461.1Sdholland path = path sep $i; 471.1Sdholland sep = "/"; 481.1Sdholland print path; 491.1Sdholland } 501.1Sdholland } 511.1Sdholland' | sort -u) 521.1Sdholland 531.1Sdhollandfor D in $ALLDIRS; do 541.1Sdholland echo "MKDIR $D" 551.1Sdholland mkdir "$D" || exit 1 561.1Sdhollanddone 571.1Sdholland 581.1Sdholland############################################################ 591.1Sdholland# 3. Copy the files. 601.1Sdholland 611.1Sdholland# In the course of copying, strip the dollar-signs from FreeBSD RCS 621.1Sdholland# tags and add a NetBSD tag. 631.1Sdholland 641.1Sdhollandfor F in $FILES; do 651.1Sdholland echo "COPY $F" 661.1Sdholland awk < "$FTOP"/"$F" ' 671.1Sdholland function detag() { 681.1Sdholland gsub("\\$", "", $0); 691.1Sdholland } 701.1Sdholland function commentout() { 711.1Sdholland $0 = "/* " $0 " */"; 721.1Sdholland } 731.1Sdholland BEGIN { 741.1Sdholland first = 1; 751.1Sdholland } 761.1Sdholland 771.1Sdholland # there are a handful of netbsd __RCSID()s in the input 781.1Sdholland /__RCSID(.*NetBSD:.*)/ { 791.1Sdholland detag(); 801.1Sdholland commentout(); 811.1Sdholland print; 821.1Sdholland first = 0; 831.1Sdholland next; 841.1Sdholland } 851.1Sdholland /__FBSDID(.*FreeBSD:.*)/ { 861.1Sdholland detag(); 871.1Sdholland commentout(); 881.1Sdholland print; 891.1Sdholland printf "__RCSID(\"%sNetBSD%s\");\n", "$", "$"; 901.1Sdholland first = 0; 911.1Sdholland next; 921.1Sdholland } 931.1Sdholland /\$NetBSD.*\$/ { 941.1Sdholland detag(); 951.1Sdholland print; 961.1Sdholland first = 0; 971.1Sdholland next; 981.1Sdholland } 991.1Sdholland /\$FreeBSD.*\$/ { 1001.1Sdholland orig = $0; 1011.1Sdholland detag(); 1021.1Sdholland print; 1031.1Sdholland sub("FreeBSD:.*\\$", "NetBSD$", orig); 1041.1Sdholland print orig; 1051.1Sdholland first = 0; 1061.1Sdholland next; 1071.1Sdholland } 1081.1Sdholland first { 1091.1Sdholland printf "/*\t%sNetBSD%s\t*/\n", "$", "$"; 1101.1Sdholland print; 1111.1Sdholland first = 0; 1121.1Sdholland next; 1131.1Sdholland } 1141.1Sdholland { print; } 1151.1Sdholland ' "name=$F" > "$F" 1161.1Sdhollanddone 1171.1Sdholland 1181.1Sdholland# If you need to diff the files against the freebsd tree for some 1191.1Sdholland# reason, e.g. because you needed to debug the awk script above, 1201.1Sdholland# uncomment this for testing. 1211.1Sdholland#exit 3 1221.1Sdholland 1231.1Sdholland############################################################ 1241.1Sdholland# 4. Move the files around the way we want them. 1251.1Sdholland 1261.1Sdholland# Be sure to reflect changes in this section into section 5. 1271.1Sdholland 1281.1Sdholland 1291.1Sdholland# If these fail, it means the script needs to be updated... 1301.1Sdhollandmv nfs/nfsproto.h nfs/oldnfsproto.h || exit 1 1311.1Sdhollandmv nfs/xdr_subs.h nfs/old_xdr_subs.h || exit 1 1321.1Sdholland 1331.1Sdholland# Make sure nothing in nfs/ and fs/nfs/ overlaps as we're going 1341.1Sdholland# to merge those dirs. 1351.1Sdholland 1361.1SdhollandBAD=$( ( 1371.1Sdholland (cd nfs && ls) 1381.1Sdholland (cd fs/nfs && ls) 1391.1Sdholland ) | sort | uniq -d) 1401.1Sdhollandif [ x"$BAD" != x ]; then 1411.1Sdholland echo "$0: The following files exist in both nfs/ and fs/nfs/:" 1>&2 1421.1Sdholland echo "$BAD" 1>&2 1431.1Sdholland echo "$0: Please add logic to fix this before continuing." 1>&2 1441.1Sdholland exit 1 1451.1Sdhollandfi 1461.1Sdholland 1471.1Sdholland# Now rearrange the dirs. 1481.1Sdholland 1491.1Sdhollandmkdir fs/nfs/common || exit 1 1501.1Sdhollandmv nfs/*.[ch] fs/nfs/common/ || exit 1 1511.1Sdhollandmv fs/nfs/*.[ch] fs/nfs/common/ || exit 1 1521.1Sdhollandmv fs/nfsserver fs/nfs/server || exit 1 1531.1Sdhollandmv fs/nfsclient fs/nfs/client || exit 1 1541.1Sdhollandmv nlm fs/nfs/nlm || exit 1 1551.1Sdholland 1561.1Sdhollandrmdir nfs || exit 1 1571.1Sdholland 1581.1Sdholland############################################################ 1591.1Sdholland# 5. Prepare a skeleton files.newnfs. 1601.1Sdholland 1611.1Sdholland# This helps make sure that freebsd changes in the file list 1621.1Sdholland# propagate. 1631.1Sdholland 1641.1Sdhollandecho 'GEN fs/nfs/files.newnfs' 1651.1Sdholland 1661.1Sdhollandegrep -w 'nfscl|nfsd' "$FTOP"/conf/files |\ 1671.1Sdholland sed '/^rpc\//d;/^xdr\//d' | sed ' 1681.1Sdholland s,^fs/nfs/,fs/nfs/common/, 1691.1Sdholland s,^fs/nfsclient/,fs/nfs/client/, 1701.1Sdholland s,^fs/nfsserver/,fs/nfs/server/, 1711.1Sdholland s,^nfs/,fs/nfs/common/, 1721.1Sdholland s,^nlm/,fs/nfs/nlm/, 1731.1Sdholland' | sort | awk ' 1741.1Sdholland BEGIN { 1751.1Sdholland # fbsd -> nbsd translation table for files.* tokens 1761.1Sdholland 1771.1Sdholland # old nfs implementation 1781.1Sdholland transtoken["nfsserver"] = "false"; 1791.1Sdholland transtoken["nfsclient"] = "false"; 1801.1Sdholland 1811.1Sdholland # new nfs implementation 1821.1Sdholland transtoken["nfscl"] = "new_nfsclient"; 1831.1Sdholland transtoken["nfsd"] = "new_nfsserver"; 1841.1Sdholland transtoken["nfslockd"] = "new_nfslockd"; 1851.1Sdholland transtoken["nfs_root"] = "new_nfs_boot"; 1861.1Sdholland transtoken["bootp"] = "new_nfs_boot_bootp"; 1871.1Sdholland 1881.1Sdholland # other stuff 1891.1Sdholland transtoken["inet"] = "true"; 1901.1Sdholland } 1911.1Sdholland { 1921.1Sdholland file = $1; 1931.1Sdholland expr = ""; 1941.1Sdholland havetoken = 0; 1951.1Sdholland for (i=2;i<=NF;i++) { 1961.1Sdholland if ($i == "optional") { 1971.1Sdholland continue; 1981.1Sdholland } 1991.1Sdholland if ($i == "|") { 2001.1Sdholland havetoken = 0; 2011.1Sdholland } 2021.1Sdholland else if (havetoken) { 2031.1Sdholland expr = expr " &"; 2041.1Sdholland havetoken = 0; 2051.1Sdholland } 2061.1Sdholland else { 2071.1Sdholland havetoken = 1; 2081.1Sdholland } 2091.1Sdholland t = $i; 2101.1Sdholland if (transtoken[t]) { 2111.1Sdholland t = transtoken[t]; 2121.1Sdholland } 2131.1Sdholland expr = expr " " t; 2141.1Sdholland seentokens[t] = 1; 2151.1Sdholland } 2161.1Sdholland gsub("false \\& [a-zA-Z0-9_]+ \\| ", "", expr); 2171.1Sdholland gsub("false \\| ", "", expr); 2181.1Sdholland gsub(" \\& true", "", expr); 2191.1Sdholland files[++nfiles] = file; 2201.1Sdholland exprs[file] = expr; 2211.1Sdholland } 2221.1Sdholland 2231.1Sdholland END { 2241.1Sdholland # This output is not meant to be perfect; it is meant as a 2251.1Sdholland # starting point. 2261.1Sdholland 2271.1Sdholland printf "#\t%sNetBSD%s\n", "$", "$"; 2281.1Sdholland printf "\n"; 2291.1Sdholland 2301.1Sdholland printf "deffs NEW_NFSCLIENT\n"; 2311.1Sdholland 2321.1Sdholland sep = "defflag opt_newnfs.h\t\t\t"; 2331.1Sdholland for (t in seentokens) { 2341.1Sdholland if (t == "true" || t == "false" || t == "|" || t == "&") { 2351.1Sdholland continue; 2361.1Sdholland } 2371.1Sdholland if (t == "new_nfsclient") { 2381.1Sdholland continue; 2391.1Sdholland } 2401.1Sdholland printf "%s%s\n", sep, toupper(t); 2411.1Sdholland sep = "\t\t\t\t\t"; 2421.1Sdholland } 2431.1Sdholland printf "\n"; 2441.1Sdholland 2451.1Sdholland for (i=1;i<=nfiles;i++) { 2461.1Sdholland printf "file\t%s", files[i]; 2471.1Sdholland ntabs = 4 - int(length(files[i])/8); 2481.1Sdholland if (ntabs < 1) { 2491.1Sdholland ntabs = 1; 2501.1Sdholland } 2511.1Sdholland for (j=0; j<ntabs; j++) { 2521.1Sdholland printf "\t"; 2531.1Sdholland } 2541.1Sdholland printf "%s\n", exprs[files[i]]; 2551.1Sdholland } 2561.1Sdholland } 2571.1Sdholland' > fs/nfs/files.newnfs 2581.1Sdholland 2591.1Sdholland############################################################ 2601.1Sdholland# 6. done 2611.1Sdholland 2621.1Sdhollandmv fs/nfs/* . || exit 1 2631.1Sdhollandrmdir fs/nfs fs || exit 1 2641.1Sdholland 2651.1Sdhollandecho "Now do:" 2661.1Sdhollandecho " cvs -d cvs.netbsd.org:/cvsroot import src/sys/fs/nfs FREEBSD FREEBSD-NNNNNN" 2671.1Sdhollandecho "where NNNNNN is the subversion version number." 268