files2mtree - localbin - leot's localbin (~/bin)
(HTM) hg clone https://bitbucket.org/iamleot/localbin
(DIR) Log
(DIR) Files
(DIR) Refs
---
files2mtree
---
1 #!/bin/sh
2
3 #
4 # Print mtree(5) entries of all files passed as arguments
5 #
6
7
8 #
9 # Generate mtree(5) entry for the file passed as argument
10 #
11 file2mtree()
12 {
13
14 #
15 # FIXME: Using %N and %Y are problematic for filenames/links with
16 # FIXME: non-printable characters (in the mtree(5) sense).
17 #
18 fmt=".%N type=%Hp uname=%Su gname=%Sg mode=%Mp%Lp"
19 if [ -h "$1" ]; then
20 fmt="${fmt} link=%Y"
21 fi
22
23 stat -f "${fmt}" "$1" |
24 sed -e 's; type=1 ; type=fifo ;' \
25 -e 's; type=2 ; type=char ;' \
26 -e 's; type=4 ; type=dir ;' \
27 -e 's; type=6 ; type=block ;' \
28 -e 's; type=10 ; type=file ;' \
29 -e 's; type=12 ; type=link ;' \
30 -e 's; type=14 ; type=socket ;'
31 }
32
33
34 if [ $# -lt 1 ]; then
35 echo "usage: $(basename $0) file ..."
36 exit 1
37 fi
38
39 for f in "$@"; do
40 file2mtree "$f"
41 done