Make scripts POSIX compatible

Rewrote repo-info.sh, tag-release.sh and build-presets.sh to remove
the need for bash when compiling.
This commit is contained in:
robxnano 2023-03-18 18:56:12 +00:00 committed by Damiano Galassi
parent 3973157911
commit e489823ecb
4 changed files with 48 additions and 57 deletions

26
configure vendored
View File

@ -13,23 +13,19 @@ inpath()
return 1 return 1
} }
if ( inpath bash ); then pp=""
pp="" for p in python3 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python2 python2.7 python
for p in python3 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python2 python2.7 python do
do if ( inpath $p ); then
if ( inpath $p ); then pp="$p"
pp="$p" break
break
fi
done
if [ "$pp" != "" ]; then
exec $pp `dirname $0`/make/configure.py "$@"
exit 0
else
echo "ERROR: no suitable version of python found."
fi fi
done
if [ "$pp" != "" ]; then
exec $pp `dirname $0`/make/configure.py "$@"
exit 0
else else
echo "ERROR: bash shell not found." echo "ERROR: no suitable version of python found."
fi fi
exit 1 exit 1

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/bin/sh
# usage: build-presets # usage: build-presets
SELF="${BASH_SOURCE[0]}" SELF="$0"
SELF_DIR=$(cd $(dirname "${SELF}") && pwd -P) SELF_DIR=$(cd $(dirname "${SELF}") && pwd -P)
SELF_DIR="${SELF_DIR:-$(pwd)}" SELF_DIR="${SELF_DIR:-$(pwd)}"
LIBHB_DIR="${SELF_DIR}/../libhb" LIBHB_DIR="${SELF_DIR}/../libhb"
@ -14,7 +14,7 @@ fi
JSON_TEMP=$(mktemp preset_builtin.json.XXX) JSON_TEMP=$(mktemp preset_builtin.json.XXX)
C_TEMP=$(mktemp preset_builtin.h.XXX) C_TEMP=$(mktemp preset_builtin.h.XXX)
if [[ "${JSON_TEMP:-}" == "" ]] || [[ "${C_TEMP:-}" == "" ]]; then if [ "${JSON_TEMP:-}" = "" ] || [ "${C_TEMP:-}" = "" ]; then
echo "unable to create temporary files" >2 echo "unable to create temporary files" >2
exit 1 exit 1
fi fi

View File

@ -1,18 +1,16 @@
#!/usr/bin/env bash #!/bin/sh
# #
# Retrieves git repository info for directory ${1} using command ${2} # Retrieves git repository info for directory ${1} using command ${2}
function repo_info() repo_info()
{ {
local repo_dir git_exe commit upstream err
# Process args # Process args
repo_dir='.' repo_dir='.'
if [[ ${1} ]]; then if [ -n "${1}" ]; then
repo_dir=${1} repo_dir=${1}
fi fi
git_exe='git' git_exe="git"
if [[ ${2} ]]; then if [ -n "${2}" ]; then
git_exe=${2} git_exe=${2}
fi fi
@ -23,19 +21,19 @@ function repo_info()
fi fi
# Check whether we have git # Check whether we have git
if ! hash ${git_exe} 2>/dev/null; then if [ -z "$(command -v ${git_exe})" ]; then
echo "Command '${git_exe}' not found." 1>&2 echo "Command '${git_exe}' not found." 1>&2
return 1 return 1
fi fi
# Check if there is a valid git repo here # Check if there is a valid git repo here
HASH=$(${git_exe} rev-parse HEAD) HASH=$(${git_exe} rev-parse HEAD 2> /dev/null)
SHORTHASH=$(${git_exe} rev-parse --short HEAD) SHORTHASH=$(${git_exe} rev-parse --short HEAD 2> /dev/null)
err=$? err=$?
if [[ ${err} -ne 0 ]]; then if [ $err -ne 0 ]; then
echo "Not a valid repository." 1>&2 echo "Not a valid repository." 1>&2
return ${err} return ${err}
elif [[ -z ${HASH} ]]; then elif [ -z "${HASH}" ]; then
echo "Not a valid repository." 1>&2 echo "Not a valid repository." 1>&2
return 1 return 1
fi fi
@ -45,8 +43,8 @@ function repo_info()
# check if an annotated tag is reachable from HEAD # check if an annotated tag is reachable from HEAD
TAG=$(${git_exe} describe --tags --abbrev=0 --exact-match --match \[0-9\]\*.\[0-9\]\*.\[0-9\]\* HEAD 2> /dev/null) TAG=$(${git_exe} describe --tags --abbrev=0 --exact-match --match \[0-9\]\*.\[0-9\]\*.\[0-9\]\* HEAD 2> /dev/null)
if [[ ${TAG} ]]; then if [ -n "${TAG}" ]; then
# if TAG is a release tag and HASH == TAG_HASH, this is release code # if TAG is a release tag and HASH == TAG_HASH, this is release code
TAG_HASH=$(${git_exe} rev-list ${TAG} --max-count=1) TAG_HASH=$(${git_exe} rev-list ${TAG} --max-count=1)
REV=$(${git_exe} rev-list $(${git_exe} merge-base ${TAG} HEAD).. --count) REV=$(${git_exe} rev-list $(${git_exe} merge-base ${TAG} HEAD).. --count)
else else
@ -56,7 +54,7 @@ function repo_info()
BRANCH=$(${git_exe} symbolic-ref -q --short HEAD) BRANCH=$(${git_exe} symbolic-ref -q --short HEAD)
REMOTE="${URL}" REMOTE="${URL}"
upstream=$(${git_exe} config branch.${BRANCH}.remote) upstream=$(${git_exe} config branch.${BRANCH}.remote)
if [[ ${upstream} ]]; then if [ -n "${upstream}" ]; then
REMOTE="${upstream}" REMOTE="${upstream}"
fi fi
DATE=$(${git_exe} log -1 --format="format:%ci") DATE=$(${git_exe} log -1 --format="format:%ci")
@ -66,9 +64,9 @@ function repo_info()
echo "URL=${URL}" echo "URL=${URL}"
echo "HASH=${HASH}" echo "HASH=${HASH}"
echo "SHORTHASH=${SHORTHASH}" echo "SHORTHASH=${SHORTHASH}"
if [[ ${TAG} ]]; then echo "TAG=${TAG}"; fi if [ -n "${TAG}" ]; then echo "TAG=${TAG}"; fi
if [[ ${TAG_HASH} ]]; then echo "TAG_HASH=${TAG_HASH}"; fi if [ -n "${TAG_HASH}" ]; then echo "TAG_HASH=${TAG_HASH}"; fi
if [[ ${REV} ]]; then echo "REV=${REV}"; fi if [ -n "${REV}" ]; then echo "REV=${REV}"; fi
echo "BRANCH=${BRANCH}" echo "BRANCH=${BRANCH}"
echo "REMOTE=${REMOTE}" echo "REMOTE=${REMOTE}"
echo "DATE=${DATE}" echo "DATE=${DATE}"

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/sh
# #
# Usage: tag-release.sh <release-ver> [<ref>] # Usage: tag-release.sh <release-ver> [<ref>]
# #
@ -22,17 +22,14 @@
# git push origin refs/tags/X.Y.Z # git push origin refs/tags/X.Y.Z
# #
SELF="${BASH_SOURCE[0]}"
SELF_NAME=$(basename "${SELF}")
GIT_EXE='git' GIT_EXE='git'
function validate_repo() validate_repo()
{ {
local HASH err AHEAD BEHIND proceed local HASH err AHEAD BEHIND proceed
# Check whether we have git # Check whether we have git
if ! hash ${GIT_EXE} 2>/dev/null; then if [ -z "$(command -v ${GIT_EXE})" ]; then
echo "Command '${GIT_EXE}' not found." 1>&2 echo "Command '${GIT_EXE}' not found." 1>&2
return 1 return 1
fi fi
@ -40,15 +37,15 @@ function validate_repo()
# Check if there is a valid git repo here # Check if there is a valid git repo here
HASH=$(${GIT_EXE} rev-parse HEAD) HASH=$(${GIT_EXE} rev-parse HEAD)
err=$? err=$?
if [[ ${err} -ne 0 ]]; then if [ ${err} -ne 0 ]; then
echo "Not a valid repository." 1>&2 echo "Not a valid repository." 1>&2
return ${err} return ${err}
elif [[ -z ${HASH} ]]; then elif [ -z "${HASH}" ]; then
echo "Not a valid repository." 1>&2 echo "Not a valid repository." 1>&2
return 1 return 1
fi fi
if [[ -n "$(${GIT_EXE} status --porcelain)" ]]; then if [ -n "$(${GIT_EXE} status --porcelain)" ]; then
echo "There are uncommitted changes. Aborting." 1>&2 echo "There are uncommitted changes. Aborting." 1>&2
return 1 return 1
fi fi
@ -56,47 +53,47 @@ function validate_repo()
echo "Fetching repo data..." echo "Fetching repo data..."
${GIT_EXE} fetch ${GIT_EXE} fetch
err=$? err=$?
if [[ ${err} -ne 0 ]]; then if [ ${err} -ne 0 ]; then
echo "Failed to fetch repo data." 1>&2 echo "Failed to fetch repo data." 1>&2
return ${err} return ${err}
fi fi
AHEAD=$(${GIT_EXE} rev-list @{u}..HEAD --count) AHEAD=$(${GIT_EXE} rev-list @{u}..HEAD --count)
BEHIND=$(${GIT_EXE} rev-list HEAD..@{u} --count) BEHIND=$(${GIT_EXE} rev-list HEAD..@{u} --count)
if [[ ${AHEAD} -ne 0 ]]; then if [ ${AHEAD} -ne 0 ]; then
echo "There are unpushed changes. Continue anyway? (y/N)" echo "There are unpushed changes. Continue anyway? (y/N)"
read proceed read proceed
if [[ ( "x${proceed}" != "xy" ) && ( "x${proceed}" != "xY" ) ]] ; then if [ "x${proceed}" != "xy" ] && [ "x${proceed}" != "xY" ] ; then
echo "Aborting..." echo "Aborting..."
return 1 return 1
fi fi
fi fi
if [[ ${BEHIND} -ne 0 ]]; then if [ ${BEHIND} -ne 0 ]; then
echo "There are unmerged upstream changes. Continue anyway? (y/N)" echo "There are unmerged upstream changes. Continue anyway? (y/N)"
read proceed read proceed
if [[ ( "x${proceed}" != "xy" ) && ( "x${proceed}" != "xY" ) ]] ; then if [ "x${proceed}" != "xy" ] && [ "x${proceed}" != "xY" ] ; then
echo "Aborting..." echo "Aborting..."
return 1 return 1
fi fi
fi fi
} }
function tag_release() tag_release()
{ {
local TAG REF COMMIT BRANCH proceed new_branch ERR HASH local TAG REF COMMIT BRANCH proceed new_branch ERR HASH
TAG=${1} TAG=${1}
REF=${2} REF=${2}
if [ "x${TAG}" == "x" ]; then if [ "x${TAG}" = "x" ]; then
echo "Missing release tag (e.g. 1.0.0)" echo "Missing release tag (e.g. 1.0.0)"
echo "Usage: ${SELF_NAME} tag [commit]" echo "Usage: tag-release.sh tag [commit]"
return 1 return 1
fi fi
# bugfix branch name # bugfix branch name
BRANCH=${TAG%.[0-9]*}.x BRANCH=${TAG%.[0-9]*}.x
if [ "x${REF}" == "x" ]; then if [ "x${REF}" = "x" ]; then
echo "Creating release tag ${TAG} and branch ${BRANCH} from HEAD, proceed? (y/N)" echo "Creating release tag ${TAG} and branch ${BRANCH} from HEAD, proceed? (y/N)"
# retrieve full hash of HEAD # retrieve full hash of HEAD
COMMIT=$(${GIT_EXE} rev-list HEAD --max-count=1) COMMIT=$(${GIT_EXE} rev-list HEAD --max-count=1)
@ -106,7 +103,7 @@ function tag_release()
COMMIT=$(${GIT_EXE} rev-list ${REF} --max-count=1) COMMIT=$(${GIT_EXE} rev-list ${REF} --max-count=1)
fi fi
read proceed read proceed
if [[ ( "x${proceed}" != "xy" ) && ( "x${proceed}" != "xY" ) ]] ; then if [ "x${proceed}" != "xy" ] && [ "x${proceed}" != "xY" ] ; then
echo "Aborting..." echo "Aborting..."
return 0 return 0
fi fi
@ -183,7 +180,7 @@ function tag_release()
echo " git push -u origin ${BRANCH}" echo " git push -u origin ${BRANCH}"
echo " git push origin refs/tags/${TAG}" echo " git push origin refs/tags/${TAG}"
read proceed read proceed
if [[ ( "x${proceed}" == "xy" ) || ( "x${proceed}" == "xY" ) ]] ; then if [ "x${proceed}" = "xy" ] || [ "x${proceed}" = "xY" ] ; then
if [ $new_branch .eq 1 ]; then if [ $new_branch .eq 1 ]; then
${GIT_EXE} push -u origin "${BRANCH}" ${GIT_EXE} push -u origin "${BRANCH}"
ERR=$? ERR=$?
@ -204,7 +201,7 @@ function tag_release()
} }
function main() main()
{ {
if validate_repo; then if validate_repo; then
tag_release "$@" tag_release "$@"