avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Prints help text |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 4 | function usage { |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 5 | cat << END |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 6 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 7 | Usage: $progname [--channel CHANNEL] |
| 8 | |
| 9 | optional arguments: |
| 10 | -h, --help show this help message and exit |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 11 | -c, --channel indicates the channel of the release. Can be "beta" |
| 12 | or "stable". Defaults to "stable". |
| 13 | -b, --browser indicates the target browser for the release. Can be |
| 14 | "chromium" or "gecko". Defaults to "chromium". |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 15 | |
| 16 | END |
| 17 | } |
| 18 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 19 | # Updates manifest.json field |
| 20 | function set_manifest_field { |
| 21 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json |
| 22 | } |
| 23 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 24 | # Get options |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 25 | opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@") |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 26 | eval set -- "$opts" |
| 27 | |
| 28 | channel=stable |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 29 | browser=chromium |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 30 | |
| 31 | while true; do |
| 32 | case "$1" in |
| 33 | -h | --help ) usage; exit; ;; |
| 34 | -c | --channel ) channel="$2"; shift 2 ;; |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 35 | -b | --browser ) browser="$2"; shift 2 ;; |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 36 | * ) break ;; |
| 37 | esac |
| 38 | done |
| 39 | |
| 40 | if [[ $channel != "stable" && $channel != "beta" ]]; then |
| 41 | echo "channel parameter value is incorrect." |
| 42 | usage |
| 43 | exit |
| 44 | fi |
| 45 | |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 46 | if [[ $browser != "chromium" && $browser != "gecko" ]]; then |
| 47 | echo "browser parameter value is incorrect." |
| 48 | usage |
| 49 | exit |
| 50 | fi |
| 51 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 52 | echo "Started building release..." |
| 53 | |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 54 | # First of all, generate the appropriate manifest.json file for the |
| 55 | # target browser |
| 56 | dependencies=( ${browser^^} ) |
| 57 | |
| 58 | bash generateManifest.bash "${dependencies[@]}" |
| 59 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 60 | # This is the version name which git gives us |
| 61 | version=$(git describe --always --tags --dirty) |
| 62 | |
| 63 | # If the version name contains a hyphen then it isn't a release |
| 64 | # version. This is also the case if it doesn't start with a "v". |
| 65 | if [[ $version == *"-"* || $version != "v"* ]]; then |
| 66 | # As it isn't a release version, setting version number to 0 so it |
| 67 | # cannot be uploaded to the Chrome Web Store |
| 68 | set_manifest_field "version" "0" |
| 69 | set_manifest_field "version_name" "$version-$channel" |
| 70 | else |
| 71 | # It is a release version, set the version fields accordingly. |
| 72 | set_manifest_field "version" "${version:1}" |
| 73 | set_manifest_field "version_name" "${version:1}-$channel" |
| 74 | fi |
| 75 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 76 | if [[ $channel == "beta" ]]; then |
| 77 | # Change manifest.json to label the release as beta |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 78 | set_manifest_field "name" "__MSG_appNameBeta__" |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 79 | |
| 80 | if [[ $browser == "gecko" ]]; then |
| 81 | # Change the extension ID |
| 82 | set_manifest_field "id" "twpowertools+beta@avm99963.com" |
| 83 | fi |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 84 | fi |
| 85 | |
| 86 | # Create ZIP file for upload to the Chrome Web Store |
| 87 | mkdir -p out |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 88 | rm -rf out/twpowertools-$version-$browser-$channel.zip |
avm99963 | 127837b | 2020-08-09 20:21:03 +0200 | [diff] [blame^] | 89 | (cd src && zip -rq ../out/twpowertools-$version-$browser-$channel.zip * -x *.git*) |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 90 | |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 91 | # Clean generated manifest.json file |
| 92 | rm -f src/manifest.json |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 93 | |
| 94 | echo "Done!" |