forked from eduardoflorendo/do-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·160 lines (130 loc) · 3.71 KB
/
install.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
#!/bin/bash
#
# This script is meant for quick & easy install via:
# curl -sSL https://agent.digitalocean.com/install.sh | sudo bash
# or:
# wget -qO- https://agent.digitalocean.com/install.sh | sudo bash
#
# To use the BETA branch of do-agent pass the BETA=1 flag to the script
# curl -sSL https://agent.digitalocean.com/install.sh | sudo BETA=1 bash
#
set -ueo pipefail
UNSTABLE=${UNSTABLE:-0}
BETA=${BETA:-0}
REPO_HOST=https://repos.insights.digitalocean.com
REPO_GPG_KEY=${REPO_HOST}/sonar-agent.asc
repo="do-agent"
[ "${UNSTABLE}" != 0 ] && repo="do-agent-unstable"
[ "${BETA}" != 0 ] && repo="do-agent-beta"
dist="unknown"
deb_list=/etc/apt/sources.list.d/digitalocean-agent.list
rpm_repo=/etc/yum.repos.d/digitalocean-agent.repo
function main() {
[ "$(id -u)" != "0" ] && \
abort "This script must be executed as root."
clean
check_do
check_dist
case "${dist}" in
debian|ubuntu)
install_apt
;;
centos|fedora)
install_rpm
;;
*)
not_supported
;;
esac
}
function install_apt() {
# forcefully remove any existing installations
apt-get remove -y do-agent || :
echo "Installing apt repository..."
apt-get -qq update || true
apt-get -qq install -y ca-certificates gnupg2 apt-utils apt-transport-https curl
echo "deb ${REPO_HOST}/apt/${repo} main main" > /etc/apt/sources.list.d/digitalocean-agent.list
echo -n "Installing gpg key..."
curl -sL "${REPO_GPG_KEY}" | apt-key add -
apt-get -qq update -o Dir::Etc::sourcelist="sources.list.d/digitalocean-agent.list"
apt-get -qq install -y do-agent
}
function install_rpm() {
echo "Installing yum repository..."
# forcefully remove any existing installations
yum remove -y do-agent || :
yum install -y pygpgme ca-certificates
cat <<-EOF > /etc/yum.repos.d/digitalocean-agent.repo
[digitalocean-agent]
name=DigitalOcean Agent
baseurl=${REPO_HOST}/yum/${repo}/\$basearch
repo_gpgcheck=0
gpgcheck=1
enabled=1
gpgkey=${REPO_GPG_KEY}
sslverify=0
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF
yum --disablerepo="*" --enablerepo="digitalocean-agent" makecache
yum install -y do-agent
}
function clean() {
echo -n "Cleaning up old sources..."
if [ -f "$deb_list" ]; then
rm -f "${deb_list}"
elif [ -f "$rpm_repo" ]; then
rm -f "${rpm_repo}"
fi
echo "OK"
}
function check_dist() {
echo -n "Verifying compatability with script..."
if [ -f /etc/os-release ]; then
dist=$(awk -F= '$1 == "ID" {gsub("\"", ""); print$2}' /etc/os-release)
elif [ -f /etc/redhat-release ]; then
dist=$(awk '{print tolower($1)}' /etc/redhat-release)
else
not_supported
fi
dist=$(echo "${dist}" | tr '[:upper:]' '[:lower:]')
case "${dist}" in
debian|ubuntu|centos|fedora)
echo "OK"
;;
*)
not_supported
;;
esac
}
function check_do() {
echo -n "Verifying machine compatability..."
# DigitalOcean embedded platform information in the DMI data.
read -r sys_vendor < /sys/devices/virtual/dmi/id/bios_vendor
if ! [ "$sys_vendor" = "DigitalOcean" ]; then
cat <<-EOF
The DigitalOcean Agent is only supported on DigitalOcean machines.
If you are seeing this message on an older droplet, you may need to power-off
and then power-on at http://cloud.digitalocean.com. After power-cycling,
please re-run this script.
EOF
exit 1
fi
echo "OK"
}
function not_supported() {
cat <<-EOF
This script does not support the OS/Distribution on this machine.
If you feel that this is an error contact support@digitalocean.com
or create an issue at https://github.com/digitalocean/do-agent/issues/new.
EOF
exit 1
}
# abort with an error message
function abort() {
read -r line func file <<< "$(caller 0)"
echo "ERROR in $file:$func:$line: $1" > /dev/stderr
exit 1
}
# leave this last to prevent any partial executions
main