#!/bin/sh # anew checksums -69- set -e usage() { printf "usage: ${0##*/} %s\n" "[-y] ARCHIVE [SOLTASK-file]" exit 1 } Y=false while : ; do case "$1" in -y) shift 1 Y=true ;; *) break ;; esac done if [ -z "${1:+s}" ]; then usage fi l=$(dirname "${1:-.}") f=$(basename "${1}") p() { echo "$l/$f"; } SOL="${2:-$l/SOLTASK}" p_err() { printf "ERR: %s\n" "$@" >&2 exit 1 } p_msg() { printf "\033[1m=>\033[0m %s\n" "$@" >&2 } confirm() {( printf "overwrite? \033[1m(y/n)\033[0m " read REPLY case $REPLY in y|Y) exit 0 ;; *) exit 1 ;; esac )} if ! [ -f "$(p)" ]; then p_err "$(p) : not a file." fi if ! [ -f "$SOL" ]; then p_err "$SOL : not a file." fi g=$(grep '^[^#]*SOLSUM=' "$SOL")\ || p_err "$SOL contains no SOLSUM=..." if [ 1 -lt $(echo "$g" |wc -l) ]; then p_err "$SOL has redundant SOLSUMs"' '"$g" elif echo "$g" |grep -q 'SOLSUM="PASS"'; then p_err "$SOL -> SOLSUM=PASS" fi SUM=$(sha256sum "$(p)") SUM="${SUM%% *}" p_msg "$SUM "''">$SOL"'' #** ** DEN ** ** #case $? in #1) p_err ... ;; #2) p_err ... ;; #*) p_err "status unknown" ;; #esac #** ** END ** ** a=$(sed 's:^[^#]*SOLSUM=.*:SOLSUM="'"$SUM"'":' "$SOL") if ! $Y; then echo "$a" >&2 confirm fi echo "$a" >"$SOL"