-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfigure-ios.sh
341 lines (310 loc) · 12.5 KB
/
configure-ios.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
#!/bin/bash
# Colors
RED='\033[31m'
GREEN='\033[1;32m'
BLUE='\033[0;34m'
NC='\033[0m'
# Vars
CONFIG_FILE="./src/common/Config.js"
APP_NAME=
PACKAGE_NAME=
SITE_URL=
WC_KEY=
WC_SECRET=
FB_APP_ID=
FB_CLIENT_TOKEN=
# STRIPE_PK=
ONE_SIGNAL_ID=
IC_LAUNCHER=
SPLASH_IMAGE=
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 iOS 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 " [--stripe-pk=<key>]${GREEN}(required)${NC}"
echo -e "\tStripe publishable key\n"
echo -e " [--one-signal-id=<key>]${GREEN}(required)${NC}"
echo -e "\tOneSignal App ID\n"
echo -e " [--launcher-icon=<path>]${GREEN}(required)${NC}"
echo -e "\tAbsolute Path to launcher icon image /path/to/laucnher.png\n"
echo -e " [--splash-image=<path>]${GREEN}(required)${NC}"
echo -e "\tAbsolute Path to splash image /path/to/splash.png\n"
echo -e " [--update=<update-key>]${GREEN}(optional)${NC}"
echo -e "\tSingle or comma separated update keys. Available keys are \"siteUrl\", \"wcKeys\", \"fbId\", \"stripePk\", \"oneSingalId\", \"iconSet\", \"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
;;
# --stripe-pk)
# STRIPE_PK=" '$VALUE',"
# ;;
--one-signal-id)
ONE_SIGNAL_ID=" '$VALUE',"
;;
--launcher-icon)
IC_LAUNCHER=$VALUE
;;
--splash-image)
SPLASH_IMAGE=$VALUE
;;
--update)
UPDATE_STRING=$VALUE
;;
*)
echo -e "\n${RED}ERROR: unknown parameter${NC} \"$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 [[ "$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
fi
# UPDATE_STRING array for updating multiple values all at once
if [[ $UPDATE_STRING == *[,]* ]]; then
IFS=','
read -a updateStrArr <<<"$UPDATE_STRING"
unset IFS
fi
# Creat new project if not exists
if [[ ! -d "$APP_NAME" ]]; then
echo -e "${BLUE}==> Creating new project...${NC}"
# git clone -b NewUpdate git@bitbucket.org:wedevs/dokan-app.git "$APP_NAME" || exit "$?"
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"
grep -rl 'com.wedevs.dokan' ./ios | xargs sed -i '' "s/com.wedevs.dokan/$PACKAGE_NAME/g"
jq '.iosRename=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
else
echo -e "${GREEN}Existing project found${NC}\n"
echo -e "${BLUE}==> Renaming iOS bundle...${NC}"
cd "$APP_NAME"
iosRename=$(jq -r '.iosRename' buildScript.json)
if [[ "$iosRename" == "false" ]]; then
grep -rl 'com.wedevs.dokan' ./ios | xargs sed -i '' "s/com.wedevs.dokan/$PACKAGE_NAME/g"
echo -e "${GREEN}Done!${NC}"
jq '.iosRename=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
else
echo -e "${GREEN}iOS project is already renamed!${NC}"
fi
fi
# install PODS
echo -e "${BLUE}==> Installing Pods...${NC}"
iosPods=$(jq -r '.iosPods' buildScript.json)
if [[ "$iosPods" == "false" ]]; then
cd ios
pod install
cd ..
jq '.iosPods=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
else
echo -e "${GREEN}Pods are already installed!${NC}"
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')
sed -i '' "s|$PREV_URL|$SITE_URL|g" "$CONFIG_FILE"
echo -e "${GREEN}Done!${NC}"
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, Client Token and url schemes
echo -e "${BLUE}==> Setting Facebook App ID...${NC}"
iosFbId=$(jq -r '.iosFbId' buildScript.json)
FB_URL_SCHEME="fb$FB_APP_ID"
if [ "$iosFbId" == "false" ]; then
plutil -replace FacebookAppID -string $FB_APP_ID "ios/"$APP_NAME"/Info.plist"
plutil -replace FacebookClientToken -string $FB_CLIENT_TOKEN "ios/"$APP_NAME"/Info.plist"
sed -i '' 's/\(fb[0-9]*\)/'"$FB_URL_SCHEME"'/' "ios/"$APP_NAME"/Info.plist"
echo -e "${GREEN}Done!${NC}"
jq '.iosFbId=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
elif [[ "$iosFbId" == "true" && "$UPDATE_STRING" == "fbId" || "${updateStrArr[@]}" =~ "fbId" ]]; then
plutil -replace FacebookAppID -string $FB_APP_ID "ios/"$APP_NAME"/Info.plist"
plutil -replace FacebookClientToken -string $FB_CLIENT_TOKEN "ios/"$APP_NAME"/Info.plist"
sed -i '' 's/\(fb[0-9]*\)/'"$FB_URL_SCHEME"'/' "ios/"$APP_NAME"/Info.plist"
echo -e "${GREEN}Facebook App Id and Client Token are updated${NC}"
else
echo -e "${GREEN}Facebook App Id 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
# remove space from $APP_NAME if exists
if [[ "$APP_NAME" = *[[:space:]]* ]]; then
APP_NAME=$(echo "$APP_NAME" | sed 's/[[:space:]]//g')
fi
# Generate app icon and splash image set
echo -e "${BLUE}==> Generating icon set...${NC}"
if [[ -f "$IC_LAUNCHER" ]]; then
iosIcon=$(jq -r '.iosIcon' buildScript.json)
if [[ "$iosIcon" == "false" ]]; then
find "./ios/"$APP_NAME"/Images.xcassets" -type f -name 'launch-icon-*' | 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
jq '.iosIcon=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$iosIcon" == "true" && "$UPDATE_STRING" == "iconSet" || "${updateStrArr[@]}" =~ "iconSet" ]]; then
find "./ios/"$APP_NAME"/Images.xcassets" -type f -name 'launch-icon-*' | 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
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
iosSplash=$(jq -r '.iosSplash' buildScript.json)
if [[ "$iosSplash" == "false" ]]; then
find "./ios/"$APP_NAME"/Images.xcassets" -type f -name 'LaunchImage-*' | 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"
echo -e "\t$splash"
done
jq '.iosSplash=true' buildScript.json >"$tmp" && mv "$tmp" buildScript.json
echo -e "${GREEN}Done!${NC}"
elif [[ "$iosSplash" == "true" && "$UPDATE_STRING" == "splashSet" || "${updateStrArr[@]}" =~ "splashSet" ]]; then
find "./ios/"$APP_NAME"/Images.xcassets" -type f -name 'LaunchImage-*' | 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"
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! Check splash image path correctly and try again${NC}"
fi
echo -e "${BLUE}==> Installing dependencies...${NC}"
yarn install
echo -e "${GREEN}\n"$APP_NAME" iOS is sucessfully configured and is ready to be built!!${NC}"