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