-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud-init.sh
More file actions
executable file
·57 lines (41 loc) · 1.52 KB
/
cloud-init.sh
File metadata and controls
executable file
·57 lines (41 loc) · 1.52 KB
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
#!/usr/bin/env bash
set -Eeuo pipefail
trap 'echo "⚠ Error ($0:$LINENO, exit code: $?): $BASH_COMMAND" >&2' ERR
function _setup_instance() {
local script
# setup host
script=$(curl -fsS "https://raw.githubusercontent.com/softvisio/scripts/main/setup-host.sh")
bash <(echo "$script")
# setup timesync
script=$(curl -fsS "https://raw.githubusercontent.com/softvisio/scripts/main/setup-timesync.sh")
bash <(echo "$script")
# install ssh public key
script=$(curl -fsS "https://raw.githubusercontent.com/softvisio/scripts/main/install-ssh-public-key.sh")
bash <(echo "$script")
# setup sshd
script=$(curl -fsS "https://raw.githubusercontent.com/softvisio/scripts/main/setup-sshd.sh")
bash <(echo "$script")
}
function _setup_hostname() {
local name
name=$(curl -fsS -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/name")
local project_id
project_id=$(curl -fsS -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/project/project-id")
hostname $name.$project_id
hostname > /etc/hostname
}
function _setup_docker() {
apt-get install -y \
docker-ce
local init_docker
init_docker=$(curl -fsS -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/init_docker") || true
if [[ -n "$init_docker" ]]; then
$init_docker
fi
}
# setup instance
_setup_instance
# setup hostname
_setup_hostname
# setup docker
_setup_docker