-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-environment.sh
More file actions
executable file
·87 lines (68 loc) · 2.86 KB
/
setup-environment.sh
File metadata and controls
executable file
·87 lines (68 loc) · 2.86 KB
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
#!/usr/bin/env bash
# Change this if you're making your own fork with a different namespace
app_id="cl.emilym.sinatra"
update_property() {
local file="$1"
local property="$2"
local value="$3"
if grep -q "^$property=" "$file"; then
awk -F= -v prop="$property" -v val="$value" '
BEGIN { OFS = "=" }
$1 == prop {
$0 = prop "=" val
updated = 1
}
{ print }
END { if (!updated) print prop, val }
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
else
echo "$property=$value" >> "$file"
fi
}
index_of() {
local needle="$1"
shift 1
local -a haystack=("$@")
for i in "${!haystack[@]}"
do
if [[ "${haystack[$i]}" == "$needle" ]]; then
echo "${i}"
return 0
fi
done
echo "-1"
return 0
}
contains() {
local i=$(index_of "$@")
if [[ "$i" -ne "-1" ]]; then
return 0
fi
return 1
}
read -p "Enter a Firebase project ID: " project_id
read -p "Enter a Google Maps API Key: " maps_api_key
read -p "Enter a server url [https://develop-api.sinatra-transport.com/canberra/]: " api_endpoint
api_endpoint="${api_endpoint:-https://develop-api.sinatra-transport.com/canberra/}"
app_list="$(firebase apps:list --non-interactive --project "$project_id" --json)"
app_namespaces=()
while IFS= read -r line; do
app_namespaces+=("$line")
done < <(jq -r '.result[] | "\(.namespace) \(.platform)"' <<< "$app_list")
app_ids=()
while IFS= read -r line; do
app_ids+=("$line")
done < <(jq -r '.result[].appId' <<< "$app_list")
if ! $(contains "$app_id.develop ANDROID" "${app_namespaces[@]}") || ! $(contains "$app_id ANDROID" "${app_namespaces[@]}") || ! $(contains "$app_id.develop IOS" "${app_namespaces[@]}") || ! $(contains "$app_id IOS" "${app_namespaces[@]}") ; then
echo "Firebase project is missing $app_id.develop or $app_id namespaces for either Android or iOS"
fi
mkdir -p androidApp/src/debug
mkdir -p androidApp/src/main
mkdir -p iosApp/iosApp/Firebase
firebase apps:sdkconfig --non-interactive --project "$project_id" ANDROID "${app_ids[$(index_of "cl.emilym.sinatra.develop ANDROID" "${app_namespaces[@]}")]}" > androidApp/src/debug/google-services.json
firebase apps:sdkconfig --non-interactive --project "$project_id" ANDROID "${app_ids[$(index_of "cl.emilym.sinatra ANDROID" "${app_namespaces[@]}")]}" > androidApp/src/main/google-services.json
firebase apps:sdkconfig --non-interactive --project "$project_id" IOS "${app_ids[$(index_of "cl.emilym.sinatra.develop IOS" "${app_namespaces[@]}")]}" > iosApp/iosApp/Firebase/GoogleService-Info-Debug.plist
firebase apps:sdkconfig --non-interactive --project "$project_id" IOS "${app_ids[$(index_of "cl.emilym.sinatra IOS" "${app_namespaces[@]}")]}" > iosApp/iosApp/Firebase/GoogleService-Info-Release.plist
touch secrets.properties
update_property secrets.properties "MAPS_API_KEY" "$maps_api_key"
update_property gradle.properties "apiUrl" "$api_endpoint"