
Fix bashate warning E006 by wrapping long lines. Also make sure bashate runs on init scripts that don't end in .sh. Change-Id: I077a064505e6f11f61c65279a54c9b2430044bf0
42 lines
956 B
Bash
Executable File
42 lines
956 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() {
|
|
[ -b /dev/sr0 ] || 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_net
|
|
check_cd
|