-
Notifications
You must be signed in to change notification settings - Fork 6
/
aws_firstboot
40 lines (32 loc) · 1.01 KB
/
aws_firstboot
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
#!/bin/sh
# KEYWORD: firstboot
# PROVIDE: aws_firstboot
# REQUIRE: NETWORKING
# BEFORE: LOGIN
: ${user=devops}
. /etc/rc.subr
name=aws_firstboot
rcvar=aws_firstboot_enable
start_cmd="${name}_run"
SSHKEYURL="http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key"
aws_firstboot_run()
{
eval SSHKEYFILE="~${user}/.ssh/authorized_keys"
echo "Fetching SSH public key AWS"
mkdir -p `dirname ${SSHKEYFILE}`
chmod 700 `dirname ${SSHKEYFILE}`
chown ${user} `dirname ${SSHKEYFILE}`
ftp -q 5 -o ${SSHKEYFILE}.ec2 -a ${SSHKEYURL} >/dev/null
if [ -f ${SSHKEYFILE}.ec2 ]; then
touch ${SSHKEYFILE}
sort -u ${SSHKEYFILE} ${SSHKEYFILE}.ec2 \
> ${SSHKEYFILE}.tmp
mv ${SSHKEYFILE}.tmp ${SSHKEYFILE}
chown ${user} ${SSHKEYFILE}
rm ${SSHKEYFILE}.ec2
else
echo "Fetching SSH public key failed!"
fi
}
load_rc_config $name
run_rc_command "$1"