/
create_resources_gcloud.sh
executable file
·58 lines (49 loc) · 1.33 KB
/
create_resources_gcloud.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
#!/bin/bash
printf "\nOnce you've logged into your project, enter the project id below."
GCLOUD_PROJECT="$1"
if [ -z "$1" ]; then
echo
read -p 'Please enter project id: ' GCLOUD_PROJECT
echo
fi
if [ -z "$GCLOUD_PROJECT" ];
then
cat<<KEYERR
***WARNING: Inform a valid gcloud project id
KEYERR
exit 1
fi
LOCATION="us-central1"
gcloud config set project $GCLOUD_PROJECT
# Enable Services
SERVICES=(
cloudiot
firebase
)
for svc in ${SERVICES[@]};
do
printf "Enabling Service: ${svc}\n"
gcloud services enable ${svc}.googleapis.com
done
# Create pubsub topic & save topic in env variable
gcloud pubsub topics create pubsub-voice-robot-arm
gcloud pubsub subscriptions create writer-pubsub-voice-robot-arm --topic=pubsub-voice-robot-arm --topic-project=$GCLOUD_PROJECT
gcloud iot registries create robot-arm-registry --region=$LOCATION --event-notification-config=topic=pubsub-voice-robot-arm
DEVICE_ID="$2"
if [ -z "$2" ]; then
echo
read -p 'Please enter device id: ' DEVICE_ID
echo
fi
# Create keys
openssl req -x509 -nodes -newkey rsa:2048 \
-keyout ${DEVICE_ID}.key.pem \
-out ${DEVICE_ID}.crt.pem \
-days 365 \
-subj "/CN=unused"
# Register devices
gcloud iot devices create $DEVICE_ID \
--region=$LOCATION \
--registry=robot-arm-registry \
--project=$GCLOUD_PROJECT \
--public-key path=${DEVICE_ID}.crt.pem,type=rsa-x509-pem