
Because it's not possible to test the metadata service code in an easy way, create a config drive ISO image for test purposes. Also speed up the metadata code to not block while waiting for the metadata service and to exit quickly when there is no config drive CD present. Change-Id: If6a5565825b67de58715e3d2de1cbf69b7f9e551
42 lines
985 B
Bash
Executable File
42 lines
985 B
Bash
Executable File
#!/bin/sh
|
|
|
|
check_net() {
|
|
url="http://169.254.169.254/2009-04-04/meta-data"
|
|
(
|
|
wget -q -O - -T 10 $url/public-keys 2> /dev/null || exit 1
|
|
echo
|
|
) | (
|
|
while read line ; do
|
|
key=$(echo $line | sed 's/\([0-9]\+\)=.*/\1/')
|
|
key_url=$url/public-keys/$key/openssh-key
|
|
wget -q -O - -T 10 $key_url 2> /dev/null || exit 1
|
|
done
|
|
) >> authorized_keys
|
|
}
|
|
|
|
json_metadata() {
|
|
F=$1/ec2/2009-04-04/meta-data.json
|
|
[ -f $F ] || return
|
|
SCRIPT='s/^\["public-keys","[0-9]\+","openssh-key"\]\t"\(.*\)\\n"$/\1/p'
|
|
JSON.sh < $F | sed -n "$SCRIPT"
|
|
}
|
|
|
|
check_cd() {
|
|
blkid /dev/sr0 | grep config-2 > /dev/null || return
|
|
mkdir /tmp/cd
|
|
if mount /dev/sr0 /tmp/cd ; then
|
|
json_metadata /tmp/cd >> authorized_keys
|
|
umount /tmp/cd
|
|
fi
|
|
rmdir /tmp/cd
|
|
}
|
|
|
|
mkdir -p /root/.ssh
|
|
cd /root/.ssh
|
|
chmod 700 .
|
|
[ -f authorized_keys ] || touch authorized_keys
|
|
chmod 600 authorized_keys
|
|
|
|
check_cd
|
|
check_net &
|