backtrace: Refactor ast_bt_get_symbols so it doesn't crash
[asterisk/asterisk.git] / build_tools / sha1sum-sh
1 #!/bin/sh
2
3 check=0
4 status=0
5
6 while [ x"$1" != x ]; do
7         case $1 in
8         -c)
9                 check=1
10                 shift
11                 continue;;
12         --status)
13                 status=1
14                 shift
15                 continue;;
16         -*)
17                 if [ $status = 0 ]; then
18                         echo "Unrecognized option $1" 1>&2
19                 fi
20                 exit 1
21                 ;;
22         *)
23                 dst=$1
24                 shift
25                 continue;;
26         esac
27 done
28
29 if [ x"$dst" = x ]; then
30         if [ $status = 0 ]; then
31                 echo "Usage: $0 [<options>] <filename>" 1>&2
32         fi
33         exit 1
34 fi
35
36 if [ $check = 1 ]; then
37         if [ -f $dst ]; then
38                 sum1=`cut -d' ' -f1 $dst`
39                 file=`cut -d' ' -f3 $dst`
40                 sum2=`openssl sha1 $file | cut -d' ' -f2`
41                 if [ x"$sum1" = x"$sum2" ]; then
42                         if [ $status = 0 ]; then
43                                 echo "$dst: OK"
44                         fi
45                         exit 0
46                 else
47                         if [ $status = 0 ]; then
48                                 echo "$dst: FAILED"
49                         fi
50                         exit 1
51                 fi
52         else
53                 echo "$0: $dst: No such file or directory" 1>&2
54                 exit 1
55         fi
56 else
57         if [ x"$status" = x1 ]; then
58                 echo "$0: the --status option is meaningful only when verifying checksums" 1>&2
59                 exit 1
60         fi
61
62         if [ -f $dst ]; then
63                 sum=`openssl sha1 $dst | cut -d' ' -f2`
64                 echo "$dst  $sum"
65                 exit 0
66         else
67                 echo "$0: $dst: No such file or directory" 1>&2
68                 exit 1
69         fi
70 fi