-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·95 lines (83 loc) · 2.46 KB
/
install
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
#!/bin/sh
#
# Install/Update AWS EC2 instance: amazon-ssm-agent
# We need to be root
if [ $(id -u) -ne 0 ]; then printf 'Need to be root!\n'; exit 1; fi
SSM_BINDIR=/usr/bin
[ -d $SSM_BINDIR ] || exit
if [ -x $SSM_BINDIR/amazon-ssm-agent ]; then
printf 'Update '
else
printf 'Install '
fi
printf 'amazon-ssm-agent ...\n'
if [ -z "$(command -v go)" ]; then
printf 'FAILED: golang not found.\n'
exit 1
fi
if [ -z "$(command -v git)" ]; then
printf 'FAILED: git not found.\n'
exit 1
fi
#SSM_SRCDIR=/usr/lib/go-1.7/src/github.com/aws
#SSM_SRCDIR=/usr/share/go/src/github.com/aws
if [ ! -d /usr/lib/go ]; then
printf 'ERROR: /usr/lib/go directory is missing. Is golang installed?\n'
exit 1
fi
# get stretchr/testify dependency
STRETCHR_SRCDIR=/usr/lib/go/src/github.com/stretchr
[ -d "$STRETCHR_SRCDIR" ] || mkdir -p "$STRETCHR_SRCDIR"
cd "$STRETCHR_SRCDIR" || exit 1
if [ -d testify ]; then
# update: git pull
cd testify || exit 1
git pull
else
# clone repository
git clone --depth 1 https://github.com/stretchr/testify
fi
# get amazon-ssm-agent
SSM_SRCDIR=/usr/lib/go/src/github.com/aws
[ -d "$SSM_SRCDIR" ] || mkdir -p "$SSM_SRCDIR"
cd "$SSM_SRCDIR" || exit 1
if [ -d amazon-ssm-agent ]; then
# update: git pull
cd amazon-ssm-agent || exit 1
git pull
else
# clone repository
git clone --depth 1 https://github.com/aws/amazon-ssm-agent
cd amazon-ssm-agent || exit 1
fi
# link the codebase to /usr/src, to make it more "visible"
ln -sf "$SSM_SRCDIR/amazon-ssm-agent" /usr/src/
printf 'Get additional tools ...\n'
make get-tools
printf 'Build ...\n'
make build-linux
[ $? -eq 0 ] || exit 1
# stop service if running
if [ "$(pgrep runsvdir)" ] && [ -d /etc/service/amazon-ssm-agent ]; then
printf 'Stop service ...\n'
sv stop amazon-ssm-agent
fi
# install compiled ssm-agent
printf 'Installing compiled amazon-ssm-agent ...\n'
cp -vf bin/linux_amd64/* $SSM_BINDIR/
[ -d /etc/amazon/ssm ] || mkdir -p /etc/amazon/ssm
cp -vf bin/amazon-ssm-agent.json.template /etc/amazon/ssm/
cp -vn bin/amazon-ssm-agent.json.template /etc/amazon/ssm/amazon-ssm-agent.json
cp -vn bin/seelog_unix.xml /etc/amazon/ssm/seelog.xml
# stop flooding the /dev/console (see bootlogd: /var/log/boot.log)
sed -i 's/.*<console.*\/>.*//' /etc/amazon/ssm/seelog.xml
# start service after update
if [ "$(pgrep runsvdir)" ] && [ -d /etc/service/amazon-ssm-agent ]; then
printf 'Start service ...\n'
sv start amazon-ssm-agent
fi
# cleanup (240 MB -> 175 MB)
printf 'Cleanup ...\n'
make clean
#rm -rf "$SSM_SRCDIR"
printf 'DONE\n'