-
Notifications
You must be signed in to change notification settings - Fork 3
/
ec2_configinit
48 lines (38 loc) · 1.11 KB
/
ec2_configinit
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
#!/bin/sh
# KEYWORD: firstboot
# PROVIDE: ec2_configinit
# REQUIRE: NETWORKING
# BEFORE: SERVERS ec2_fetchkey firstboot_freebsd_update firstboot_pkgs
# Define ec2_configinit_enable=YES in /etc/rc.conf to enable automatic
# system configuration from EC2 user-data when the system first boots.
: ${ec2_configinit_enable=NO}
. /etc/rc.subr
name="ec2_configinit"
rcvar=ec2_configinit_enable
start_cmd="ec2_configinit_run"
stop_cmd=":"
CONFIGPATH="latest/user-data"
IMDSV2GET="/usr/local/bin/aws-ec2-imdsv2-get"
ec2_configinit_run()
{
# Download to a temporary location.
echo -n "Fetching EC2 user-data"
CONFFILE=`mktemp "${TMPDIR:-/tmp}/configinit.XXXXXX"`
${IMDSV2GET} ${CONFIGPATH} > ${CONFFILE} 2>/dev/null
# If we succeeded, process it; otherwise report failure.
if [ $? = 0 ]; then
# Process the user-data.
echo .
echo -n "Processing EC2 user-data"
/usr/local/sbin/configinit $CONFFILE
echo .
else
echo " failed."
fi
# Whether we suceeded or not, delete the temporary file.
rm $CONFFILE
# Signal /etc/rc to reload rc.conf in case it changed.
kill -ALRM $$
}
load_rc_config $name
run_rc_command "$1"