forked from canonical/cloud-init
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud-init.config
More file actions
50 lines (43 loc) · 1.47 KB
/
cloud-init.config
File metadata and controls
50 lines (43 loc) · 1.47 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
#!/bin/sh -e
. /usr/share/debconf/confmodule
hasEc2Md() {
local d=/var/lib/cloud i=/var/lib/cloud/instance/ f=""
local flist="${i}/datasource ${i}/obj.pkl ${d}/cache/obj.pkl"
# search current instance data source information
for f in ${flist}; do
[ -f "${f}" ] || continue
grep -q DataSourceEc2 "${f}" 2>/dev/null && return 0
done
# there was no data above found that would have been indicated
# by a upgrade. lets just see if we can't find the metadata
# service. if wget is not present (it is not 'essential')
# then we will quietly return 1
local url="http://169.254.169.254/2009-04-04/meta-data/instance-id"
i=""
if command -v wget >/dev/null 2>&1; then
local tout="--connect-timeout 5 --read-timeout 5 --tries 1"
i=$(wget "${url}" ${tout} -O - 2>/dev/null) || :
elif command -v curl >/dev/null 2>&1; then
i=$(curl "${url}" --max-time 1) || :
fi
# if instance-id starts with 'i-' then in all likelyhood its good
[ "${i#i-}" != "${i}" ] && return 0
return 1
}
if [ ! -f /etc/cloud/distro.cfg ] &&
[ ! -f /etc/cloud/cloud.cfg.d/90_dpkg.cfg ] &&
{ db_fget cloud-init/datasources seen || : ; } &&
[ "${RET}" = "false" ]; then
db_get cloud-init/datasources
def="${RET}"
# if this is the first time this we've run, then try
# to detect if we would have access to DataSourceEc2
case " ${def}," in
*\ Ec2,*) :;;
*) hasEc2Md &&
db_set cloud-init/datasources "${def:+${def}, }Ec2";;
esac
fi
db_input low cloud-init/datasources || true
db_go
exit 0