summaryrefslogtreecommitdiff
path: root/sysutils/radmind/files/patch-contrib__specialist
blob: f882db8aec0d452a3a1971ea940b4773c8c98b06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--- ./contrib/specialist.orig	2014-06-29 12:15:04.244544161 +0200
+++ ./contrib/specialist	2014-06-29 12:15:04.245544128 +0200
@@ -0,0 +1,79 @@
+#! /bin/sh
+
+# specialist: assist creation of special files.
+
+PATH=/bin:/usr/bin:/usr/local/bin; export PATH
+
+SCRIPT=`basename "$0"`
+INPUT_FORMAT=${INPUT_FORMAT:=path}
+
+usage() {
+    echo "usage: ${SCRIPT} [ -T ]" 1>&2
+    exit 1
+}
+
+die() {
+    msg=$*
+
+    echo "${msg}" 1>&2
+    exit 2
+}
+
+# create a special transcript line for the given path.
+specialize() {
+    local path="$1"
+
+    [ -n "${path}" -a -f "${path}" ] || die "Invalid path: ${path}"
+
+    fsdiff -1 -c sha1 "${path}"
+    return $?
+}
+
+specialize_transcript() {
+    local path=""
+    status=0
+
+    while read type path remainder; do
+	if [ x"${type}" != x"f" ]; then
+	    continue
+	fi
+
+	specialize "${path}"
+    done
+}
+
+specialize_paths() {
+    local path=""
+    status=0
+
+    while read path; do
+	specialize "${path}"
+	if [ $? -ne 0 ]; then
+	    status=1
+	fi
+    done
+
+    return "${status}"
+}
+
+while getopts T opt; do
+    case $opt in
+    T)
+	INPUT_FORMAT="transcript"
+	;;
+
+    *)
+	usage
+	;;
+	
+    esac
+done
+shift $((OPTIND - 1))
+
+if [ x"${INPUT_FORMAT}" = x"transcript" ]; then
+    specialize_transcript
+else
+    specialize_paths
+fi
+
+exit $?