Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/distrib/common MAKEDEV.wrapper
details: https://anonhg.NetBSD.org/src/rev/638db827bbf4
branches: trunk
changeset: 521818:638db827bbf4
user: lukem <lukem%NetBSD.org@localhost>
date: Wed Feb 06 16:08:16 2002 +0000
description:
MAKEDEV.wrapper
generate list of commands from provided MAKEDEV script with
given arguments, to feed into makedev2spec.awk
makedev2spec.awk
take output of MAKEDEV.wrapper and generate an mtree(8) specfile.
diffstat:
distrib/common/MAKEDEV.wrapper | 23 ++++
distrib/common/MAKEDEV.wrapper.local | 5 +
distrib/common/makedev2spec.awk | 189 +++++++++++++++++++++++++++++++++++
3 files changed, 217 insertions(+), 0 deletions(-)
diffs (229 lines):
diff -r e59e13b35228 -r 638db827bbf4 distrib/common/MAKEDEV.wrapper
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/common/MAKEDEV.wrapper Wed Feb 06 16:08:16 2002 +0000
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# MAKEDEV.wrapper --
+# Wrapper script for the MAKEDEV script defined in ${MAKEDEVSCRIPT}
+# to output a list of commands that MAKEDEV would have run to
+# generate the specified devices/special nodes. This list can then
+# be converted into an mtree(8) specfile by makedev2spec.awk
+#
+
+ln() { echo "ln $*" ; }
+rm() { echo "rm $*" ; }
+mknod() { echo "mknod $*" ; }
+chgrp() { echo "chgrp $*" ; }
+chmod() { echo "chmod $*" ; }
+chown() { echo "chown $*" ; }
+mkdir() { echo "mkdir $*" ; }
+
+if [ -n "$MAKEDEVSCRIPT" -a -f "$MAKEDEVSCRIPT" ]; then
+ . $MAKEDEVSCRIPT
+else
+ echo 1>&2 "\$MAKEDEVSCRIPT needs to be defined and refer to a file."
+ exit 1
+fi
diff -r e59e13b35228 -r 638db827bbf4 distrib/common/MAKEDEV.wrapper.local
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/common/MAKEDEV.wrapper.local Wed Feb 06 16:08:16 2002 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: MAKEDEV.wrapper.local,v 1.1 2002/02/06 16:08:16 lukem Exp $
+#
+#
+# dummy file to shut MAKEDEV up which it's run by MAKEDEV.wrapper
+#
diff -r e59e13b35228 -r 638db827bbf4 distrib/common/makedev2spec.awk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/common/makedev2spec.awk Wed Feb 06 16:08:16 2002 +0000
@@ -0,0 +1,189 @@
+# $NetBSD: makedev2spec.awk,v 1.1 2002/02/06 16:08:16 lukem Exp $
+#
+# Copyright (c) 2002 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Luke Mewburn of Wasabi Systems.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# makedev2spec.awk --
+# Generate mtree(8) specfile from MAKEDEV.wrapper output.
+# Typical usage is:
+# MAKEDEVSCRIPT=.../MAKEDEV sh MAKEDEV.wrapper some_devs |
+# awk -f makedev2spec.awk > specfile
+#
+
+BEGIN \
+{
+ errexit = 0;
+ prefix = "./dev/";
+}
+
+
+$1 == "ln" \
+{
+ if ($2 != "-fs" || NF != 4)
+ err("Usage: ln -fs from to");
+ delete gname[$4];
+ delete uname[$4];
+ type[$4] = "type=link link=" $3;
+ mode[$4] = 0755;
+ next;
+}
+
+$1 == "mkdir" \
+{
+ type[$2] = "type=dir";
+ next;
+}
+
+$1 == "mknod" \
+{
+ if (NF != 5)
+ err("usage; mknod name type major minor");
+ if ($3 !~ /^[bc]$/)
+ err("unknown " $1 " type " $3);
+ type[$2] = "type=" ($3 == "b" ? "block" : "char" ) \
+ " device=netbsd," $4 "," $5;
+ next;
+}
+
+
+$1 == "rm" \
+{
+ for (i = 2; i <= NF; i++) {
+ if ($i == "-f")
+ continue;
+ else if ($i ~ /^-/)
+ err("Unsupported " $1 " option " $i);
+ n = split(glob($i), globs, " ");
+ for (j = 1; j <= n; j++) {
+ delete type[globs[j]];
+ delete gname[globs[j]];
+ delete mode[globs[j]];
+ delete uname[globs[j]];
+ }
+ }
+ next;
+}
+
+# XXX: doesn't change symlinks - need to fix
+$1 == "chgrp" \
+{
+ for (i = 3; i <= NF; i++) {
+ n = split(glob($i), globs, " ");
+ for (j = 1; j <= n; j++) {
+ gname[globs[j]] = $2;
+ }
+ }
+ next;
+}
+
+# XXX: doesn't change symlinks - need to fix
+$1 == "chmod" \
+{
+ for (i = 3; i <= NF; i++) {
+ n = split(glob($i), globs, " ");
+ for (j = 1; j <= n; j++) {
+ mode[globs[j]] = $2;
+ }
+ }
+ next;
+}
+
+# XXX: doesn't change symlinks - need to fix
+$1 == "chown" \
+{
+ user = $2;
+ if ((n = match(user, /[\.:]/)) > 0) {
+ group = substr(user, n + 1);
+ user = substr(user, 1, n-1);
+ } else {
+ group = "";
+ }
+ for (i = 3; i <= NF; i++) {
+ n = split(glob($i), globs, " ");
+ for (j = 1; j <= n; j++) {
+ uname[globs[j]] = user;
+ if (group != "")
+ gname[globs[j]] = group;
+ }
+ }
+ next;
+}
+
+{
+ err("Unknown keyword " $1);
+}
+
+
+
+END \
+{
+ if (errexit == 0) {
+ for (i in type) {
+ printf("%s%-15s %s mode=0%s uname=%s gname=%s\n",
+ prefix, i, type[i],
+ mode[i] ? mode[i] : "600",
+ uname[i] ? uname[i] : "root",
+ gname[i] ? gname[i] : "wheel");
+ }
+ }
+}
+
+
+function err(msg) \
+{
+ printf("%s at line %d of input.\n", msg, NR) >"/dev/stderr";
+ errexit=1;
+ exit 1;
+}
+
+function glob(g, l, result) \
+{
+ if (g !~ /[?*[]/)
+ return g;
+ result = "";
+ gsub(/\./, "\\.", g);
+ gsub(/?/, ".", g);
+ gsub(/*/, ".*", g);
+ g = "^" g "$";
+#print "glob() got a glob " g >"/dev/stderr";
+ for (l in type) {
+#print "glob() checking " l " and " g >"/dev/stderr";
+ if (l ~ g) {
+ result = l " " result;
+#print "glob(" $0 ") matched " l " and " g >"/dev/stderr";
+ }
+ }
+#print "glob(" $0 ") returned " result >"/dev/stderr";
+ return result;
+}
Home |
Main Index |
Thread Index |
Old Index