Admin/component_repository/checksum
author berghofe
Mon, 23 Jul 2012 18:52:10 +0200
changeset 48453 2421ff8c57a5
parent 48264 387ed2f30918
permissions -rwxr-xr-x
set_vcs now derives prefix from fully qualified procedure / function name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
#
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
     5
# Computes and validates checksums for the Isabelle component repository
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
     6
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
     7
THIS="$(cd $(dirname "$0"); pwd)"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
     8
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
     9
function usage()
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    10
{
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    11
  echo
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    12
  echo "Usage: $0 [OPTIONS] [DIR]"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    13
  echo
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    14
  echo "  Options are:"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    15
  echo "    -u           update the recorded checksums in the repository"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    16
  echo "    -c           compare the actual checksums with the recorded ones"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    17
  echo
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    18
  echo "  Compute the checksums of components in DIR (default '/home/isabelle/components')"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    19
  echo "  and synchronize them with the Isabelle repository."
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    20
  echo
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    21
  exit 1
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    22
}
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    23
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    24
function fail()
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    25
{
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    26
  echo "$1" >&2
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    27
  exit 2
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    28
}
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
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    31
## process command line
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
# options
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
UPDATE=""
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    36
CHECK=""
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    37
COMPONENTS_DIR="/home/isabelle/components"
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
while getopts "uc" OPT
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    40
do
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    41
  case "$OPT" in
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    42
    u)
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    43
      UPDATE=true
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    44
      ;;
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    45
    c)
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    46
      CHECK=true
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    47
      ;;
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    48
  esac
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    49
done
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    50
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    51
shift $(($OPTIND - 1))
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    52
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    53
[ -n "$UPDATE" ] || [ -n "$CHECK" ] || usage
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
# args
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
[ "$#" -ge 1 ] && { COMPONENTS_DIR="$1"; shift; }
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    58
[ "$#" -ne 0 ] && usage
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    59
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    60
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    61
## compute checksums
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    62
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    63
CHECKSUM_FILE="$THIS/components.sha1"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    64
CHECKSUM_TMP="$THIS/components.sha1.tmp"
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
cd "$COMPONENTS_DIR"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    67
sha1sum *.tar.gz > "$CHECKSUM_TMP"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    68
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    69
[ -n "$UPDATE" ] && mv "$CHECKSUM_TMP" "$CHECKSUM_FILE"
387ed2f30918 added component integrity checks and some initial checksums
krauss
parents:
diff changeset
    70
[ -n "$CHECK" ] && (diff "$CHECKSUM_FILE" "$CHECKSUM_TMP" || fail "Integrity error")