-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfigure-android.sh
executable file
·381 lines (348 loc) · 15.7 KB
/
configure-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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash
# Colors
RED='\033[31m'
GREEN='\033[1;32m'
BLUE='\033[0;34m'
NC='\033[0m'
# Vars
ANDROID_STRINGS="./android/app/src/main/res/values/strings.xml"
ANDROID_SPLASH_BACKGROUND_COLOR="./android/app/src/main/res/values/colors.xml"
ANDROID_MANIFEST="./android/app/src/main/AndroidManifest.xml"
CONFIG_FILE="./src/common/Config.js"
APP_NAME=
PACKAGE_NAME=
SITE_URL=
WC_KEY=
WC_SECRET=
FB_APP_ID=
FB_CLIENT_TOKEN=
GOOGLE_GEO_KEY=
# STRIPE_PK=
ONE_SIGNAL_ID=
IC_LAUNCHER=
SPLASH_IMAGE=
SPLASH_BACKGROUND=
UPDATE_STRING=
tmp=$(mktemp) # to hold values of buildScript.json changed by jq temporarily, before writing to actual file
function usage() {
printf "\n"
echo -e "Dokan Android app configuration script.\n"
echo -e " [--app-name=<name>]${GREEN}(required)${NC}"
echo -e "\tName of the app\n"
echo -e " [--package-name=<name>]${GREEN}(required)${NC}"
echo -e "\tUnique package name for your app e.g com.wedevs.dokan or com.dokan\n"
echo -e " [--site-url=<url>]${GREEN}(required)${NC}"
echo -e "\tWebsite url e.g. https://wedevs.com\n"
echo -e " [--wc-key=<key>]${GREEN}(required)${NC}"
echo -e "\tWoocommerce consumer key\n"
echo -e " [--wc-secret=<key>]${GREEN}(required)${NC}"
echo -e "\tWoocommerce consumer secret\n"
echo -e " [--fb-app-id=<key>]${GREEN}(required)${NC}"
echo -e "\tFacbook App ID\n"
echo -e " [--fb-client-token=<key>]${GREEN}(required)${NC}"
echo -e "\tFacbook Client token\n"
echo -e " [--google-geo-key=<key>]${GREEN}(optional)${NC}"
echo -e "\tGoogle maps API key\n"
# echo -e " [--stripe-pk=<key>]${GREEN}(optional)${NC}"
# echo -e "\tStripe publishable key\n"
echo -e " [--onse-signal-id=<key>]${GREEN}(required)${NC}"
echo -e "\tOneSignal App ID\n"
echo -e " [--launcher-icon=<path>]${GREEN}(required)${NC}"
echo -e "\tPath to launcher icon image /path/to/laucnher.png\n"
echo -e " [--splash-image=<path>]${GREEN}(required)${NC}"
echo -e "\tPath to splash image /path/to/splash.png\n"
echo -e " [--splash-background=<hexadecimal color (#FFFFFF)>]${GREEN}(required)${NC}"
echo -e "\tSplash screen background color\n"
echo -e " [--update=<update-key>]${GREEN}(optional)${NC}"
echo -e "\tSingle or comma separated update keys. Available keys are \"siteUrl\", \"wcKeys\", \"fbId\", \"geoKey\", \"stripePk\", \"oneSingalId\", \"iconSet\",\"splashBackground\" \"splashSet\"\n"
}
# Execute with no args
if [[ "$1" == "" ]]; then
usage
exit 1
fi
while [ "$1" != "" ]; do
PARAM=$(echo $1 | awk -F= '{print $1}')
VALUE=$(echo $1 | awk -F= '{print $2}')
case $PARAM in
--app-name)
APP_NAME="$VALUE"
;;
--package-name)
PACKAGE_NAME=$VALUE
;;
--site-url)
SITE_URL=" '$VALUE',"
;;
--wc-key)
WC_KEY=" '$VALUE'"
;;
--wc-secret)
WC_SECRET=" '$VALUE'"
;;
--fb-app-id)
FB_APP_ID=$VALUE
;;
--fb-client-token)
FB_CLIENT_TOKEN=$VALUE
;;
--google-geo-key)
GOOGLE_GEO_KEY=$VALUE
;;
# --stripe-pk)
# STRIPE_PK=" '$VALUE',"
# ;;
--one-signal-id)
ONE_SIGNAL_ID=" '$VALUE',"
;;
--launcher-icon)
IC_LAUNCHER=$VALUE
;;
--splash-image)
SPLASH_IMAGE=$VALUE
;;
--splash-background)
SPLASH_BACKGROUND=$VALUE
;;
--update)
UPDATE_STRING=$VALUE
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
# Validate supplied args
if [[ "$APP_NAME" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--app-name] is required\n"
exit 1
elif [[ "$PACKAGE_NAME" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--package-name] is required\n"
exit 1
elif [[ "$SITE_URL" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--site-url] is required\n"
exit 1
elif [[ "$WC_KEY" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--wc-key] is required\n"
exit 1
elif [[ "$WC_SECRET" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--wc-secret] is required\n"
exit 1
elif [[ "$FB_APP_ID" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--fb-app-id] is required\n"
exit 1
elif [[ "$FB_CLIENT_TOKEN" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--fb-client-token] is required\n"
exit 1
# elif [[ "$GOOGLE_GEO_KEY" == "" && "$UPDATE_STRING" == "" ]]; then
# echo -e "\n${RED}ERROR: ${NC}[--google-geo-key] is required\n"
# exit 1
# elif [[ "$STRIPE_PK" == "" && "$UPDATE_STRING" == "" ]]; then
# echo -e "\n${RED}ERROR: ${NC}[--stripe-pk] is required\n"
# exit 1
elif [[ "$ONE_SIGNAL_ID" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--one-signal-id] is required\n"
exit 1
elif [[ "$IC_LAUNCHER" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--launcher-icon] is required\n"
exit 1
elif [[ "$SPLASH_IMAGE" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--splash-image] is required\n"
exit 1
elif [[ "$SPLASH_BACKGROUND" == "" && "$UPDATE_STRING" == "" ]]; then
echo -e "\n${RED}ERROR: ${NC}[--splash-background] is required\n"
exit 1
fi
# UPDATE_STRING array for updating multiple values all at once
if [[ $UPDATE_STRING == *[,]* ]]; then
IFS=','
read -a updateStrArr <<<"$UPDATE_STRING"
fi
# Creat new project dir
if [[ ! -d "$APP_NAME" ]]; then
echo -e "${BLUE}==> Creating new project...${NC}"
git clone -b master git@github.com:weDevsOfficial/dokan-app.git "$APP_NAME" || exit "$?"
cd "$APP_NAME"
react-native-rename "$APP_NAME" -b "$PACKAGE_NAME"
else
echo -e "${GREEN}Existing project found\n${NC}"
cd "$APP_NAME"
fi
# Replace site url
echo -e "${BLUE}==> Setting Site URL...${NC}"
siteUrl=$(jq -r '.siteUrl' buildScript.json)
if [[ "$siteUrl" == "false" ]]; then
PREV_URL=$(awk -F "url:" '{print $2}' src/common/Config.js | tr -d '\n')
# echo -e "this... $PREV_URL Url....!${NC}"
# echo -e "$SITE_URL Url....!${NC}"
sed -i '' "s|$PREV_URL|$SITE_URL|g" "$CONFIG_FILE"
echo -e "${GREEN}Done!${NC}"
jq '.siteUrl=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
elif [[ "$siteUrl" == "true" && "$UPDATE_STRING" == "siteUrl" || "${updateStrArr[@]}" =~ "siteUrl" ]]; then
PREV_URL=$(awk -F "url:" '{print $2}' src/common/Config.js | tr -d '\n')
sed -i '' "s|$PREV_URL|$SITE_URL|g" "$CONFIG_FILE"
echo -e "${GREEN}Site URL is updated!${NC}"
else
echo -e "${GREEN}Site URL is already configured!${NC}"
fi
# Replace woocommerce values
echo -e "${BLUE}==> Setting WooCommerce API keys...${NC}"
wcKeys=$(jq -r '.wcKeys' buildScript.json)
if [[ "$wcKeys" == "false" ]]; then
sed -i '' 's/\(consumerKey:\)\(.*\)/\1'"$WC_KEY,"'/' "$CONFIG_FILE"
sed -i '' 's/\(consumerSecret:\)\(.*\)/\1'"$WC_SECRET,"'/' "$CONFIG_FILE"
echo -e "${GREEN}Done!${NC}"
jq '.wcKeys=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
elif [[ "$wcKeys" == "true" && "$UPDATE_STRING" == "wcKeys" || "${updateStrArr[@]}" =~ "wcKeys" ]]; then
sed -i '' 's/\(consumerKey:\)\(.*\)/\1'"$WC_KEY,"'/' "$CONFIG_FILE"
sed -i '' 's/\(consumerSecret:\)\(.*\)/\1'"$WC_SECRET,"'/' "$CONFIG_FILE"
echo -e "${GREEN}WooCommerce API keys are updated!${NC}"
else
echo -e "${GREEN}WooCommerce API keys are already configured!${NC}"
fi
# Replace facebook-app-id
echo -e "${BLUE}==> Setting Facebook App ID and client token...${NC}"
androidFbId=$(jq -r '.androidFbId' buildScript.json)
if [[ "$androidFbId" == "false" ]]; then
xmlstarlet ed --inplace -O -u "/resources/string[@name='facebook_app_id']" -v "$FB_APP_ID" "$ANDROID_STRINGS"
xmlstarlet ed --inplace -O -u "/resources/string[@name='facebook_client_token']" -v "$FB_CLIENT_TOKEN" "$ANDROID_STRINGS"
xmlstarlet ed --inplace -O -u "/resources/string[@name='fb_login_protocol_scheme']" -v "fb$FB_APP_ID" "$ANDROID_STRINGS"
xmlstarlet ed --inplace -O -u "/manifest/application/provider[@android:authorities]/@android:authorities" -v "com.facebook.app.FacebookContentProvider$FB_APP_ID" "$ANDROID_MANIFEST"
jq '.androidFbId=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$androidFbId" == "true" && "$UPDATE_STRING" == "fbId" || "${updateStrArr[@]}" =~ "fbId" ]]; then
xmlstarlet ed --inplace -O -u "/resources/string[@name='facebook_app_id']" -v "$FB_APP_ID" "$ANDROID_STRINGS"
xmlstarlet ed --inplace -O -u "/resources/string[@name='facebook_client_token']" -v "$FB_CLIENT_TOKEN" "$ANDROID_STRINGS"
xmlstarlet ed --inplace -O -u "/resources/string[@name='fb_login_protocol_scheme']" -v "fb$FB_APP_ID" "$ANDROID_STRINGS"
xmlstarlet ed --inplace -O -u "/manifest/application/provider[@android:authorities]/@android:authorities" -v "com.facebook.app.FacebookContentProvider$FB_APP_ID" "$ANDROID_MANIFEST"
echo -e "${GREEN}Facebook App Id and client token is updated${NC}"
else
echo -e "${GREEN}Facebook App Id and client token is already configured!${NC}"
fi
# Replace google-geo-key
echo -e "${BLUE}==> Setting Google Maps API key...${NC}"
androidGeoKey=$(jq -r '.androidGeoKey' buildScript.json)
if [[ "$androidGeoKey" == "false" ]]; then
xmlstarlet ed --inplace -O -u "/resources/string[@name='google_map_api_key']" -v "$GOOGLE_GEO_KEY" "$ANDROID_STRINGS"
jq '.androidGeoKey=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$androidGeoKey" == "true" && "$UPDATE_STRING" == "geoKey" || "${updateStrArr[@]}" =~ "geoKey" ]]; then
xmlstarlet ed --inplace -O -u "/resources/string[@name='google_map_api_key']" -v "$GOOGLE_GEO_KEY" "$ANDROID_STRINGS"
jq '.androidGeoKey=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Google Map API key is updated!${NC}"
else
echo -e "${GREEN}Google map API key is already configured!${NC}"
fi
# Replace splash screen background color
echo -e "${BLUE}==> Changing splash screen background color...${NC}"
splashScreenBackgroundColor=$(jq -r '.splashScreenBackgroundColor' buildScript.json)
if [[ "$splashScreenBackgroundColor" == "false" ]]; then
xmlstarlet ed --inplace -O -u "/resources/item[@name='splashBackground']" -v "$SPLASH_BACKGROUND" "$ANDROID_SPLASH_BACKGROUND_COLOR"
jq '.splashScreenBackgroundColor=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$splashScreenBackgroundColor" == "true" && "$UPDATE_STRING" == "splashBackground" || "${updateStrArr[@]}" =~ "splashBackground" ]]; then
xmlstarlet ed --inplace -O -u "/resources/item[@name='splashBackground']" -v "$SPLASH_BACKGROUND" "$ANDROID_SPLASH_BACKGROUND_COLOR"
jq '.splashScreenBackgroundColor=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Splash Background Color is updated!${NC}"
else
echo -e "${GREEN}Splash Background Color is already configured!${NC}"
fi
# Replace Stripe Publishable_key
# echo -e "${BLUE}==> Setting Stripe Publishable Key...${NC}"
# stripePk=$(jq -r '.stripePk' buildScript.json)
# if [[ "$stripePk" == "false" ]]; then
# sed -i '' 's/\(publishableKey:\)\(.*\)/\1'"$STRIPE_PK"'/' "$CONFIG_FILE"
# echo -e "${GREEN}Done!${NC}"
# jq '.stripePk=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
# elif [[ "$stripePk" == "true" && "$UPDATE_STRING" == "stripePk" || "${updateStrArr[@]}" =~ "stripePk" ]]; then
# sed -i '' 's/\(publishableKey:\)\(.*\)/\1'"$STRIPE_PK"'/' "$CONFIG_FILE"
# echo -e "${GREEN}Stripe Publishable Key is updated!${NC}"
# else
# echo -e "${GREEN}Stripe Publishable Key is already configured!${NC}"
# fi
# Replace OneSignal App ID
echo -e "${BLUE}==> Setting OnseSignal App ID...${NC}"
oneSingalId=$(jq -r '.oneSingalId' buildScript.json)
if [[ "$oneSingalId" == "false" ]]; then
sed -i '' 's/\(appID:\)\(.*\)/\1'"$ONE_SIGNAL_ID"'/' "$CONFIG_FILE"
echo -e "${GREEN}Done!${NC}"
jq '.oneSingalId=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
elif [[ "$oneSingalId" == "true" && "$UPDATE_STRING" == "oneSingalId" || "${updateStrArr[@]}" =~ "oneSingalId" ]]; then
sed -i '' 's/\(appID:\)\(.*\)/\1'"$ONE_SIGNAL_ID"'/' "$CONFIG_FILE"
echo -e "${GREEN}OnseSignal App ID is updated!${NC}"
else
echo -e "${GREEN}OnseSignal App ID is already configured!${NC}"
fi
# Generate app icon and splash image set
echo -e "${BLUE}==> Generating icon set...${NC}"
if [[ -f $IC_LAUNCHER ]]; then
androidIcon=$(jq -r '.androidIcon' buildScript.json)
if [[ "$androidIcon" == "false" ]]; then
find ./android/app/src -type f -name 'ic_launcher.*' | while read -r icon; do
size=$(convert "$icon" -print '%wx%h^' /dev/null)
cp "$IC_LAUNCHER" "$icon" && convert "$icon" -resize "$size" -background none -gravity center -extent "$size" "$icon"
echo -e "\t$icon"
done
find ./android/app/src -type f -name 'ic_launcher_round.*' | while read -r icon; do
size=$(convert "$icon" -print '%wx%h^' /dev/null)
cp "$IC_LAUNCHER" "$icon" && convert "$icon" -resize "$size" -background none -gravity center -extent "$size" -vignette 0x0 "$icon"
echo -e "\t$icon"
done
jq '.androidIcon=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$androidIcon" == "true" && "$UPDATE_STRING" == "iconSet" || "${updateStrArr[@]}" =~ "iconSet" ]]; then
find ./android/app/src -type f -name 'ic_launcher.*' | while read -r icon; do
size=$(convert "$icon" -print '%wx%h^' /dev/null)
cp "$IC_LAUNCHER" "$icon" && convert "$icon" -resize "$size" -background none -gravity center -extent "$size" "$icon"
echo -e "\t$icon"
done
find ./android/app/src -type f -name 'ic_launcher_round.*' | while read -r icon; do
size=$(convert "$icon" -print '%wx%h^' /dev/null)
cp "$IC_LAUNCHER" "$icon" && convert "$icon" -resize "$size" -background none -gravity center -extent "$size" -vignette 0x0 "$icon"
echo -e "\t$icon"
done
echo -e "${GREEN}Icon set is updated!${NC}"
else
echo -e "${GREEN}Icon set is already generated!${NC}"
fi
elif [[ ! -f $IC_LAUNCHER && "$UPDATE_STRING" != "" ]]; then
echo -e "${GREEN}Icon set is already generated!${NC}"
else
echo -e "${RED}Icon image not found! Set icon image path correctly and try again${NC}"
exit 1
fi
echo -e "${BLUE}==> Generating splash image set...${NC}"
if [[ -f $SPLASH_IMAGE ]]; then
androidSplash=$(jq -r '.androidSplash' buildScript.json)
if [[ "$androidSplash" == "false" ]]; then
find ./android/app/src -type f -name 'launch_screen.*' | while read -r splash; do
size=$(convert "$splash" -print '%wx%h^' /dev/null)
cp "$SPLASH_IMAGE" "$splash" && convert "$splash" -resize "$size" -background none -gravity center -extent "$size" "$splash"
# cp "$SPLASH_IMAGE" "$splash" && convert "$splash" -background none -gravity center -extent "$size" "$splash"
echo -e "\t$splash"
done
jq '.androidSplash=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$androidSplash" == "false" && "$UPDATE_STRING" == "splashSet" || "${updateStrArr[@]}" =~ "splashSet" ]]; then
find ./android/app/src -type f -name 'launch_screen.*' | while read -r splash; do
size=$(convert "$splash" -print '%wx%h^' /dev/null)
cp "$SPLASH_IMAGE" "$splash" && convert "$splash" -resize "$size" -background none -gravity center -extent "$size" "$splash"
# cp "$SPLASH_IMAGE" "$splash" && convert "$splash" -background none -gravity center -extent "$size" "$splash"
echo -e "\t$splash"
done
echo -e "${GREEN}Splash image set is updated!${NC}"
else
echo -e "${GREEN}Splash image set is already generated!${NC}"
fi
elif [[ ! -f $SPLASH_IMAGE && "$UPDATE_STRING" != "" ]]; then
echo -e "${GREEN}Splash image set is already generated!${NC}"
else
echo -e "${RED}Splash image not found! Set splash image path correctly and try again\n${NC}"
exit 1
fi
echo -e "${BLUE}==> Installing dependencies...${NC}"
yarn install
echo -e "${GREEN}\n"$APP_NAME" Android is sucessfully configured and is ready to be built!!${NC}"