142606111b
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
193 lines
4.5 KiB
Bash
193 lines
4.5 KiB
Bash
#!/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
|
|
}
|