-
Notifications
You must be signed in to change notification settings - Fork 13
/
configure-secrets.sh
executable file
·83 lines (70 loc) · 2.53 KB
/
configure-secrets.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
#!/bin/sh -e
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
NOBOLD='\033[21m'
usage () {
cat <<HELP_USAGE
usage: $0 param1 param[n]...
Parameters:
- param1: The SDK name which needs to have a -Secrets.xcconfig file
- param[n]: a list of secrets environment variables to put in secret config file
Example usage:
$0 InAppMessaging RIAM_CONFIG_URL RIAM_APP_SUBSCRIPTION_KEY
HELP_USAGE
}
if [ $# == 0 ]; then
usage
exit 1
fi
#In order to have the // in https://, we need to split it with an empty variable substitution via $()
secureDoubleSlashForXCConfig() {
ENDPOINT=$1
URL_DOUBLE_SLASH_TO_BE_REPLACED="\/\/"
BY_2_SLASHES_SPLITTED_BY_EMPTY_VARIABLE="/\$()/"
SECURE_DOUBLE_SLASH_FOR_XCCONFIG_RESULT="${ENDPOINT/$URL_DOUBLE_SLASH_TO_BE_REPLACED/$BY_2_SLASHES_SPLITTED_BY_EMPTY_VARIABLE}"
}
vars=("${@:2}")
SECRETS_FILE=../${1}-Secrets.xcconfig
echo "${GREEN}Configuring project's build secrets in ${BOLD}$SECRETS_FILE${GREEN}...${NOCOLOR}"
# Overwrite secrets xcconfig and add file header
echo "// Secrets configuration for the app." > $SECRETS_FILE
echo "//" >> $SECRETS_FILE
echo "// **DO NOT** add this file to git." >> $SECRETS_FILE
echo "//" >> $SECRETS_FILE
echo "// Auto-generated file. Any modifications will be lost on next 'pod install'" >> $SECRETS_FILE
echo "//" >> $SECRETS_FILE
echo "// Add new secrets configuration in ./configure-secrets.sh" >> $SECRETS_FILE
echo "//" >> $SECRETS_FILE
echo "// In order to have the // in https://, we need to split it with an empty" >> $SECRETS_FILE
echo "// variable substitution via \$() e.g. ROOT_URL = https:/\$()/www.example.com" >> $SECRETS_FILE
longest_name=-1
for var_name in ${vars[@]}
do
current=${#var_name}
if [ $current -gt $longest_name ]
then
longest_name=$current
fi
done
success=true
for var_name in ${vars[@]}
do
nbstars=$(($longest_name - ${#var_name} + 5))
stars=$(printf '%*s' $nbstars '')
value=$(eval "echo \$$var_name")
if [ -z "$value" ]; then
>&2 echo "➜ ${BOLD}$var_name${NOCOLOR} ${stars// /*} ${RED}ERROR!${NOCOLOR} Missing environment variable ${BOLD}$var_name${NOCOLOR}."
success=false
else
echo "➜ ${BOLD}$var_name${NOCOLOR} ${stars// /*} ${GREEN}OK${NOCOLOR}"
fi
secureDoubleSlashForXCConfig $value
# Set secrets from environment variables
cmd='echo "${var_name} = $SECURE_DOUBLE_SLASH_FOR_XCCONFIG_RESULT"'
eval ${cmd} >> $SECRETS_FILE
done
if [ $success = false ] ; then
echo "Before building the project you must set missing environment variables. See project README for instructions."
fi