-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_sdk.sh
98 lines (87 loc) · 2.26 KB
/
send_sdk.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
#!/bin/bash
HELP_MESSAGE="send_sdk [-j|--javascript][-p|--Production][-d|--dev][-i|--ios][-u|--user]<username>[-c|--channel]<channel name>[-cmt|--comment]<message>[-h|--help]"
DIR='/tmp'
DEFAULT_USR='-u firstname1_lastname1'
API_ID='<prod_api_id>'
SDK_TYPE='android'
SDK_POSTFIX=''
PARAMETERS='groupId="com.xxxxx",invokerPackage="com.xxxxx.xxxxxxxx",artifactId="xxxxx-xxxxxxxx",artifactVersion="1.0.0"'
IOS_DEFAULT_USR='firstname2_lastname2'
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--Production)
STAGE="Production"
;;
-d|--dev)
STAGE="dev"
API_ID='<dev_api_id>'
;;
-j|--javascript)
SDK_TYPE="javascript"
;;
-i|--ios)
SDK_TYPE="swift"
PARAMETERS='classPrefix="XXXXXX"'
DEFAULT_USR="-u $IOS_DEFAULT_USR"
;;
-u|--user)
USR="-u $2"
echo $3
shift
;;
-c|--channel)
CHANNEL="-c $2"
shift
;;
-d|--dir)
DIR="$2"
shift
;;
-cmt|--comment)
COMMENT="-i $2"
COMMENT_MSG="with comment \"$2\""
shift
;;
-h|--help)
echo $HELP_MESSAGE
exit 0
;;
*)
echo $HELP_MESSAGE
exit 1
;;
esac
shift # past argument or value
done
if [ -z $STAGE ]; then
echo "Provide stage"
echo $HELP_MESSAGE
exit 1
fi
FILENAME="$DIR/${SDK_TYPE}${SDK_POSTFIX}_sdk_${STAGE}_$(date +%Y-%m-%d_%H_%M_%S).zip"
if [ $SDK_TYPE = "javascript" ]; then
CMD="aws apigateway get-sdk --rest-api-id $API_ID --stage-name $STAGE --sdk-type $SDK_TYPE $FILENAME --output text"
else
CMD="aws apigateway get-sdk --rest-api-id $API_ID --stage-name $STAGE --sdk-type $SDK_TYPE --parameters $PARAMETERS $FILENAME --output text"
fi
$CMD>/dev/null
if [ $? -ne 0 ]; then
echo "aws apigateway exited with error, not sending message"
exit 1
fi
if [[ -z $USR && -z $CHANNEL ]]; then
USR=$DEFAULT_USR
fi
SLACK_CMD="slackcat -m $FILENAME $CHANNEL $USR $COMMENT"
MESSAGE="Sending file $FILENAME to ${CHANNEL:3} ${USR:3} $COMMENT_MSG"
echo $MESSAGE
$SLACK_CMD
if [ $? -eq 0 ]; then
echo "message sent sucessfully"
else
echo "message was not sent"
exit 1
fi
rm -f $FILENAME