Remove MAKEDEV.subr. This removes the risk of third party scripts (or
human procedures) breaking because they assume it's enough to copy MAKEDEV fom one place to another. Let MAKEDEV return after defining shell functions but before doing any real work, if MAKEDEV_AS_LIBRARY is set. Let MAKEDEV.local load MAKEDEV as a function library via "MAKEDEV_AS_LIBRARY=1 . MAKEDEV".
This commit is contained in:
parent
6c3a4a6a17
commit
68723a5b5f
@ -1,5 +1,5 @@
|
||||
#!/bin/sh -
|
||||
# $NetBSD: MAKEDEV.local,v 1.10 2007/03/01 20:48:26 apb Exp $
|
||||
# $NetBSD: MAKEDEV.local,v 1.11 2007/03/03 06:36:00 apb Exp $
|
||||
#
|
||||
# Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
@ -59,7 +59,7 @@ all)
|
||||
#makedev_local foo
|
||||
;;
|
||||
|
||||
# Add more cases here. You can call functions defined in MAKEDEV.subr.
|
||||
# Add more cases here. You can call functions defined in MAKEDEV.
|
||||
# For example:
|
||||
#foo)
|
||||
# mkdev foo c 0 0 600
|
||||
@ -75,14 +75,19 @@ 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.
|
||||
# MAIN: Figure out where MAKEDEV is; load MAKEDEV as a function library;
|
||||
# call the setup function to parse command line args and set some other
|
||||
# variables; then call the makedev_local function to create requested
|
||||
# devices.
|
||||
#
|
||||
case "$0" in
|
||||
*/*) . "${0%/*}/MAKEDEV.subr" ;;
|
||||
*) . ./MAKEDEV.subr ;;
|
||||
*/*) MAKEDEV="${0%/*}/MAKEDEV" ;;
|
||||
*) MAKEDEV="./MAKEDEV" ;;
|
||||
esac
|
||||
[ -f "${MAKEDEV}" ] || MAKEDEV="/dev/MAKEDEV"
|
||||
|
||||
MAKEDEV_AS_LIBRARY=1 . "${MAKEDEV}" || exit 1
|
||||
|
||||
setup ${1+"$@"}
|
||||
shift $((${OPTIND}-1))
|
||||
makedev_local ${1+"$@"}
|
||||
|
@ -1,204 +0,0 @@
|
||||
#!/bin/sh -
|
||||
# $NetBSD: MAKEDEV.subr.tmpl,v 1.2 2007/03/02 21:29:23 dsl 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 [ -n "$count_nodes" ]; then
|
||||
count_nodes=$((count_nodes + 1))
|
||||
return
|
||||
fi
|
||||
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 [ -n "$count_nodes" ]; then
|
||||
count_nodes=$((count_nodes + 1))
|
||||
return
|
||||
fi
|
||||
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 [ -n "$count_nodes" ]; then
|
||||
count_nodes=$((count_nodes + 1))
|
||||
return
|
||||
fi
|
||||
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
|
||||
}
|
190
etc/MAKEDEV.tmpl
190
etc/MAKEDEV.tmpl
@ -1,5 +1,5 @@
|
||||
#!/bin/sh -
|
||||
# $NetBSD: MAKEDEV.tmpl,v 1.78 2007/03/02 22:44:16 dsl Exp $
|
||||
# $NetBSD: MAKEDEV.tmpl,v 1.79 2007/03/03 06:36:01 apb Exp $
|
||||
#
|
||||
# Copyright (c) 2003,2007 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
@ -291,7 +291,183 @@
|
||||
# xenevt Xen event interface
|
||||
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
|
||||
#
|
||||
# Apart from a few lines right at the end, this file should consist
|
||||
# entirely of function definitions.
|
||||
#
|
||||
# This file is used both as a standalone script (via "sh ./MAKEDEV all"
|
||||
# or similar), and as a function library (via "MAKEDEV_AS_LIBRARY=1 .
|
||||
# MAKEDEV" from MAKEDEV.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
|
||||
}
|
||||
|
||||
setup()
|
||||
{
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
|
||||
|
||||
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 [ -n "$count_nodes" ]; then
|
||||
count_nodes=$((count_nodes + 1))
|
||||
return
|
||||
fi
|
||||
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 [ -n "$count_nodes" ]; then
|
||||
count_nodes=$((count_nodes + 1))
|
||||
return
|
||||
fi
|
||||
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 [ -n "$count_nodes" ]; then
|
||||
count_nodes=$((count_nodes + 1))
|
||||
return
|
||||
fi
|
||||
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
|
||||
@ -1640,14 +1816,12 @@ else
|
||||
fi
|
||||
|
||||
#
|
||||
# MAIN: Load function definitions from MAKEDEV.subr; call setup function
|
||||
# to parse command line args and set some other variables; then call
|
||||
# MAIN: If MAKEDEV_AS_LIBRARY is set, then we are being used as a
|
||||
# function library, so just return. Otherwise, call the setup function
|
||||
# to parse command line args and set some other variables; then call the
|
||||
# makedev function to create requested devices.
|
||||
#
|
||||
case "$0" in
|
||||
*/*) . "${0%/*}/MAKEDEV.subr" ;;
|
||||
*) . ./MAKEDEV.subr ;;
|
||||
esac
|
||||
[ -n "${MAKEDEV_AS_LIBRARY}" ] && return
|
||||
|
||||
setup ${1+"$@"}
|
||||
shift $((${OPTIND}-1))
|
||||
|
15
etc/Makefile
15
etc/Makefile
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.339 2007/02/26 20:44:03 apb Exp $
|
||||
# $NetBSD: Makefile,v 1.340 2007/03/03 06:36:01 apb Exp $
|
||||
# from: @(#)Makefile 8.7 (Berkeley) 5/25/95
|
||||
|
||||
# Environment variables without default values:
|
||||
@ -163,18 +163,12 @@ distribution: .PHONY .MAKE check_DESTDIR distrib-dirs
|
||||
.endif # !DISTRIBUTION_DONE
|
||||
|
||||
|
||||
CLEANFILES+= MAKEDEV MAKEDEV.subr
|
||||
CLEANFILES+= MAKEDEV
|
||||
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 \
|
||||
@ -273,7 +267,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 MAKEDEV.subr
|
||||
install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV
|
||||
${_MKMSG_INSTALL} ${DESTDIR}/etc/master.passwd
|
||||
${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
|
||||
master.passwd ${DESTDIR}/etc
|
||||
@ -292,9 +286,6 @@ install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV MAKEDEV.subr
|
||||
${_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 \
|
||||
|
Loading…
Reference in New Issue
Block a user