Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build versions that aren't me making up numbers? via https://blog.twi…
- Loading branch information
Showing
7 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash -euo pipefail | ||
# https://blog.twitch.tv/ios-versioning-89e02f0a5146 | ||
|
||
if [ ${#} -eq 0 ] | ||
then | ||
# read from STDIN | ||
MAYBE_GIT_HASH=$( cat ) | ||
else | ||
MAYBE_GIT_HASH="${1}" | ||
fi | ||
|
||
LEGAL_GIT_HASH_CHARACTERS="0123456789ABCDEFabcdef" | ||
# grep regex doesn't allow + metacharacter :( | ||
HASH_GREP_REGEX='^['"${LEGAL_GIT_HASH_CHARACTERS}"']['"${LEGAL_GIT_HASH_CHARACTERS}"']*$' | ||
GIT_HASH=$( echo "${MAYBE_GIT_HASH}" | grep "${HASH_GREP_REGEX}" ) || { | ||
echo "\"${MAYBE_GIT_HASH}\" doesnt look like a git hash. A git hash should have only: \"${LEGAL_GIT_HASH_CHARACTERS}\"" >&2 | ||
exit 1 | ||
} | ||
|
||
# We must prefix the git hash with a 1 | ||
# If it starts with a zero, when we decimalize it, | ||
# and later hexify it, we'll lose the zero. | ||
ONE_PREFIXED_GIT_HASH=1"${GIT_HASH}" | ||
|
||
# bc requires hex to be uppercase because | ||
# lowercase letters are reserved for bc variables | ||
UPPERCASE_ONE_PREFIXED_GIT_HASH=$( echo "${ONE_PREFIXED_GIT_HASH}" | tr "[:lower:]" "[:upper:]" ) | ||
|
||
# convert to decimal | ||
# See "with bc": http://stackoverflow.com/a/13280173/9636 | ||
echo "ibase=16;obase=A;${UPPERCASE_ONE_PREFIXED_GIT_HASH}" | bc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash -euo pipefail | ||
# https://blog.twitch.tv/ios-versioning-89e02f0a5146 | ||
|
||
if [ ${#} -eq 0 ] | ||
then | ||
# read from STDIN | ||
MAYBE_CFBUNDLEVERSION=$( cat ) | ||
else | ||
MAYBE_CFBUNDLEVERSION="${1}" | ||
fi | ||
|
||
MAYBE_DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH=$( echo "${MAYBE_CFBUNDLEVERSION}" | sed 's/[0-9][0-9]*\.\([0-9][0-9]*\)/\1/' ) | ||
|
||
LEGAL_DECIMALIZED_GIT_HASH_CHARACTERS="0123456789" | ||
# grep regex doesn't allow + metacharacter :( | ||
DECIMALIZED_GREP_REGEX='^['"${LEGAL_DECIMALIZED_GIT_HASH_CHARACTERS}"']['"${LEGAL_DECIMALIZED_GIT_HASH_CHARACTERS}"']*$' | ||
DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH=$( echo "${MAYBE_DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH}" | grep "${DECIMALIZED_GREP_REGEX}" ) || { | ||
echo "\"${MAYBE_CFBUNDLEVERSION}\" doesnt look like a CFBundleVersion we expect. It should contain two dot-separated numbers." >&2 | ||
exit 1 | ||
} | ||
|
||
# convert to hex | ||
# http://stackoverflow.com/a/379422/9636 | ||
MAYBE_ONE_PREFIXED_GIT_HASH=$( echo "ibase=10;obase=16;${DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH}" | bc ) | ||
|
||
#grep doesn't allow + metacharacter. Thus match any one: (.) then any zero or more: (.*) | ||
ONE_PREFIXED_GIT_HASH=$( echo "${MAYBE_ONE_PREFIXED_GIT_HASH}" | grep '^1..*$' ) || { | ||
echo "\"${MAYBE_CFBUNDLEVERSION}\"'s second number, \"${MAYBE_DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH}\", is \"${MAYBE_ONE_PREFIXED_GIT_HASH}\" in hex, which didnt start with a \"1\"." >&2 | ||
exit 2 | ||
} | ||
|
||
# Read ${ONE_PREFIXED_GIT_HASH} starting at position 1. | ||
# See "Variable expansion / Substring replacement" in | ||
# http://www.tldp.org/LDP/abs/html/parameter-substitution.html | ||
UPPERCASED_GIT_HASH="${ONE_PREFIXED_GIT_HASH:1}" | ||
|
||
# bc uses uppercase letters for hex because | ||
# it reserves lowercase letters for variables | ||
# but git hashes are written with lowercase letters | ||
# so convert to lowercase to look more git-like | ||
GIT_HASH=$( echo "${UPPERCASED_GIT_HASH}" | tr "[:upper:]" "[:lower:]" ) | ||
|
||
echo "${GIT_HASH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -euo pipefail | ||
# https://blog.twitch.tv/ios-versioning-89e02f0a5146 | ||
|
||
if [ ${#} -eq 0 ] | ||
then | ||
# read from STDIN | ||
DATE=$( cat ) | ||
else | ||
DATE="${1}" | ||
fi | ||
|
||
SECONDS_FROM_EPOCH_TO_NOW=$( date "+%s" ) | ||
SECONDS_FROM_EPOCH_TO_DATE=$( date -j -f "%b %d %Y %T %Z" "${DATE}" "+%s" ) | ||
|
||
MINUTES_SINCE_DATE=$(( $(( ${SECONDS_FROM_EPOCH_TO_NOW}-${SECONDS_FROM_EPOCH_TO_DATE} ))/60 )) | ||
|
||
echo "${MINUTES_SINCE_DATE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash -euo pipefail | ||
# https://blog.twitch.tv/ios-versioning-89e02f0a5146 | ||
|
||
# When we increment OB_BUNDLE_SHORT_VERSION_STRING | ||
# also update OB_BUNDLE_SHORT_VERSION_DATE to the current date/time | ||
# we don't have to be very exact, but it should be updated at least | ||
# once every 18 months because iTunes requires that a CFBundleVersion | ||
# be at most 18 characters long, and DECIMALIZED_GIT_HASH will be | ||
# at most 10 characters long. Thus, MINUTES_SINCE_DATE needs to be | ||
# at most 7 characters long so we can use the format: | ||
# ${MINUTES_SINCE_DATE}.${DECIMALIZED_GIT_HASH} | ||
# | ||
OB_BUNDLE_SHORT_VERSION_DATE="October 9 2018 00:00:00 GMT" | ||
OB_BUNDLE_SHORT_VERSION_STRING=2.1.990 | ||
|
||
BASH_SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
MINUTES_SINCE_DATE="$( cd "${BASH_SOURCE_DIR}" && ./minutes_since_date.bash "${OB_BUNDLE_SHORT_VERSION_DATE}" )" | ||
|
||
# decimalized git hash is guaranteed to be 10 characters or fewer because | ||
# the biggest short=7 git hash we can get is FFFFFFF and | ||
# $ ./decimalize_git_hash.bash FFFFFFF | wc -c | ||
# > 10 | ||
DECIMALIZED_GIT_HASH="$( cd "${BASH_SOURCE_DIR}"; ./decimalize_git_hash.bash $( git rev-parse --short=7 HEAD ) )" | ||
echo "Decimalized: \"${DECIMALIZED_GIT_HASH}\"" | ||
|
||
OB_BUNDLE_VERSION="${MINUTES_SINCE_DATE}"."${DECIMALIZED_GIT_HASH}" | ||
|
||
echo $OB_BUNDLE_SHORT_VERSION_STRING | ||
echo $OB_BUNDLE_VERSION | ||
|
||
cat <<EOF > "${SRCROOT}"/OnionBrowser/version.h | ||
#define OBBundleShortVersionString ${OB_BUNDLE_SHORT_VERSION_STRING} | ||
#define OBBundleVersion ${OB_BUNDLE_VERSION} | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters