13
13
# systems, as older shells may not understand command substitution
14
14
# with parentheses, as required by POSIX.
15
15
# NetBSD: cksum & {g,s}etextattr, should be included in src.
16
- # OpenBSD: No extended attribute support since July 2005 (commit 9dd8235)
16
+ # OpenBSD: No extended attribute support since July 2005:
17
+ # > https://github.com/openbsd/src/commit/9dd8235"
18
+ # > Extended Attributes was a piece to get to ACLs, however ACLs have
19
+ # > not been worked on, so EA is pointless. Also the code is not enabled
20
+ # > in GENERIC so it is not being tested or maintained.
17
21
#
18
22
# Each operating system has its own routines for setting/getting EAs and also
19
23
# for calculating checksums. The only hardcoded value is the digest algorithm
26
30
# - Or rewrite this whole thing in Python, for portability's sake? (hashlib, os/xattr)
27
31
#
28
32
DIGEST=" md5" # md5, sha1, sha256, sha512
33
+ PROG=$( basename " $0 " )
29
34
30
35
# Adjust if needed
31
36
PATH=/bin:/usr/bin:/sbin:/usr/local/bin:/opt/local/bin:/opt/csw/bin:/usr/sfw/bin
32
37
33
38
print_usage ()
34
39
{
35
- echo " Usage: $( basename " $0 " ) [get] [file]"
36
- echo " $( basename " $0 " ) [set] [file]"
37
- echo " $( basename " $0 " ) [get-set] [file]"
38
- echo " $( basename " $0 " ) [check-set] [file]"
39
- echo " $( basename " $0 " ) [check] [file]"
40
- echo " $( basename " $0 " ) [remove] [file]"
41
- echo " $( basename " $0 " ) [test]"
42
- echo " "
43
- echo " get-set - sets a new checksum if none is found, print checksum otherwise."
44
- echo " check-set - sets a new checksum if none is found, verify checksum otherwise."
40
+ cat << EOF
41
+ Usage: ${PROG} [get] [file]
42
+ ${PROG} [set] [file]
43
+ ${PROG} [get-set] [file]
44
+ ${PROG} [check-set] [file]
45
+ ${PROG} [check] [file]
46
+ ${PROG} [remove] [file]
47
+ ${PROG} [test]
48
+
49
+ get-set - sets a new checksum if none is found, print checksum otherwise.
50
+ check-set - sets a new checksum if none is found, verify checksum otherwise.
51
+ EOF
45
52
}
46
53
47
54
if [ $# -ne 2 ] || [ ! -f " $2 " ] && [ ! " $1 " = " test" ]; then
@@ -104,24 +111,24 @@ case ${OS} in
104
111
${DIGEST} -q " $1 "
105
112
;;
106
113
107
- NetBSD)
108
- # cksum should support all common algorithms.
109
- cksum -q -a ${DIGEST} " $1 "
110
- ;;
111
-
112
114
Linux)
113
115
# GNU/coreutils should be installed on most Linux distributions.
114
116
# It's also by far much faster than its perl or openssl alternatives.
115
117
${DIGEST} sum " $1 " | awk ' {print $1}'
116
118
;;
117
119
120
+ NetBSD)
121
+ # cksum should support all common algorithms.
122
+ cksum -q -a ${DIGEST} " $1 "
123
+ ;;
124
+
118
125
SunOS)
119
126
# SUNWcsu should be available. If it's not, we'd have much bigger problems.
120
127
digest -a ${DIGEST} " $1 "
121
128
;;
122
129
123
130
* )
124
- do_log " We don't support ${OS} , yet :-(" 1
131
+ do_log " We don't support ${OS} :-(" 1
125
132
;;
126
133
esac
127
134
}
@@ -137,10 +144,6 @@ case ${OS} in
137
144
pxattr -n user.checksum.${DIGEST} " $1 " 2> /dev/null | awk ' /user.checksum/ {print $NF}'
138
145
;;
139
146
140
- NetBSD)
141
- getextattr -q user checksum.${DIGEST} " $1 "
142
- ;;
143
-
144
147
Linux)
145
148
# NOTE: If the designated EA is not set, getfattr may not return a non-zero
146
149
# exit code. This has been fixed upstream but may not have been picked up
@@ -155,12 +158,16 @@ case ${OS} in
155
158
getfattr --only-values --name user.checksum.${DIGEST} -- " $1 " 2> /dev/null | awk ' /[a-z0-9]/ {print $1}'
156
159
;;
157
160
161
+ NetBSD)
162
+ getextattr -q user checksum.${DIGEST} " $1 "
163
+ ;;
164
+
158
165
SunOS)
159
166
runat " $1 " cat user.checksum.${DIGEST} 2> /dev/null
160
167
;;
161
168
162
169
* )
163
- do_log " We don't support ${OS} , yet :-(" 1
170
+ do_log " We don't support ${OS} :-(" 1
164
171
;;
165
172
esac
166
173
}
@@ -179,20 +186,20 @@ case ${OS} in
179
186
pxattr -n user.checksum.${DIGEST} -v " ${CHECKSUM_C} " " $1 "
180
187
;;
181
188
182
- NetBSD)
183
- setextattr user checksum.${DIGEST} " ${CHECKSUM_C} " " $1 "
184
- ;;
185
-
186
189
Linux)
187
190
setfattr --name user.checksum.${DIGEST} --value " ${CHECKSUM_C} " -- " $1 "
188
191
;;
189
192
193
+ NetBSD)
194
+ setextattr user checksum.${DIGEST} " ${CHECKSUM_C} " " $1 "
195
+ ;;
196
+
190
197
SunOS)
191
198
runat " $1 " " echo ${CHECKSUM_C} > user.checksum.${DIGEST} "
192
199
;;
193
200
194
201
* )
195
- do_log " We don't support ${OS} , yet :-(" 1
202
+ do_log " We don't support ${OS} :-(" 1
196
203
;;
197
204
esac
198
205
}
@@ -290,7 +297,7 @@ case ${ACTION} in
290
297
;;
291
298
292
299
* )
293
- do_log " We don't support ${OS} , yet :-(" 1
300
+ do_log " We don't support ${OS} :-(" 1
294
301
;;
295
302
esac
296
303
;;
0 commit comments