| author | wenzelm | 
| Wed, 10 Jun 2015 22:28:56 +0200 | |
| changeset 60423 | 5035a2af185b | 
| parent 51053 | 81a75d9a9a4e | 
| permissions | -rwxr-xr-x | 
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 1 | #!/usr/bin/env bash | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 2 | # | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 3 | # Author: Alexander Krauss | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 4 | # | 
| 50528 | 5 | # DESCRIPTION: compute and validate checksums for component repository | 
| 6 | ||
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 7 | |
| 50528 | 8 | ## diagnostics | 
| 9 | ||
| 10 | PRG="$(basename "$0")" | |
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 11 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 12 | function usage() | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 13 | {
 | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 14 | echo | 
| 50528 | 15 | echo "Usage: $PRG [OPTIONS] [DIR]" | 
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 16 | echo | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 17 | echo " Options are:" | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 18 | echo " -u update the recorded checksums in the repository" | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 19 | echo " -c compare the actual checksums with the recorded ones" | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 20 | echo | 
| 50528 | 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." | |
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 24 | echo | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 25 | exit 1 | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 26 | } | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 27 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 28 | function fail() | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 29 | {
 | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 30 | echo "$1" >&2 | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 31 | exit 2 | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 32 | } | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 33 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 34 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 35 | ## process command line | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 36 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 37 | # options | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 38 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 39 | UPDATE="" | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 40 | CHECK="" | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 41 | COMPONENTS_DIR="/home/isabelle/components" | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 42 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 43 | while getopts "uc" OPT | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 44 | do | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 45 | case "$OPT" in | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 46 | u) | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 47 | UPDATE=true | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 48 | ;; | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 49 | c) | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 50 | CHECK=true | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 51 | ;; | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 52 | esac | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 53 | done | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 54 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 55 | shift $(($OPTIND - 1)) | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 56 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 57 | [ -n "$UPDATE" ] || [ -n "$CHECK" ] || usage | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 58 | |
| 50528 | 59 | |
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 60 | # args | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 61 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 62 | [ "$#" -ge 1 ] && { COMPONENTS_DIR="$1"; shift; }
 | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 63 | [ "$#" -ne 0 ] && usage | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 64 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 65 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 66 | ## compute checksums | 
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 67 | |
| 50528 | 68 | CHECKSUM_DIR="$ISABELLE_HOME/Admin/components" | 
| 69 | CHECKSUM_FILE="$CHECKSUM_DIR/components.sha1" | |
| 70 | CHECKSUM_TMP="$CHECKSUM_DIR/components.sha1.tmp" | |
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 71 | |
| 50528 | 72 | ( | 
| 73 | cd "$COMPONENTS_DIR" | |
| 51053 
81a75d9a9a4e
another attempt to standardize sort order in a portable way;
 wenzelm parents: 
50932diff
changeset | 74 | sha1sum *.tar.gz | sort -k2 -f > "$CHECKSUM_TMP" | 
| 50528 | 75 | ) | 
| 48264 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 76 | |
| 
387ed2f30918
added component integrity checks and some initial checksums
 krauss parents: diff
changeset | 77 | [ -n "$UPDATE" ] && mv "$CHECKSUM_TMP" "$CHECKSUM_FILE" | 
| 50528 | 78 | [ -n "$CHECK" ] && {
 | 
| 79 | diff "$CHECKSUM_FILE" "$CHECKSUM_TMP" || fail "Integrity error" | |
| 80 | } |