|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +cd "$(dirname "$0")" |
| 4 | +if [ "$1" = clean ]; then |
| 5 | + target=Common/CommonResource.h |
| 6 | + grep -q '^#define EDCB_VERSION_EXTRA ' $target |
| 7 | + if [ $? -eq 0 ]; then |
| 8 | + grep -v '^#define EDCB_VERSION_EXTRA ' $target | sed 's/$/\r/' >$target.new |
| 9 | + mv $target.new $target |
| 10 | + fi |
| 11 | + |
| 12 | + target=EpgTimer/EpgTimer/AppVersion.cs |
| 13 | + grep -q '^ *const string VERSION_EXTRA = "";' $target |
| 14 | + if [ $? -ne 0 ]; then |
| 15 | + grep -v '^ *\(}\|const string VERSION_EXTRA =\)' $target | sed 's/$/\r/' >$target.new |
| 16 | + echo -e " const string VERSION_EXTRA = \"\";\r\n }\r\n}\r" >>$target.new |
| 17 | + mv $target.new $target |
| 18 | + fi |
| 19 | +elif [ "$1" = gen ]; then |
| 20 | + git_hash=$(git rev-parse --short=7 HEAD) |
| 21 | + if [ $? -eq 0 ]; then |
| 22 | + target=Common/CommonResource.h |
| 23 | + grep -qF "$git_hash" $target |
| 24 | + if [ $? -ne 0 ]; then |
| 25 | + echo -e "#define EDCB_VERSION_EXTRA \"[$git_hash]\"\r" >$target.new |
| 26 | + grep -v '^#define EDCB_VERSION_EXTRA ' $target | sed 's/$/\r/' >>$target.new |
| 27 | + mv $target.new $target |
| 28 | + fi |
| 29 | + |
| 30 | + target=EpgTimer/EpgTimer/AppVersion.cs |
| 31 | + grep -qF "$git_hash" $target |
| 32 | + if [ $? -ne 0 ]; then |
| 33 | + grep -v '^ *\(}\|const string VERSION_EXTRA =\)' $target | sed 's/$/\r/' >$target.new |
| 34 | + echo -e " const string VERSION_EXTRA = \"[$git_hash]\";\r\n }\r\n}\r" >>$target.new |
| 35 | + mv $target.new $target |
| 36 | + fi |
| 37 | + fi |
| 38 | +elif [ "$1" = edittag ]; then |
| 39 | + target=Common/CommonResource.h |
| 40 | + if [ -z "$2" ]; then |
| 41 | + sed "0,/^\\/*#define EDCB_VERSION_TAG / s|^/*\\(#define EDCB_VERSION_TAG \\).*|//\\1\"\"|" $target | sed 's/$/\r/' >$target.new |
| 42 | + else |
| 43 | + sed "0,/^\\/*#define EDCB_VERSION_TAG / s|^/*\\(#define EDCB_VERSION_TAG \\).*|\\1\"$2\"|" $target | sed 's/$/\r/' >$target.new |
| 44 | + fi |
| 45 | + mv $target.new $target |
| 46 | + |
| 47 | + target=EpgTimer/EpgTimer/AppVersion.cs |
| 48 | + sed "s|^\\( *const string VERSION_TAG = \\).*|\\1\"$2\";|" $target | sed 's/$/\r/' >$target.new |
| 49 | + mv $target.new $target |
| 50 | +else |
| 51 | + echo 'Usage: versionhash.sh clean|gen|edittag [<tag>]' |
| 52 | + exit 2 |
| 53 | +fi |
0 commit comments