Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/embedded Add support for configuring Amazon.co...



details:   https://anonhg.NetBSD.org/src/rev/b3c9f98abbb5
branches:  trunk
changeset: 446332:b3c9f98abbb5
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Nov 30 20:53:02 2018 +0000

description:
Add support for configuring Amazon.com EC2 SSH keys and hostnames. While
here, only set wscons=YES if a wsdisplay0 device is present.

diffstat:

 distrib/utils/embedded/conf/arm64.conf  |  10 +++++-
 distrib/utils/embedded/conf/armv7.conf  |   4 +-
 distrib/utils/embedded/conf/evbarm.conf |  10 +++++-
 distrib/utils/embedded/files/ec2_init   |  52 +++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+), 5 deletions(-)

diffs (128 lines):

diff -r 59406a6cd457 -r b3c9f98abbb5 distrib/utils/embedded/conf/arm64.conf
--- a/distrib/utils/embedded/conf/arm64.conf    Fri Nov 30 17:53:08 2018 +0000
+++ b/distrib/utils/embedded/conf/arm64.conf    Fri Nov 30 20:53:02 2018 +0000
@@ -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_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"
 
diff -r 59406a6cd457 -r b3c9f98abbb5 distrib/utils/embedded/conf/armv7.conf
--- a/distrib/utils/embedded/conf/armv7.conf    Fri Nov 30 17:53:08 2018 +0000
+++ b/distrib/utils/embedded/conf/armv7.conf    Fri Nov 30 20:53:02 2018 +0000
@@ -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_evbarm
        cat >> "${mnt}/etc/rc.conf" << EOF
 mdnsd=YES
-wscons=YES
 devpubd=YES
+wscons=\$(dev_exists wsdisplay0)
 EOF
 }
 
diff -r 59406a6cd457 -r b3c9f98abbb5 distrib/utils/embedded/conf/evbarm.conf
--- a/distrib/utils/embedded/conf/evbarm.conf   Fri Nov 30 17:53:08 2018 +0000
+++ b/distrib/utils/embedded/conf/evbarm.conf   Fri Nov 30 20:53:02 2018 +0000
@@ -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 @@
        
        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
diff -r 59406a6cd457 -r b3c9f98abbb5 distrib/utils/embedded/files/ec2_init
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/utils/embedded/files/ec2_init     Fri Nov 30 20:53:02 2018 +0000
@@ -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"



Home | Main Index | Thread Index | Old Index