3 URL="http://169.254.169.254/latest/"
5 CURL="curl --retry 3 -f -s"
12 stat_busy "Starting ec2"
14 ## Set hostname and static ip
15 if ! grep -q ".internal" /etc/hosts ; then
16 cp /etc/hosts /etc/hosts.orig
17 HOSTNAME=$($CURL "${URL}meta-data/local-hostname")
18 IPV4=$($CURL "${URL}meta-data/local-ipv4")
19 if [[ -n "$HOSTNAME" && -n "$IPV4" && -n "${HOSTNAME%.*.internal}" ]]; then
20 echo "$IPV4 $HOSTNAME ${HOSTNAME%.*.internal}" >> /etc/hosts
22 echo "domain $(hostname -d)" >> /etc/resolv.conf
25 if [ ! -f /root/.ssh/authorized_keys ] ; then
27 $CURL -o /root/.ssh/authorized_keys "${URL}meta-data/public-keys/0/openssh-key"
30 if useradd -m -g adm -s /bin/zsh -p x -G wheel,log $NEWUSER 2>/dev/null; then
31 cp -r /root/. /home/$NEWUSER
32 chown -R ${NEWUSER}:adm /home/${NEWUSER}/.
34 if [ -f /root/firstboot ]; then
35 if $CURL -o /root/user-data "${URL}user-data"; then
36 /bin/bash /root/user-data
48 stat_busy "Stopping ec2"
49 sed -i "/domain/d" /etc/resolv.conf
50 sed -i "/$(hostname)/d" /etc/hosts
63 echo "usage: $0 {start|stop|restart}"