This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathprovision.sh
127 lines (113 loc) · 3.9 KB
/
provision.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
# ==============================================================================
#
# Community Hass.io Add-ons: Vagrant
#
# Provisions a Vagrant guest with Hass.io
#
# ==============================================================================
set -o errexit # Exit script when a command exits with non-zero status
set -o errtrace # Exit on error inside any functions or sub-shells
set -o nounset # Exit script on use of an undefined variable
set -o pipefail # Return exit status of the last command in the pipe that failed
# ==============================================================================
# GLOBALS
# ==============================================================================
readonly EX_OK=0
readonly HASSIO_INSTALLER="https://raw.githubusercontent.com/home-assistant/supervised-installer/master/installer.sh"
readonly DOCKER_DOWNLOAD="https://download.docker.com/linux"
readonly APT_REQUIREMENTS=(
apparmor-utils
apt-transport-https
avahi-daemon
ca-certificates
curl
dbus
dkms
jq
network-manager
socat
software-properties-common
)
# ==============================================================================
# SCRIPT LOGIC
# ==============================================================================
# ------------------------------------------------------------------------------
# Installs all required software packages and tools
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
install_requirements() {
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y "${APT_REQUIREMENTS[@]}"
}
# ------------------------------------------------------------------------------
# Installs the Docker engine
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
install_docker() {
local os
local lsb_release
os=$(. /etc/os-release; echo "${ID}")
lsb_release=$(lsb_release -cs)
curl -fsSL "${DOCKER_DOWNLOAD}/${os}/gpg" | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] ${DOCKER_DOWNLOAD}/${os} ${lsb_release} stable"
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce
usermod -aG docker ubuntu
}
# ------------------------------------------------------------------------------
# Installs and starts Hass.io
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
install_hassio() {
curl -sL "${HASSIO_INSTALLER}" | bash -s
}
# ------------------------------------------------------------------------------
# Shows a message on how to connect to Home Assistant, including the
# dynamic IP the guest was given.
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
show_post_up_message() {
local ip_public
local ip_private
ip_public=$(ip -4 -o addr s enp0s9|head -1|cut -d\ -f 7|cut -d/ -f 1)
ip_private=$(ip -4 -o addr s enp0s8|head -1|cut -d\ -f 7|cut -d/ -f 1)
echo '====================================================================='
echo ' Community Hass.io Add-ons: Vagrant'
echo ''
echo ' Hass.io is installed & started! It may take a couple of minutes'
echo ' before it is actually responding/available.'
echo ''
echo ' Home Assistant is running on the following links:'
echo " - http://${ip_private}:8123"
echo " - http://${ip_public}:8123"
echo '====================================================================='
}
# ==============================================================================
# RUN LOGIC
# ------------------------------------------------------------------------------
main() {
install_requirements
install_docker
install_hassio
show_post_up_message
exit "${EX_OK}"
}
main "$@"