equal
deleted
inserted
replaced
1 #!/usr/bin/env bash |
|
2 # |
|
3 # Author: Alexander Krauss |
|
4 # |
|
5 # Computes and validates checksums for the Isabelle component repository |
|
6 |
|
7 THIS="$(cd $(dirname "$0"); pwd)" |
|
8 |
|
9 function usage() |
|
10 { |
|
11 echo |
|
12 echo "Usage: $0 [OPTIONS] [DIR]" |
|
13 echo |
|
14 echo " Options are:" |
|
15 echo " -u update the recorded checksums in the repository" |
|
16 echo " -c compare the actual checksums with the recorded ones" |
|
17 echo |
|
18 echo " Compute the checksums of components in DIR (default '/home/isabelle/components')" |
|
19 echo " and synchronize them with the Isabelle repository." |
|
20 echo |
|
21 exit 1 |
|
22 } |
|
23 |
|
24 function fail() |
|
25 { |
|
26 echo "$1" >&2 |
|
27 exit 2 |
|
28 } |
|
29 |
|
30 |
|
31 ## process command line |
|
32 |
|
33 # options |
|
34 |
|
35 UPDATE="" |
|
36 CHECK="" |
|
37 COMPONENTS_DIR="/home/isabelle/components" |
|
38 |
|
39 while getopts "uc" OPT |
|
40 do |
|
41 case "$OPT" in |
|
42 u) |
|
43 UPDATE=true |
|
44 ;; |
|
45 c) |
|
46 CHECK=true |
|
47 ;; |
|
48 esac |
|
49 done |
|
50 |
|
51 shift $(($OPTIND - 1)) |
|
52 |
|
53 [ -n "$UPDATE" ] || [ -n "$CHECK" ] || usage |
|
54 |
|
55 # args |
|
56 |
|
57 [ "$#" -ge 1 ] && { COMPONENTS_DIR="$1"; shift; } |
|
58 [ "$#" -ne 0 ] && usage |
|
59 |
|
60 |
|
61 ## compute checksums |
|
62 |
|
63 CHECKSUM_FILE="$THIS/components.sha1" |
|
64 CHECKSUM_TMP="$THIS/components.sha1.tmp" |
|
65 |
|
66 cd "$COMPONENTS_DIR" |
|
67 sha1sum *.tar.gz > "$CHECKSUM_TMP" |
|
68 |
|
69 [ -n "$UPDATE" ] && mv "$CHECKSUM_TMP" "$CHECKSUM_FILE" |
|
70 [ -n "$CHECK" ] && (diff "$CHECKSUM_FILE" "$CHECKSUM_TMP" || fail "Integrity error") |
|