Provide a new MAKEDEV.subr file containing utility functions for

use by both MAKEDEV and MAKEDEV.local.  This allows MAKEDEV.local
to accept the same command line arguments as MAKEDEV.

The installed MAKEDEV.subr is generated from MAKEDEV.subr.tmpl.

Replace the licence on MAKEDEV.local with a NetBSD licence, since I
rewrote the entire file.

Reviewed by christos and agc
This commit is contained in:
apb 2007-02-26 20:44:03 +00:00
parent cbe547e6a7
commit 142606111b
4 changed files with 274 additions and 191 deletions

View File

@ -1,8 +1,7 @@
#!/bin/sh -
# $NetBSD: MAKEDEV.local,v 1.7 2007/02/26 20:44:03 apb Exp $
#
# $NetBSD: MAKEDEV.local,v 1.6 2003/12/15 08:57:52 jdolecek Exp $
#
# Copyright (c) 1991 The Regents of the University of California.
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -15,41 +14,72 @@
# 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 University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
# 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 REGENTS 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 REGENTS 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.
# 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.
#
# @(#)MAKEDEV.local 8.1 (Berkeley) 6/9/93
###########################################################################
#
# MAKEDEV.local can be customised to create site-specific device nodes.
# By default it does nothing, except parse and accept the same command
# line options as MAKEDEV.
#
# "MAKEDEV all" or "MAKEDEV local" will invoke "MAKEDEV.local all";
# MAKEDEV.local may also be invoked directly with other args.
# Local device MAKEDEV script.
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/rescue
umask 77
# makedev_local special [...]
# the main loop
#
makedev_local()
{
for i
do
case $i in
all)
#sh $0 list_of_all_devices
# Customise this. For example:
#makedev_local foo
;;
# Add more cases here. You can call functions defined in MAKEDEV.tmpl.
# For example:
#foo)
# mkdev foo c 0 0 600
# ;;
*)
echo "$0: unknown device type: $*"
warn "$i: unknown device"
;;
esac
done
}
#
# MAIN: Load function definitions from MAKEDEV.subr; call setup function
# to parse command line args and set some other variables; then call
# makedev_local function to create requested devices.
#
. "$(dirname "$0")/MAKEDEV.subr"
setup ${1+"$@"}
shift $((${OPTIND}-1))
makedev_local ${1+"$@"}

192
etc/MAKEDEV.subr.tmpl Normal file
View File

@ -0,0 +1,192 @@
#!/bin/sh -
# $NetBSD: MAKEDEV.subr.tmpl,v 1.1 2007/02/26 20:44:03 apb Exp $
#
# Copyright (c) 2003,2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# 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.
#
#
###########################################################################
# Common code used by MAKEDEV and MAKDEV.local
get_opts() {
opts="$*"
shift $((${OPTIND}-1))
opts="${opts%$*}"
}
usage()
{
cat 1>&2 << _USAGE_
Usage: ${0##*/} [-f] [-m mknod] [-s] special [...]
Create listed special devices. Options:
-f Force permissions to be updated on existing devices.
-m mknod Name of mknod(8) program. [\$TOOL_MKNOD or mknod]
-s Generate mtree(8) specfile instead of creating devices.
_USAGE_
exit 1
}
# zeropad width number
# display number with a zero (`0') padding of width digits.
#
zeropad()
{
case $(($1 - ${#2})) in
5) echo 00000$2;;
4) echo 0000$2;;
3) echo 000$2;;
2) echo 00$2;;
1) echo 0$2;;
0) echo $2;;
*) echo "$0: bad padding" 1>&2; exit 1;;
esac
}
# hexprint number
# display (base10) number as hexadecimal
#
hexprint()
{
case $1 in
[0-9]) echo $1 ;;
10) echo a ;;
11) echo b ;;
12) echo c ;;
13) echo d ;;
14) echo e ;;
15) echo f ;;
*) echo $(hexprint $(($1 / 16)))$(hexprint $(($1 % 16))) ;;
esac
}
#
# functions available to create nodes:
#
# mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]]
# create device node `name' with the appropriate permissions
#
# lndev src target
# create a symlink from src to target
#
# makedir dir mode
# create directory with appropriate mode
#
mkdev()
{
if $do_specfile; then
case $2 in
b) type=block ;;
c) type=char ;;
esac
echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}"
else
${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4
fi
}
lndev()
{
if $do_specfile; then
echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root"
else
ln -f -s $1 $2
fi
}
makedir()
{
if $do_specfile; then
echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root"
else
mkdir $1 2>/dev/null
chmod $2 $1
fi
}
warn()
{
echo 1>&2 "$0: $*"
}
setup()
{
do_force=false
do_specfile=false
while getopts fm:s ch; do
case ${ch} in
f) do_force=true ;;
m) TOOL_MKNOD=${OPTARG} ;;
s) do_specfile=true ;;
*) usage ;;
esac
done
opts=
get_opts "$@"
shift $((${OPTIND} - 1))
[ $# -gt 0 ] || usage
MKNOD="${TOOL_MKNOD:-mknod} -F netbsd"
if $do_force; then
MKNOD="${MKNOD} -R"
else
MKNOD="${MKNOD} -r"
fi
u_root="%uid_root%"
u_uucp="%uid_uucp%"
g_kmem="%gid_kmem%"
g_ntpd="%gid_ntpd%"
g_operator="%gid_operator%"
g_wheel="%gid_wheel%"
dialin=0
dialout=524288
callunit=262144
# only allow read&write for owner by default
umask 077
# Check if we have fdesc mounted
if [ -d fd ]; then
case "$(df fd)" in
*fdesc*) nofdesc=false;;
*) nofdesc=true;;
esac
else
nofdesc=true
fi
if $do_specfile; then
echo ". type=dir"
fi
}

View File

@ -1,7 +1,7 @@
#!/bin/sh -
# $NetBSD: MAKEDEV.tmpl,v 1.73 2007/02/07 03:01:13 riz Exp $
# $NetBSD: MAKEDEV.tmpl,v 1.74 2007/02/26 20:44:03 apb Exp $
#
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# Copyright (c) 2003,2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -293,167 +293,9 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
get_opts() {
opts="$*"
shift $((${OPTIND}-1))
opts="${opts%$*}"
}
usage()
{
cat 1>&2 << _USAGE_
Usage: ${0##*/} [-f] [-m mknod] [-s] special [...]
Create listed special devices. Options:
-f Force permissions to be updated on existing devices.
-m mknod Name of mknod(8) program. [\$TOOL_MKNOD or mknod]
-s Generate mtree(8) specfile instead of creating devices.
_USAGE_
exit 1
}
# zeropad width number
# display number with a zero (`0') padding of width digits.
#
zeropad()
{
case $(($1 - ${#2})) in
5) echo 00000$2;;
4) echo 0000$2;;
3) echo 000$2;;
2) echo 00$2;;
1) echo 0$2;;
0) echo $2;;
*) echo "$0: bad padding" 1>&2; exit 1;;
esac
}
# hexprint number
# display (base10) number as hexadecimal
#
hexprint()
{
case $1 in
[0-9]) echo $1 ;;
10) echo a ;;
11) echo b ;;
12) echo c ;;
13) echo d ;;
14) echo e ;;
15) echo f ;;
*) echo $(hexprint $(($1 / 16)))$(hexprint $(($1 % 16))) ;;
esac
}
do_force=false
do_specfile=false
while getopts fm:s ch; do
case ${ch} in
f) do_force=true ;;
m) TOOL_MKNOD=${OPTARG} ;;
s) do_specfile=true ;;
*) usage ;;
esac
done
opts=
get_opts "$@"
shift $((${OPTIND} - 1))
[ $# -gt 0 ] || usage
MKNOD="${TOOL_MKNOD:-mknod} -F netbsd"
if $do_force; then
MKNOD="${MKNOD} -R"
else
MKNOD="${MKNOD} -r"
fi
u_root="%uid_root%"
u_uucp="%uid_uucp%"
g_kmem="%gid_kmem%"
g_ntpd="%gid_ntpd%"
g_operator="%gid_operator%"
g_wheel="%gid_wheel%"
dialin=0
dialout=524288
callunit=262144
# only allow read&write for owner by default
umask 077
# Check if we have fdesc mounted
if [ -d fd ]; then
case "$(df fd)" in
*fdesc*) nofdesc=false;;
*) nofdesc=true;;
esac
else
nofdesc=true
fi
if $do_specfile; then
echo ". type=dir"
fi
#
# functions available to create nodes:
#
# mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]]
# create device node `name' with the appropriate permissions
#
# lndev src target
# create a symlink from src to target
#
# makedir dir mode
# create directory with appropriate mode
#
mkdev()
{
if $do_specfile; then
case $2 in
b) type=block ;;
c) type=char ;;
esac
echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}"
else
${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4
fi
}
lndev()
{
if $do_specfile; then
echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root"
else
ln -f -s $1 $2
fi
}
makedir()
{
if $do_specfile; then
echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root"
else
mkdir $1 2>/dev/null
chmod $2 $1
fi
}
warn()
{
echo 1>&2 "$0: $*"
}
# makedev special [...]
# the main loop
#
makedev()
{
@ -477,12 +319,12 @@ all)
makedev tun0 tun1 tun2 tun3
makedev ipl pf crypto random systrace
makedev lkm lockstat clockctl
makedev local
makedev atabus0 atabus1 atabus2 atabus3
makedev tap tap0 tap1 tap2 tap3
makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
makedev bthub
makedev puffs
makedev local # do this last
;;
init)
@ -1636,8 +1478,10 @@ midevend)
local)
if [ -f "$0.local" ]; then
umask 0
sh $0.local $opts all
sh "$0.local" $opts all
umask 077
else
warn "missing $0.local"
fi
;;
@ -1769,4 +1613,12 @@ makedisk_minimal()
mkdev r${name}${unit}$rn c $chr $(($unit * $doff + $ro)) 640 $g_operator
}
makedev $*
#
# MAIN: Load function definitions from MAKEDEV.subr; call setup function
# to parse command line args and set some other variables; then call
# makedev function to create requested devices.
#
. "$(dirname "$0")/MAKEDEV.subr"
setup ${1+"$@"}
shift $((${OPTIND}-1))
makedev ${1+"$@"}

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.338 2007/02/04 14:44:34 rpaulo Exp $
# $NetBSD: Makefile,v 1.339 2007/02/26 20:44:03 apb Exp $
# from: @(#)Makefile 8.7 (Berkeley) 5/25/95
# Environment variables without default values:
@ -163,12 +163,18 @@ distribution: .PHONY .MAKE check_DESTDIR distrib-dirs
.endif # !DISTRIBUTION_DONE
CLEANFILES+= MAKEDEV
CLEANFILES+= MAKEDEV MAKEDEV.subr
MAKEDEV: .EXEC
${_MKTARGET_CREATE}
MACHINE=${MACHINE:Q} MACHINE_ARCH=${MACHINE_ARCH:Q} \
NETBSDSRCDIR=${NETBSDSRCDIR:Q} \
awk -f ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl > ${.TARGET}
MAKEDEV.subr: .EXEC
${_MKTARGET_CREATE}
MACHINE=${MACHINE:Q} MACHINE_ARCH=${MACHINE_ARCH:Q} \
NETBSDSRCDIR=${NETBSDSRCDIR:Q} \
awk -f ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.subr.tmpl \
> ${.TARGET}
RELEASEVARS= BSDOBJDIR BSDSRCDIR BUILDID \
DESTDIR EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
@ -267,7 +273,7 @@ CONFIGSYMLINKS+= ${TZDIR}/${LOCALTIME} /etc/localtime \
# install-etc-files --
# Install etc (config) files; not performed by "make build"
#
install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV
install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV MAKEDEV.subr
${_MKMSG_INSTALL} ${DESTDIR}/etc/master.passwd
${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
master.passwd ${DESTDIR}/etc
@ -286,6 +292,9 @@ install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV
${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV
${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
MAKEDEV ${DESTDIR}/dev
${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV.subr
${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
MAKEDEV.subr ${DESTDIR}/dev
.for owner group mode file in \
${BINOWN} operator 664 /etc/dumpdates \
${BINOWN} operator 600 /etc/skeykeys \