#!/bin/bash function help { cat </dev/null); then ettus_githash32="0$short_hash" else ettus_githash32="f$short_hash" fi fi fi # Second attempt: Read from file if it exists if [[ $git_success -eq 0 ]]; then if [[ -f $hashfile ]]; then ettus_githash32=$(cat $hashfile) fi fi echo ${ettus_githash32} exit 0 else # Require git command -v git >/dev/null || { echo "ERROR: git not found"; exit 1; } # Get hash from git short_hash="$(git rev-parse --verify HEAD --short=7 2>/dev/null)" || { echo "ERROR: Not a git tree"; exit 2; } # Check if tree is clean. If yes, the top 4 bits are 0 if (git diff --quiet 2>/dev/null); then ettus_githash32="0$short_hash" else ettus_githash32="f$short_hash" fi echo $ettus_githash32 > $hashfile echo "INFO: Wrote $ettus_githash32 to $hashfile" exit 0 fi