/
scripts.go
53 lines (47 loc) · 1.59 KB
/
scripts.go
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
package main
import (
"strings"
)
func genStartupScript() string {
return strings.Join([]string{
"#!/bin/bash -xeu",
genBaseSystemUtilitiesInstallScriptSnippet(),
genGCPOpsAgentInstallScriptSnippet(),
genCaddyInstallScriptSnippet(),
"touch /tmp/STARTUP_FINISHED", // so other scripts can know when this is done
}, "\n")
}
func genCaddyInstallScriptSnippet() string {
return `# genCaddyInstallScriptSnippet
if [ ! -f "/etc/CADDY_INSTALLED" ]; then
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --yes --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install -y caddy
touch /etc/CADDY_INSTALLED
fi
`
}
func genGCPOpsAgentInstallScriptSnippet() string {
return `# genGCPOpsAgentInstallScriptSnippet
if [ ! -f "/etc/GCP_OPS_AGENT_INSTALLED" ]; then
cd /tmp
curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
bash add-google-cloud-ops-agent-repo.sh --also-install
touch /etc/GCP_OPS_AGENT_INSTALLED
fi
`
}
func genBaseSystemUtilitiesInstallScriptSnippet() string {
return `# genBaseSystemUtilitiesInstallScriptSnippet
# get latest updates
apt update
apt dist-upgrade -y
# install utilities
if [ ! -f "/etc/UTILITIES_INSTALLED" ]; then
apt install -y \
ack apt-transport-https bsdmainutils ca-certificates curl debian-keyring debian-archive-keyring iputils-ping jq less lsof nano ncat net-tools nmap sysstat telnet tmux traceroute vim
touch /etc/UTILITIES_INSTALLED
fi
`
}