Add files2mtree - localbin - leot's localbin (~/bin)
HTML hg clone https://bitbucket.org/iamleot/localbin
DIR Log
DIR Files
DIR Refs
---
DIR changeset 19c5a9e741de1af4dec2c2d72e13666b0aade647
DIR parent c99c9cfb401d1881bc3317a783a7dfd045b14227
HTML Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sun, 1 Sep 2019 17:18:45
Add files2mtree
Diffstat:
files2mtree | 41 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
---
diff -r c99c9cfb401d -r 19c5a9e741de files2mtree
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/files2mtree Sun Sep 01 17:18:45 2019 +0200
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+#
+# Print mtree(5) entries of all files passed as arguments
+#
+
+
+#
+# Generate mtree(5) entry for the file passed as argument
+#
+file2mtree()
+{
+
+ #
+ # FIXME: Using %N and %Y are problematic for filenames/links with
+ # FIXME: non-printable characters (in the mtree(5) sense).
+ #
+ fmt=".%N type=%Hp uname=%Su gname=%Sg mode=%Mp%Lp"
+ if [ -h "$1" ]; then
+ fmt="${fmt} link=%Y"
+ fi
+
+ stat -f "${fmt}" "$1" |
+ sed -e 's; type=1 ; type=fifo ;' \
+ -e 's; type=2 ; type=char ;' \
+ -e 's; type=4 ; type=dir ;' \
+ -e 's; type=6 ; type=block ;' \
+ -e 's; type=10 ; type=file ;' \
+ -e 's; type=12 ; type=link ;' \
+ -e 's; type=14 ; type=socket ;'
+}
+
+
+if [ $# -lt 1 ]; then
+ echo "usage: $(basename $0) file ..."
+ exit 1
+fi
+
+for f in "$@"; do
+ file2mtree "$f"
+done