|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# update the iOS and Android native SDKs |
| 4 | + |
| 5 | +# properties |
| 6 | +script_name=$(basename "$0") |
| 7 | +ios_tag=false |
| 8 | +and_tag=false |
| 9 | + |
| 10 | +# options |
| 11 | +usage() { |
| 12 | + printf "\n invalid usage" |
| 13 | + printf "\n ./%s -h -> help" "$script_name" |
| 14 | + printf "\n ./%s -i 0.13.5 -> build ios" "$script_name" |
| 15 | + printf "\n ./%s -a 2.4.11 -> build android" "$script_name" |
| 16 | + printf "\n" |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +options() { |
| 21 | + # require at least 1 argument |
| 22 | + if [[ "$#" -lt 1 ]]; then usage; fi |
| 23 | + |
| 24 | + # types of arguments (: = disable verbose errors, -h, i: = -i value, a: = -a value) |
| 25 | + while getopts ":hi:a:" opt; do |
| 26 | + case $opt in |
| 27 | + h) |
| 28 | + usage |
| 29 | + ;; |
| 30 | + i) |
| 31 | + ios_tag=${OPTARG} |
| 32 | + ;; |
| 33 | + a) |
| 34 | + and_tag=${OPTARG} |
| 35 | + ;; |
| 36 | + *) |
| 37 | + usage |
| 38 | + ;; |
| 39 | + esac |
| 40 | + done |
| 41 | +} |
| 42 | + |
| 43 | +update_ios() { |
| 44 | + # properties |
| 45 | + path="../../ios/dependencies" |
| 46 | + tag_url="https://github.com/BranchMetrics/ios-branch-deep-linking/archive/$ios_tag.zip" |
| 47 | + zip_tmp=ios-branch-deep-linking-$ios_tag |
| 48 | + |
| 49 | + # validate and download |
| 50 | + check_tag "$tag_url" |
| 51 | + download_sdk "$path" "$tag_url" "$zip_tmp" |
| 52 | + |
| 53 | + # copy in new dependencies |
| 54 | + mv "$zip_tmp/Branch-SDK/Branch-SDK" "$path" |
| 55 | + mv "$zip_tmp/Branch-SDK/Fabric" "$path" |
| 56 | + |
| 57 | + # replace all instances of '#import "../Fabric/' with '#import "' in .m files |
| 58 | + find "$path" -type f -name '*.m' -exec perl -i -pe 's/\#import \"\.\.\/Fabric\//#import "/' '{}' + |
| 59 | + |
| 60 | + # clean up |
| 61 | + remove_tmp "$zip_tmp" |
| 62 | +} |
| 63 | + |
| 64 | +update_and() { |
| 65 | + # properties |
| 66 | + path="../../android/dependencies" |
| 67 | + tag_url="https://github.com/BranchMetrics/android-branch-deep-linking/archive/$and_tag.zip" |
| 68 | + zip_tmp=android-branch-deep-linking-$and_tag |
| 69 | + |
| 70 | + # validate and download |
| 71 | + check_tag "$tag_url" |
| 72 | + download_sdk "$path" "$tag_url" "$zip_tmp" |
| 73 | + |
| 74 | + # copy in new dependencies |
| 75 | + mv "$zip_tmp/Branch-$and_tag.jar" "$path" |
| 76 | + |
| 77 | + # clean up |
| 78 | + remove_tmp "$zip_tmp" |
| 79 | +} |
| 80 | + |
| 81 | +check_tag() { |
| 82 | + # check that tag exists |
| 83 | + tag_url_status=$(curl -L -o /dev/null --silent --head --write-out '%{http_code}\n' "$tag_url") |
| 84 | + if [ "$tag_url_status" = "200" ]; then |
| 85 | + echo "downloading $tag_url" |
| 86 | + else |
| 87 | + echo "could not find '$tag_url'" |
| 88 | + echo "curl returned status '$tag_url_status'" |
| 89 | + exit -1 |
| 90 | + fi |
| 91 | +} |
| 92 | + |
| 93 | +download_sdk() { |
| 94 | + # overwrite any existing versions of sdk.zip |
| 95 | + curl -L -o "$path"/sdk.zip "$tag_url" |
| 96 | + |
| 97 | + # delete old extracted content |
| 98 | + rm -rf "$zip_tmp" |
| 99 | + |
| 100 | + # silently (-q) extract download |
| 101 | + unzip -q -x "$path"/sdk.zip |
| 102 | + |
| 103 | + # remove |
| 104 | + rm -rf "${path:?}"/* |
| 105 | +} |
| 106 | + |
| 107 | +remove_tmp() { |
| 108 | + # clean up extract |
| 109 | + rm -rf "$zip_tmp" |
| 110 | +} |
| 111 | + |
| 112 | +main() { |
| 113 | + # cd into directory containing this script |
| 114 | + cd "$(dirname "$0")" |
| 115 | + |
| 116 | + # fail fast on errors |
| 117 | + set -e |
| 118 | + |
| 119 | + # install sdk |
| 120 | + if [[ "$ios_tag" != "false" ]]; then |
| 121 | + update_ios |
| 122 | + fi |
| 123 | + if [[ "$and_tag" != "false" ]]; then |
| 124 | + update_and |
| 125 | + fi |
| 126 | +} |
| 127 | + |
| 128 | +options "$@" |
| 129 | +main |
0 commit comments