-
Notifications
You must be signed in to change notification settings - Fork 83
/
launch.sh
executable file
·162 lines (139 loc) · 3.35 KB
/
launch.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
set -e
# ----- Help
help_message() {
cat <<- _EOF_
Helper script to build a branch run it on a device
Usage: $SCRIPT_NAME [-b|--branch branch] [-g|--gdk app|master|commitHash] [-d|--development] [-u|--uninstall] [-h|--help]
Options:
-h, --help Display this help message and exit
-b, --branch Checkout remote branch
-g, --gdk Download GDK [app (app version), master (latest master), commitHash (specific commit hash)]
-d, --development Development flavor
-a, --add-wallet Add wallet and login credentials
-q, --qa Launch QA Tester activity
-u, --uninstall Uninstall before install
_EOF_
exit 0
}
# ----- Vars
FLAVOR="production"
GDK=false
ADD_WALLET=false
BRANCH=false
UNINSTALL=false
PACKAGE="com.greenaddress.greenbits_android_wallet"
LAUNCH_ACTIVITY="MainActivity"
# --- Argument handling
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
help_message ;;
-b | --branch)
shift
BRANCH=$1
shift ;;
-g | --gdk)
shift
GDK=$1
shift ;;
-a | --add-wallet)
shift
ADD_WALLET=$1
shift ;;
-u | --uninstall)
UNINSTALL=true
shift ;;
-d | --development)
FLAVOR="development"
shift ;;
-f | --fdroid)
FLAVOR="fdroid"
shift ;;
-b | --branch )
shift
BRANCH=("$1")
shift ;;
-q | --qa )
LAUNCH_ACTIVITY="QATesterActivity"
shift ;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]:-}" # restore positional parameters
# --- Functions
uninstall(){
echo "Uninstalling.."
if [[ $FLAVOR == "production" ]]; then
./gradlew uninstallProductionDebug
elif [[ $FLAVOR == "fdroid" ]]; then
./gradlew uninstallProductionFDroidDebug
else
./gradlew uninstallDevelopmentDebug
fi
}
install(){
if [[ $FLAVOR == "production" ]]; then
./gradlew installProductionDebug
elif [[ $FLAVOR == "fdroid" ]]; then
./gradlew installProductionFDroidDebug
else
./gradlew installDevelopmentDebug
fi
}
launch(){
# kill
adb shell am force-stop $PACKAGE
# launch
if [[ $1 != false ]]; then
adb shell am start -n "$PACKAGE/com.blockstream.green.ui.$LAUNCH_ACTIVITY" --es ADD_WALLET $1
else
adb shell am start -n "$PACKAGE/com.blockstream.green.ui.$LAUNCH_ACTIVITY"
fi
}
checkout(){
echo "Checking out $1"
git checkout $1
git reset --hard origin/$1
git status
}
gdk(){
if [[ $GDK == "app" ]]; then
./gdk/fetch_android_binaries.sh
else
# Export the GDK_COMMIT for it to be appended in app version
export GDK_COMMIT=$1
./gdk/fetch_android_binaries.sh -c $1
fi
}
info(){
echo -e "\n--------------------------------------------------------"
echo "Flavor: $FLAVOR"
echo "Branch: `git branch --show-current`"
echo "Commit Hash: `git rev-parse HEAD`"
echo -e "--------------------------------------------------------\n"
}
info
# --- Execution
if [[ $FLAVOR == "development" ]]; then
PACKAGE="$PACKAGE.dev"
fi
if [[ $BRANCH != false ]]; then
checkout $BRANCH
fi
if [[ $UNINSTALL = true ]]; then
uninstall
fi
if [[ $GDK != false ]]; then
gdk $GDK
fi
install
launch $ADD_WALLET
info