|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +die() { echo "$@" 1>&2 ; exit 1; } |
| 4 | + |
| 5 | +prompt_for_number() { |
| 6 | + local prompt_text=$1 |
| 7 | + local default_value=$2 |
| 8 | + local tmp="" |
| 9 | + while true; do |
| 10 | + read -p "$prompt_text [$default_value]: " tmp |
| 11 | + if [ "$tmp" = "" ]; then |
| 12 | + echo "$default_value"; return |
| 13 | + elif echo "$tmp" | grep -q -E '^[0-9]+$'; then |
| 14 | + echo "$tmp"; return |
| 15 | + fi |
| 16 | + done |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +################################## |
| 21 | +# Switch to top minetest directory |
| 22 | +################################## |
| 23 | + |
| 24 | +cd ${0%/*}/.. |
| 25 | + |
| 26 | + |
| 27 | +####################### |
| 28 | +# Determine old version |
| 29 | +####################### |
| 30 | + |
| 31 | +# Make sure all the files we need exist |
| 32 | +grep -q -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt || die "error: Could not find CMakeLists.txt" |
| 33 | +grep -q -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt || die "error: Could not find CMakeLists.txt" |
| 34 | +grep -q -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt || die "error: Could not find CMakeLists.txt" |
| 35 | +grep -q -E '^ANDROID_VERSION_CODE = [0-9]+$' build/android/Makefile || die "error: Could not find build/android/Makefile" |
| 36 | + |
| 37 | +VERSION_MAJOR=$(grep -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9) |
| 38 | +VERSION_MINOR=$(grep -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9) |
| 39 | +VERSION_PATCH=$(grep -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt | tr -dC 0-9) |
| 40 | +ANDROID_VERSION_CODE=$(grep -E '^ANDROID_VERSION_CODE = [0-9]+$' build/android/Makefile | tr -dC 0-9) |
| 41 | + |
| 42 | +echo "Current Minetest version: $VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" |
| 43 | +echo "Current Android version code: $ANDROID_VERSION_CODE" |
| 44 | + |
| 45 | + |
| 46 | +######################## |
| 47 | +# Prompt for new version |
| 48 | +######################## |
| 49 | + |
| 50 | +NEW_VERSION_MAJOR=$VERSION_MAJOR |
| 51 | +NEW_VERSION_MINOR=$VERSION_MINOR |
| 52 | +NEW_VERSION_PATCH=$(expr $VERSION_PATCH + 1) |
| 53 | + |
| 54 | +NEW_VERSION_MAJOR=$(prompt_for_number "Set major" $NEW_VERSION_MAJOR) |
| 55 | + |
| 56 | +if [ "$NEW_VERSION_MAJOR" != "$VERSION_MAJOR" ]; then |
| 57 | + NEW_VERSION_MINOR=0 |
| 58 | + NEW_VERSION_PATCH=0 |
| 59 | +fi |
| 60 | + |
| 61 | +NEW_VERSION_MINOR=$(prompt_for_number "Set minor" $NEW_VERSION_MINOR) |
| 62 | + |
| 63 | +if [ "$NEW_VERSION_MINOR" != "$VERSION_MINOR" ]; then |
| 64 | + NEW_VERSION_PATCH=0 |
| 65 | +fi |
| 66 | + |
| 67 | +NEW_VERSION_PATCH=$(prompt_for_number "Set patch" $NEW_VERSION_PATCH) |
| 68 | + |
| 69 | +NEW_ANDROID_VERSION_CODE=$(expr $ANDROID_VERSION_CODE + 1) |
| 70 | +NEW_ANDROID_VERSION_CODE=$(prompt_for_number "Set android version code" $NEW_ANDROID_VERSION_CODE) |
| 71 | + |
| 72 | +NEW_VERSION="$NEW_VERSION_MAJOR.$NEW_VERSION_MINOR.$NEW_VERSION_PATCH" |
| 73 | + |
| 74 | + |
| 75 | +echo |
| 76 | +echo "New version: $NEW_VERSION" |
| 77 | +echo "New android version code: $NEW_ANDROID_VERSION_CODE" |
| 78 | + |
| 79 | + |
| 80 | +####################################### |
| 81 | +# Replace version everywhere and commit |
| 82 | +####################################### |
| 83 | + |
| 84 | +sed -i -re "s/^set\(VERSION_MAJOR [0-9]+\)$/set(VERSION_MAJOR $NEW_VERSION_MAJOR)/" CMakeLists.txt || die "Failed to update VERSION_MAJOR" |
| 85 | + |
| 86 | +sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEW_VERSION_MINOR)/" CMakeLists.txt || die "Failed to update VERSION_MINOR" |
| 87 | + |
| 88 | +sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEW_VERSION_PATCH)/" CMakeLists.txt || die "Failed to update VERSION_PATCH" |
| 89 | + |
| 90 | +sed -i -re "s/^\tset\(VERSION_PATCH \\\$.VERSION_PATCH}-dev\)$/\t#set(VERSION_PATCH \${VERSION_PATCH}-dev)/" CMakeLists.txt || die "Failed to disable -dev suffix" |
| 91 | + |
| 92 | +sed -i -re "s/^ANDROID_VERSION_CODE = [0-9]+$/ANDROID_VERSION_CODE = $NEW_ANDROID_VERSION_CODE/" build/android/Makefile || die "Failed to update ANDROID_VERSION_CODE" |
| 93 | + |
| 94 | +sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" doc/lua_api.txt || die "Failed to update doc/lua_api.txt" |
| 95 | + |
| 96 | +sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" doc/menu_lua_api.txt || die "Failed to update doc/menu_lua_api.txt" |
| 97 | + |
| 98 | +git add -f CMakeLists.txt build/android/Makefile doc/lua_api.txt doc/menu_lua_api.txt || die "git add failed" |
| 99 | + |
| 100 | +git commit -m "Bump version to $NEW_VERSION" || die "git commit failed" |
0 commit comments