Add support for configuring Amazon.com EC2 SSH keys and hostnames. While

here, only set wscons=YES if a wsdisplay0 device is present.
This commit is contained in:
jmcneill 2018-11-30 20:53:02 +00:00
parent 01089dfb82
commit af8f486465
4 changed files with 71 additions and 5 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: arm64.conf,v 1.4 2018/08/27 22:36:49 jmcneill Exp $
# $NetBSD: arm64.conf,v 1.5 2018/11/30 20:53:02 jmcneill Exp $
# ARM64 customization script used by mkimage
#
board=arm64
@ -21,12 +21,18 @@ customize() {
customize_evbarm
cat >> "${mnt}/etc/rc.conf" << EOF
mdnsd=YES
wscons=YES
devpubd=YES
wscons=\$(dev_exists wsdisplay0)
ec2_init=\$(dev_exists ena0)
EOF
}
populate_common() {
# Add EC2 init script
cp ${DIR}/files/ec2_init ${mnt}/etc/rc.d/ec2_init
echo "./etc/rc.d/ec2_init type=file uname=root gname=wheel mode=0555" \
>> "$tmp/selected_sets"
# Rename kernel to netbsd.img
mv "${mnt}/boot/netbsd-${kernel_GENERIC64}.img" "${mnt}/boot/netbsd.img"

View File

@ -1,4 +1,4 @@
# $NetBSD: armv7.conf,v 1.27 2018/11/22 21:11:37 aymeric Exp $
# $NetBSD: armv7.conf,v 1.28 2018/11/30 20:53:02 jmcneill Exp $
# ARMv7 customization script used by mkimage
#
board=armv7
@ -26,8 +26,8 @@ customize() {
customize_evbarm
cat >> "${mnt}/etc/rc.conf" << EOF
mdnsd=YES
wscons=YES
devpubd=YES
wscons=\$(dev_exists wsdisplay0)
EOF
}

View File

@ -1,4 +1,4 @@
# $NetBSD: evbarm.conf,v 1.30 2018/10/06 13:11:22 jmcneill Exp $
# $NetBSD: evbarm.conf,v 1.31 2018/11/30 20:53:02 jmcneill Exp $
# evbarm shared config
#
image=$HOME/${board}.img
@ -127,6 +127,14 @@ customize_evbarm() {
cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
cat >> ${mnt}/etc/rc.conf << EOF
dev_exists() {
if /sbin/drvctl -l $1 >/dev/null 2>&1 ; then
printf YES
else
printf NO
fi
}
rc_configured=YES
hostname=${board}
sshd=YES

View File

@ -0,0 +1,52 @@
#!/bin/sh
#
# $NetBSD: ec2_init,v 1.1 2018/11/30 20:53:02 jmcneill Exp $
#
# PROVIDE: ec2_init
# REQUIRE: NETWORKING
# BEFORE: LOGIN
$_rc_subr_loaded . /etc/rc.subr
name="ec2_init"
rcvar=${name}
start_cmd="ec2_init"
stop_cmd=":"
METADATA_URL="http://169.254.169.254/latest/meta-data/"
SSH_KEY_URL="public-keys/0/openssh-key"
HOSTNAME_URL="hostname"
SSH_KEY_FILE="/root/.ssh/authorized_keys"
ec2_init()
{
(
umask 022
# fetch the key pair from Amazon Web Services
EC2_SSH_KEY=$(ftp -o - "${METADATA_URL}${SSH_KEY_URL}")
if [ -n "$EC2_SSH_KEY" ]; then
# A key pair is associated with this instance, add it
# to root 'authorized_keys' file
mkdir -p $(dirname "$SSH_KEY_FILE")
touch "$SSH_KEY_FILE"
cd $(dirname "$SSH_KEY_FILE")
grep -q "$EC2_SSH_KEY" "$SSH_KEY_FILE"
if [ $? -ne 0 ]; then
echo "Setting EC2 SSH key pair: ${EC2_SSH_KEY##* }"
echo "$EC2_SSH_KEY" >> "$SSH_KEY_FILE"
fi
fi
# set hostname
HOSTNAME=$(ftp -o - "${METADATA_URL}${HOSTNAME_URL}")
echo "Setting EC2 hostname: ${HOSTNAME}"
echo "$HOSTNAME" > /etc/myname
hostname "$HOSTNAME"
)
}
load_rc_config $name
run_rc_command "$1"