-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathquickstart.sh
89 lines (74 loc) · 2.98 KB
/
quickstart.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
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# This script is designed for quickstart.
#
# Before running the script, users must:
# 1) Deploy Greengrass V2 to an x86-compatible Linux machine, virtual machine or EC2 instance.
# 2) Initialize the Greengrass core device to satisfy the the requirements to run Docker containers using
# Docker Compose and Docker Hub.
# 3) Set the AWS region in gdk-config.json.
#
# This script will:
# 1) Install required Python packages.
# 2) Upload the secure parts of the Home Assistant configuration to Secrets Manager.
# 3) Use GDK to build the component.
# 4) Use GDK to publish a new component version to Greengrass cloud services and upload artifacts to an S3 bucket.
# 5) Prompt you to add permissions for the configuration secret and artifacts bucket to the Greengrass core device role.
# 6) Deploy the new component version to the Greengrass core.
#
# Example execution:
# bash quickstart.sh GGHomeAssistant
# Fail if we don't get the correct number of arguments
if [ "$#" -ne 1 ]; then
echo "Usage: bash quickstart.sh GGCoreDeviceName"
exit 1
fi
# Exit when any command fails
set -e
banner() {
echo -e "\n---------- $1 ----------"
}
# Don't let them proceed until they've set the region in the GDK configuration
done=0
while [ $done -eq 0 ]; do
echo "Have you set the AWS region in gdk-config.json? ('Press 'y' for yes or 'x' to exit)"
read -rsn1 keypress
if [ "$keypress" = "x" ]; then
echo "Cannot proceed"
exit 1
elif [ "$keypress" = "y" ]; then
done=1
fi
done
# Install requirements
banner "Install required packages"
pip3 install -r requirements.txt
pip3 install git+https://github.com/aws-greengrass/aws-greengrass-gdk-cli.git
# Create the Home Assistant configuration secret in Secrets Manager to hold the secrets.yaml configuration securely
banner "Create or update the Home Assistant configuration secret"
python3 create_config_secret.py
# Build the component
banner "Build the Greengrass component"
gdk component build
# Publish a new component version
banner "Publish a new Greengrass component version"
gdk component publish
# Don't let them proceed until they've added the S3 bucket and secret permissions to the Greengrass device role
done=0
while [ $done -eq 0 ]; do
echo "Have you added the bucket and secret permissions to the Greengrass device role? ('Press 'y' for yes or 'x' to exit)"
read -rsn1 keypress
if [ "$keypress" = "x" ]; then
echo "Deployment not performed"
exit 1
elif [ "$keypress" = "y" ]; then
done=1
fi
done
# Get the recipe file generated by the build stage and extract the new component version
RECIPE_FILE=$(ls greengrass-build/recipes/aws.greengrass.labs.*.json)
COMPONENT_VERSION=$(cat $RECIPE_FILE | jq -r '.ComponentVersion')
# Deploy the new component version
banner "Deploy the new Greengrass component version"
python3 deploy_component_version.py $COMPONENT_VERSION $1