#=============================================================================== # Common shell utilities: logging, command checks, checksum verification. # # Sourced by: build.sh # Sourced globals: (none) # Modifies globals: (none) #=============================================================================== check_command() { if ! command -v "$1" &> /dev/null; then echo "$1 not found" return 1 else echo "$1 found" return 0 fi } section_header() { echo -e "\033[1;36m--- $1 ---\033[0m" } section_footer() { echo -e "\033[1;36m--- End $1 ---\033[0m" } verify_sha256() { local file_path="$1" local expected_hash="$2" local label="${3:-file}" if [[ -z $expected_hash ]]; then echo "Warning: No SHA-256 hash for ${label}," \ 'skipping verification' >&2 return 0 fi echo "Verifying SHA-256 checksum for ${label}..." local actual_hash _ read -r actual_hash _ < <(sha256sum "$file_path") if [[ $actual_hash != "$expected_hash" ]]; then echo "SHA-256 mismatch for ${label}!" >&2 echo " Expected: $expected_hash" >&2 echo " Actual: $actual_hash" >&2 return 1 fi echo "SHA-256 verified: ${label}" }