-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·31 lines (24 loc) · 1008 Bytes
/
setup.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
#!/bin/bash
path="$( cd "$(dirname "$0")" ; pwd -P )"
read -p 'Twillio SID: ' account_sid
read -p 'Twillio Token: ' auth_token
read -p 'Number Recieving Alerts: ' target_num
echo $account_sid > $path/.twillio_sid
echo $auth_token > $path/.twillio_auth
echo $target_num > $path/.target_num
available_number=$(<$path/.twillio_num)
if [ -z "$available_number" ]
then
available_number=`curl -X GET \
"https://api.twilio.com/2010-04-01/Accounts/${account_sid}/AvailablePhoneNumbers/US/Local" \
-u "${account_sid}:${auth_token}" | \
sed -n "/PhoneNumber/{s/.*<PhoneNumber>//;s/<\/PhoneNumber.*//;p;}"` \
&& echo $available_number
curl -X POST -d "PhoneNumber=${available_number}" \
"https://api.twilio.com/2010-04-01/Accounts/${account_sid}/IncomingPhoneNumbers" \
-u "${account_sid}:${auth_token}"
echo $available_number > $path/.twillio_num
else
echo Using Existing Twillio Number: $available_number
fi
echo "Setup Complete with $available_number alerting $target_num"