forked from hassio-addons/hassio-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprovision.sh
178 lines (159 loc) · 5.28 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/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/hassio-installer/master/hassio_install.sh"
readonly DOCKER_DOWNLOAD="https://download.docker.com/linux"
readonly NETDATA_INSTALLER="https://my-netdata.io/kickstart-static64.sh"
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
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
apt-get install -y docker-ce
usermod -aG docker ubuntu
}
# ------------------------------------------------------------------------------
# Installs and starts netdata
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
install_netdata() {
curl -s "${NETDATA_INSTALLER}" > /tmp/kickstart-netdata.sh
bash /tmp/kickstart-netdata.sh --dont-wait
rm /tmp/kickstart-netdata.sh
}
# ------------------------------------------------------------------------------
# Installs and starts Portainer
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
install_portainer() {
mkdir -p /usr/share/portainer
docker pull portainer/portainer:latest
docker create \
--name=portainer \
--restart=always \
-v /usr/share/portainer:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 9000:9000 \
portainer/portainer \
-H unix:///var/run/docker.sock \
--no-auth
docker start portainer
}
# ------------------------------------------------------------------------------
# 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 ''
echo ' Portainer is running on the following links:'
echo " - http://${ip_private}:9000"
echo " - http://${ip_public}:9000"
echo ''
echo ' Netdata is providing awesome stats on these links:'
echo " - http://${ip_private}:19999"
echo " - http://${ip_public}:19999"
echo '====================================================================='
}
# ==============================================================================
# RUN LOGIC
# ------------------------------------------------------------------------------
main() {
install_requirements
install_docker
install_netdata
install_portainer
install_hassio
show_post_up_message
exit "${EX_OK}"
}
main "$@"