xref: /netbsd-src/etc/makespec (revision 5c7c1d2b1c59b1bfd15664a7d3514322214dfeff)
1d6c3c02aSchristos#!/bin/sh
2d6c3c02aSchristos#
3d6c3c02aSchristos# Copyright (c) 2024 The NetBSD Foundation, Inc.
4d6c3c02aSchristos# All rights reserved.
5d6c3c02aSchristos#
6d6c3c02aSchristos# This code is derived from software contributed to The NetBSD Foundation
7d6c3c02aSchristos# by Christos Zoulas.
8d6c3c02aSchristos#
9d6c3c02aSchristos# Redistribution and use in source and binary forms, with or without
10d6c3c02aSchristos# modification, are permitted provided that the following conditions
11d6c3c02aSchristos# are met:
12d6c3c02aSchristos# 1. Redistributions of source code must retain the above copyright
13d6c3c02aSchristos#    notice, this list of conditions and the following disclaimer.
14d6c3c02aSchristos# 2. Redistributions in binary form must reproduce the above copyright
15d6c3c02aSchristos#    notice, this list of conditions and the following disclaimer in the
16d6c3c02aSchristos#    documentation and/or other materials provided with the distribution.
17d6c3c02aSchristos#
18d6c3c02aSchristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19d6c3c02aSchristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20d6c3c02aSchristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21d6c3c02aSchristos# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22d6c3c02aSchristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23d6c3c02aSchristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24d6c3c02aSchristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25d6c3c02aSchristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26d6c3c02aSchristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27d6c3c02aSchristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28d6c3c02aSchristos# POSSIBILITY OF SUCH DAMAGE.
29d6c3c02aSchristos#
30d6c3c02aSchristos# Create an mtree spec file with per file type defaults
31d6c3c02aSchristos
32d6c3c02aSchristosTYPES="b c d f l p s"
33d6c3c02aSchristos
34d6c3c02aSchristosgetmode() {
35d6c3c02aSchristos	case $1 in
36d6c3c02aSchristos	b|c)	echo 0600;;
37d6c3c02aSchristos	d)	echo 0755;;
38d6c3c02aSchristos	f)	echo 0644;;
39d6c3c02aSchristos	l)	echo 0777;;
40d6c3c02aSchristos	p|s)	echo 0666;;
41d6c3c02aSchristos	*)	echo "*error $1*";;
42d6c3c02aSchristos	esac
43d6c3c02aSchristos}
44d6c3c02aSchristos
45d6c3c02aSchristosgettype() {
46d6c3c02aSchristos	case $1 in
47d6c3c02aSchristos	b)	echo block;;
48d6c3c02aSchristos	c)	echo char;;
49d6c3c02aSchristos	d)	echo dir;;
50d6c3c02aSchristos	f)	echo file;;
51d6c3c02aSchristos	l)	echo link;;
52d6c3c02aSchristos	p)	echo fifo;;
53d6c3c02aSchristos	s)	echo socket;;
54d6c3c02aSchristos	*)	echo "*error $1*";;
55d6c3c02aSchristos	esac
56d6c3c02aSchristos}
57d6c3c02aSchristos
58*5c7c1d2bSchristosusage() {
59*5c7c1d2bSchristos	echo "Usage: $0 -d <base> <dir>..." 1>&2
60d6c3c02aSchristos	exit 1
61*5c7c1d2bSchristos}
62*5c7c1d2bSchristos
63*5c7c1d2bSchristos
64*5c7c1d2bSchristoswhile getopts "d:" i; do
65*5c7c1d2bSchristos	case $i in
66*5c7c1d2bSchristos	d)
67*5c7c1d2bSchristos		DIR="$OPTARG";;
68*5c7c1d2bSchristos	*)
69*5c7c1d2bSchristos		usage;;
70*5c7c1d2bSchristos	esac
71*5c7c1d2bSchristosdone
72*5c7c1d2bSchristos
73*5c7c1d2bSchristosshift $((OPTIND - 1))
74*5c7c1d2bSchristos
75*5c7c1d2bSchristosif [ -z "$DIR" ] || [ -z "$1" ]; then
76*5c7c1d2bSchristos	usage
77d6c3c02aSchristosfi
78d6c3c02aSchristos
79*5c7c1d2bSchristoscd "$DIR"
80*5c7c1d2bSchristos
81*5c7c1d2bSchristosfor d; do
82*5c7c1d2bSchristos	case $d in
83*5c7c1d2bSchristos	.);;
84*5c7c1d2bSchristos	*)	d="./$d";;
85*5c7c1d2bSchristos	esac
86d6c3c02aSchristos	for i in $TYPES; do
87d6c3c02aSchristos
88d6c3c02aSchristos		t=$(gettype $i)
89d6c3c02aSchristos		m=$(getmode $i)
90*5c7c1d2bSchristos		find $d -type $i -exec \
91d6c3c02aSchristos		printf "%s type=$t uname=root gname=wheel mode=$m\n" {} \;
92*5c7c1d2bSchristos	done
93d6c3c02aSchristos
94d6c3c02aSchristosdone | sort
95