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 10PRG="$(basename "$0")" 11 12function 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 28function fail() 29{ 30 echo "$1" >&2 31 exit 2 32} 33 34 35## process command line 36 37# options 38 39UPDATE="" 40CHECK="" 41COMPONENTS_DIR="/home/isabelle/components" 42 43while getopts "uc" OPT 44do 45 case "$OPT" in 46 u) 47 UPDATE=true 48 ;; 49 c) 50 CHECK=true 51 ;; 52 esac 53done 54 55shift $(($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 68CHECKSUM_DIR="$ISABELLE_HOME/Admin/components" 69CHECKSUM_FILE="$CHECKSUM_DIR/components.sha1" 70CHECKSUM_TMP="$CHECKSUM_DIR/components.sha1.tmp" 71 72( 73 cd "$COMPONENTS_DIR" 74 sha1sum *.tar.gz | sort -k2 -f > "$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