#!/bin/sh # TODO: Think of a way to generate version without git repository for source tarballs. Making the script overwrite # itself with a static version sounds good enough, really. try_tag() { local tag if tag=$(git describe --exact-match --tags --dirty=-dirty 2>/dev/null); then case "${tag}" in *-dirty) return 1;; *) echo "${tag}"; return 0;; esac fi return 1 } if ! version=$(try_tag); then fmt=%Y%m%d if git diff-index --quiet HEAD --; then latest="$(git rev-list -1 --date=format:${fmt} --pretty=%ad --no-commit-header HEAD)" modified=0 else latest="$(date +${fmt})" modified=1 fi count=$(git rev-list --date=format:${fmt} --pretty=%ad --no-commit-header HEAD | sed -n /${latest}/p | wc -l) count=$(( ${count} + ${modified} )) version="${latest}.${count}" fi echo "${version}"