-
Notifications
You must be signed in to change notification settings - Fork 152
/
user-data.txt
105 lines (76 loc) · 2.08 KB
/
user-data.txt
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
#!/bin/bash -xe
yum update -y
yum install httpd -y
echo 'Hello' >> /var/www/html/index.html
systemctl restart httpd
## Code Deploy Agent Bootstrap Script##
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
AUTOUPDATE=false
function installdep(){
if [ ${PLAT} = "ubuntu" ]; then
apt-get -y update
# Satisfying even ubuntu older versions.
apt-get -y install jq awscli ruby2.0 || apt-get -y install jq awscli ruby
elif [ ${PLAT} = "amz" ]; then
yum -y update
yum install -y aws-cli ruby jq
fi
}
function platformize(){
#Linux OS detection#
if hash lsb_release; then
echo "Ubuntu server OS detected"
export PLAT="ubuntu"
elif hash yum; then
echo "Amazon Linux detected"
export PLAT="amz"
else
echo "Unsupported release"
exit 1
fi
}
function execute(){
if [ ${PLAT} = "ubuntu" ]; then
cd /tmp/
wget https://aws-codedeploy-${REGION}.s3.amazonaws.com/latest/install
chmod +x ./install
if ./install auto; then
echo "Instalation completed"
if ! ${AUTOUPDATE}; then
echo "Disabling Auto Update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
exit 0
else
echo "Instalation script failed, please investigate"
rm -f /tmp/install
exit 1
fi
elif [ ${PLAT} = "amz" ]; then
cd /tmp/
wget https://aws-codedeploy-${REGION}.s3.amazonaws.com/latest/install
chmod +x ./install
if ./install auto; then
echo "Instalation completed"
if ! ${AUTOUPDATE}; then
echo "Disabling auto update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
exit 0
else
echo "Instalation script failed, please investigate"
rm -f /tmp/install
exit 1
fi
else
echo "Unsupported platform ''${PLAT}''"
fi
}
platformize
installdep
REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r ".region")
execute