generate-version: conform to POSIX sh

This commit is contained in:
Daniel Eklöf 2019-10-19 22:07:38 +02:00
parent c4f9168191
commit 4250ae0a01
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/bin/sh
set -e
@ -10,16 +10,22 @@ out_file=${3}
# echo "source directory: ${src_dir}"
# echo "output file: ${out_file}"
if [[ $(command -v git) ]]; then
new_version="$(git describe --always --tags) ($(env LC_TIME=C date "+%b %d %Y"), branch '$(git rev-parse --abbrev-ref HEAD)')"
if command -v git > /dev/null; then
workdir=$(pwd)
cd "${src_dir}"
git_version=$(git describe --always --tags)
git_branch=$(git rev-parse --abbrev-ref HEAD)
cd "${workdir}"
new_version="${git_version} ($(env LC_TIME=C date "+%b %d %Y"), branch '${git_branch}')"
else
new_version="${default_version}"
fi
new_version="#define YAMBAR_VERSION \"${new_version}\""
if [[ -f "${out_file}" ]]; then
old_version=$(<"${out_file}")
if [ -f "${out_file}" ]; then
old_version=$(cat "${out_file}")
else
old_version=""
fi
@ -27,6 +33,6 @@ fi
# echo "old version: ${old_version}"
# echo "new version: ${new_version}"
if [[ "${old_version}" != "${new_version}" ]]; then
if [ "${old_version}" != "${new_version}" ]; then
echo "${new_version}" > "${out_file}"
fi