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