-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathupdate-android.sh
executable file
·134 lines (117 loc) · 3.76 KB
/
update-android.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
# ----------
# Setup Code
# ----------
set -euo pipefail
TEMP_DIR=
cleanup() {
if [ "$TEMP_DIR" != "" ]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT_NAME="${0##*/}"
CONFIG_FILE="$SCRIPT_DIR/prepare-android-vendor.config"
print_help() {
echo "Usage: $SCRIPT_NAME [options]"
echo
echo "Options (must select one):"
echo " --version <version> (example: $SCRIPT_NAME --version 5.8.0)"
echo " --local <path> (example: $SCRIPT_NAME --local ../../../bugsnag-android)"
echo " --sha <version> (example: $SCRIPT_NAME --sha 64132f5)"
echo " --list-versions (lists all versions available and exits)"
}
error_bad_opt(){
echo "$SCRIPT_NAME: invalid option '$1'";
echo
print_help
exit 1
}
error_missing_field(){
echo "$SCRIPT_NAME: $1 missing required field";
echo
print_help
exit 1
}
sed_in_place() {
local script="$1"
local file="$2"
if [[ "$OSTYPE" == linux* ]]; then
sed -i "$script" "$file"
else
sed -i '' "$script" "$file"
fi
}
MODE=unset
GIT_TAG=
BUGSNAG_ANDROID_REPO_DIR=
set_bugsnag_version() {
local version=$1
local build_gradle_file="$SCRIPT_DIR/android/build.gradle"
echo "Now using Bugsnag version $version"
sed_in_place "s/api \"com.bugsnag:bugsnag-android:.*/api \"com.bugsnag:bugsnag-android:$version\"/" "$build_gradle_file"
sed_in_place "s/api \"com.bugsnag:bugsnag-plugin-react-native:.*/api \"com.bugsnag:bugsnag-plugin-react-native:$version\"/" "$build_gradle_file"
}
set_bugsnag_version_from_src_dir() {
local src_dir="$(cd "$1" && pwd)"
if [ ! -f "$src_dir/gradlew" ]; then
echo "Source directory doesn't look like the bugsnag-android repo: $src_dir"
exit 1
fi
local bugsnag_android_version=$(cat $src_dir/gradle.properties | grep VERSION_NAME)
set_bugsnag_version "${bugsnag_android_version#*=}-react-native"
}
set_bugsnag_version_from_sha() {
local tag=$1
echo "Checking out https://github.com/bugsnag/bugsnag-android.git with tag $tag"
TEMP_DIR="$(mktemp -d)"
pushd "$TEMP_DIR" >/dev/null
git clone https://github.com/bugsnag/bugsnag-android.git
cd bugsnag-android
git checkout $tag
git submodule update --init --recursive
popd >/dev/null
set_bugsnag_version_from_src_dir "$TEMP_DIR/bugsnag-android"
}
# BSD-friendly getopt-style supporting longopt
while [ $# -gt 0 ]; do
case $1 in
--) shift; break;;
-*) case $1 in
--list-versions)
git ls-remote --tags https://github.com/bugsnag/bugsnag-android.git | \
grep -v "{}" | awk "{print \$2}" | sed 's/refs\/tags\/v//g' | sed 's/refs\/tags\///g'
exit 0
;;
--version)
if [ $# -lt 2 ]; then error_missing_field $1; fi
echo "version" >"$CONFIG_FILE"
echo "$2" >>"$CONFIG_FILE"
set_bugsnag_version "$2"
exit 0
;;
--local)
if [ $# -lt 2 ]; then error_missing_field $1; fi
full_local_path="$(cd "$2" && pwd)"
echo "local" >"$CONFIG_FILE"
echo "$full_local_path" >>"$CONFIG_FILE"
set_bugsnag_version_from_src_dir "$full_local_path"
exit 0
;;
--sha)
if [ $# -lt 2 ]; then error_missing_field $1; fi
echo "sha" >"$CONFIG_FILE"
echo "$2" >>"$CONFIG_FILE"
set_bugsnag_version_from_sha "$2"
exit 0
;;
-*)
error_bad_opt $1;;
esac;;
*) error_bad_opt $1;;
esac
shift
done
print_help
exit 1