File: sha1sum-sh

package info (click to toggle)
asterisk 1%3A1.8.13.1~dfsg1-3%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,336 kB
  • sloc: ansic: 497,975; sh: 11,763; cpp: 5,934; makefile: 3,065; perl: 3,019; yacc: 2,147; xml: 498; sql: 387; tcl: 113; php: 62; python: 42
file content (71 lines) | stat: -rwxr-xr-x 1,085 bytes parent folder | download | duplicates (5)
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
#!/bin/sh

check=0
status=0

while [ x"$1" != x ]; do
	case $1 in
	-c)
		check=1
		shift
		continue;;
	--status)
		status=1
		shift
		continue;;
	-*)
		if [ $status = 0 ]; then
			echo "Unrecognized option $1" 1>&2
		fi
		exit 1
		;;
	*)
		dst=$1
		shift
		continue;;
	esac
done

if [ x"$dst" = x ]; then
	if [ $status = 0 ]; then
		echo "Usage: $0 [<options>] <filename>" 1>&2
	fi
	exit 1
fi

if [ $check = 1 ]; then
	if [ -f $dst ]; then
		sum1=`cut -d' ' -f1 $dst`
		file=`cut -d' ' -f3 $dst`
		sum2=`openssl sha1 $file | cut -d' ' -f2`
		if [ x"$sum1" = x"$sum2" ]; then
			if [ $status = 0 ]; then
				echo "$dst: OK"
			fi
			exit 0
		else
			if [ $status = 0 ]; then
				echo "$dst: FAILED"
			fi
			exit 1
		fi
	else
		echo "$0: $dst: No such file or directory" 1>&2
		exit 1
	fi
else
	if [ x"$status" = x1 ]; then
		echo "$0: the --status option is meaningful only when verifying checksums" 1>&2
		exit 1
	fi

	if [ -f $dst ]; then
		sum=`openssl sha1 $dst | cut -d' ' -f2`
		echo "$dst  $sum"
		exit 0
	else
		echo "$0: $dst: No such file or directory" 1>&2
		exit 1
	fi
fi