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