From 2096301e009fbee43640794d703944626e96fa38 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sat, 10 Aug 2013 16:55:27 +0200 Subject: [PATCH] Cleanup raw/assets, use common.tasks.initd --- providers/raw/__init__.py | 2 +- providers/raw/assets/grub.d/40_custom.orig | 81 ------------------- .../raw/assets/init.d/ec2-get-credentials | 45 ----------- providers/raw/assets/init.d/ec2-run-user-data | 46 ----------- providers/raw/assets/init.d/expand-volume | 26 ------ .../raw/assets/init.d/generate-ssh-hostkeys | 36 --------- .../init.d/squeeze/generate-ssh-hostkeys | 33 -------- providers/raw/tasks/initd.py | 49 ----------- 8 files changed, 1 insertion(+), 317 deletions(-) delete mode 100644 providers/raw/assets/grub.d/40_custom.orig delete mode 100644 providers/raw/assets/init.d/ec2-get-credentials delete mode 100644 providers/raw/assets/init.d/ec2-run-user-data delete mode 100644 providers/raw/assets/init.d/expand-volume delete mode 100644 providers/raw/assets/init.d/generate-ssh-hostkeys delete mode 100644 providers/raw/assets/init.d/squeeze/generate-ssh-hostkeys delete mode 100644 providers/raw/tasks/initd.py diff --git a/providers/raw/__init__.py b/providers/raw/__init__.py index bda1a99..bfc8834 100644 --- a/providers/raw/__init__.py +++ b/providers/raw/__init__.py @@ -10,7 +10,7 @@ from tasks import boot from common.tasks import boot as common_boot from tasks import security from common.tasks import network -from tasks import initd +from common.tasks import initd from common.tasks import cleanup diff --git a/providers/raw/assets/grub.d/40_custom.orig b/providers/raw/assets/grub.d/40_custom.orig deleted file mode 100644 index 0e74a8e..0000000 --- a/providers/raw/assets/grub.d/40_custom.orig +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/sh - -# This file generates the old menu.lst configuration with grub2 -# It was copied from tomheadys github repo: -# https://github.com/tomheady/ec2debian/blob/master/src/root/etc/grub.d/40_custom - -prefix=/usr -exec_prefix=${prefix} -bindir=${exec_prefix}/bin -libdir=${exec_prefix}/lib -. ${libdir}/grub/grub-mkconfig_lib - -export TEXTDOMAIN=grub -export TEXTDOMAINDIR=${prefix}/share/locale - -GRUB_DEVICE=/dev/sda1 - - -cat << EOF -default ${GRUB_DEFAULT} -timeout ${GRUB_TIMEOUT} -EOF - -if ${GRUB_HIDDEN_TIMEOUT:-false}; then - printf "hiddenmenu\n" -fi - -linux_entry () -{ - os="$1" - version="$2" - args="$4" - - title="$(gettext_quoted "%s, with Linux %s")" - - cat << EOF -title ${version} - root (hd0) - kernel ${rel_dirname}/${basename} root=${GRUB_DEVICE} ro ${args} - initrd ${rel_dirname}/${initrd} -EOF -} - -list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do - if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi - done` -prepare_boot_cache= - -while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` - basename=`basename $linux` - dirname=`dirname $linux` - rel_dirname=`make_system_path_relative_to_its_root $dirname` - version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` - alt_version=`echo $version | sed -e "s,\.old$,,g"` - linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" - - initrd= - for i in "initrd.img-${version}" "initrd-${version}.img" \ - "initrd-${version}" "initramfs-${version}.img" \ - "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ - "initrd-${alt_version}" "initramfs-${alt_version}.img"; do - if test -e "${dirname}/${i}" ; then - initrd="$i" - break - fi - done - - initramfs= - for i in "config-${version}" "config-${alt_version}"; do - if test -e "${dirname}/${i}" ; then - initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"` - break - fi - done - - linux_entry "${OS}" "${version}" \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - - list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` -done diff --git a/providers/raw/assets/init.d/ec2-get-credentials b/providers/raw/assets/init.d/ec2-get-credentials deleted file mode 100644 index b304ae2..0000000 --- a/providers/raw/assets/init.d/ec2-get-credentials +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: ec2-get-credentials -# Required-Start: $network -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: -# Description: Retrieve the ssh credentials and add to authorized_keys -### END INIT INFO -# -# ec2-get-credentials - Retrieve the ssh credentials and add to authorized_keys -# -# Based on /usr/local/sbin/ec2-get-credentials from Amazon's ami-20b65349 -# - -prog=$(basename $0) -logger="logger -t $prog" - -public_key_url=http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key -username='root' -# A little bit of nastyness to get the homedir, when the username is a variable -ssh_dir="`eval printf ~$username`/.ssh" -authorized_keys="$ssh_dir/authorized_keys" - -# Try to get the ssh public key from instance data. -public_key=`wget -qO - $public_key_url` -if [ -n "$public_key" ]; then - if [ ! -f $authorized_keys ]; then - if [ ! -d $ssh_dir ]; then - mkdir -m 700 $ssh_dir - chown $username:$username $ssh_dir - fi - touch $authorized_keys - chown $username:$username $authorized_keys - fi - - if ! grep -s -q "$public_key" $authorized_keys; then - printf "\n%s" -- "$public_key" >> $authorized_keys - $logger "New ssh key added to $authorized_keys from $public_key_url" - chmod 600 $authorized_keys - chown $username:$username $authorized_keys - fi -fi diff --git a/providers/raw/assets/init.d/ec2-run-user-data b/providers/raw/assets/init.d/ec2-run-user-data deleted file mode 100644 index 17b8b6f..0000000 --- a/providers/raw/assets/init.d/ec2-run-user-data +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: ec2-run-user-data -# Required-Start: ec2-get-credentials -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: -# Description: Run instance user-data if it looks like a script. -### END INIT INFO -# -# Only retrieves and runs the user-data script once per instance. If -# you want the user-data script to run again (e.g., on the next boot) -# then readd this script with insserv: -# insserv -d ec2-run-user-data -# -prog=$(basename $0) -logger="logger -t $prog" -instance_data_url="http://169.254.169.254/2008-02-01" - - -# Retrieve the instance user-data and run it if it looks like a script -user_data_file=$(tempfile --prefix ec2 --suffix .user-data --mode 700) -$logger "Retrieving user-data" -wget -qO $user_data_file $instance_data_url/user-data 2>&1 | $logger - -if [ $(file -b --mime-type $user_data_file) = 'application/x-gzip' ]; then - $logger "Uncompressing gzip'd user-data" - mv $user_data_file $user_data_file.gz - gunzip $user_data_file.gz -fi - -if [ ! -s $user_data_file ]; then - $logger "No user-data available" -elif head -1 $user_data_file | egrep -v '^#!'; then - $logger "Skipping user-data as it does not begin with #!" -else - $logger "Running user-data" - $user_data_file 2>&1 | logger -t "user-data" - $logger "user-data exit code: $?" -fi -rm -f $user_data_file - -# Disable this script, it may only run once -insserv -r $0 diff --git a/providers/raw/assets/init.d/expand-volume b/providers/raw/assets/init.d/expand-volume deleted file mode 100644 index 3b2d2a6..0000000 --- a/providers/raw/assets/init.d/expand-volume +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: expand-volume -# Required-Start: -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: -# Description: Expand the filesystem of the mounted root volume to its maximum possible size -### END INIT INFO - -prog=$(basename $0) -logger="logger -t $prog" - -device_path="/dev/xvda1" - -filesystem=`blkid | grep $device_path | sed 's#\(.*\):.*TYPE="\(.*\)".*#\2#'` - -case $filesystem in - xfs) xfs_growfs / ;; - ext2) resize2fs $device_path ;; - ext3) resize2fs $device_path ;; - ext4) resize2fs $device_path ;; - *) $logger "The filesystem $filesystem was not recognized. Unable to expand size." ;; -esac diff --git a/providers/raw/assets/init.d/generate-ssh-hostkeys b/providers/raw/assets/init.d/generate-ssh-hostkeys deleted file mode 100644 index c9efb12..0000000 --- a/providers/raw/assets/init.d/generate-ssh-hostkeys +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: generate-ssh-hostkeys -# Required-Start: $local_fs -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: S -# Default-Stop: -# Description: Generate ssh host keys if they do not exist -### END INIT INFO - -prog=$(basename $0) -logger="logger -t $prog" - -rsa_key="/etc/ssh/ssh_host_rsa_key" -dsa_key="/etc/ssh/ssh_host_dsa_key" -ecdsa_key="/etc/ssh/ssh_host_ecdsa_key" - -# Exit if the hostkeys already exist -if [ -f $rsa_key -a -f $dsa_key -a -f $ecdsa_key ]; then - exit -fi - -# Generate the ssh host keys -[ -f $rsa_key ] || ssh-keygen -f $rsa_key -t rsa -C 'host' -N '' -[ -f $dsa_key ] || ssh-keygen -f $dsa_key -t dsa -C 'host' -N '' -[ -f $ecdsa_key ] || ssh-keygen -f $ecdsa_key -t ecdsa -C 'host' -N '' - -# Output the public keys to the console -# This allows user to get host keys securely through console log -echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----" | $logger -ssh-keygen -l -f $rsa_key.pub | $logger -ssh-keygen -l -f $dsa_key.pub | $logger -ssh-keygen -l -f $ecdsa_key.pub | $logger -echo "------END SSH HOST KEY FINGERPRINTS------" | $logger diff --git a/providers/raw/assets/init.d/squeeze/generate-ssh-hostkeys b/providers/raw/assets/init.d/squeeze/generate-ssh-hostkeys deleted file mode 100644 index 148b87d..0000000 --- a/providers/raw/assets/init.d/squeeze/generate-ssh-hostkeys +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: generate-ssh-hostkeys -# Required-Start: $local_fs -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: S -# Default-Stop: -# Description: Generate ssh host keys if they do not exist -### END INIT INFO - -prog=$(basename $0) -logger="logger -t $prog" - -rsa_key="/etc/ssh/ssh_host_rsa_key" -dsa_key="/etc/ssh/ssh_host_dsa_key" - -# Exit if the hostkeys already exist -if [ -f $rsa_key -a -f $dsa_key ]; then - exit -fi - -# Generate the ssh host keys -[ -f $rsa_key ] || ssh-keygen -f $rsa_key -t rsa -C 'host' -N '' -[ -f $dsa_key ] || ssh-keygen -f $dsa_key -t dsa -C 'host' -N '' - -# Output the public keys to the console -# This allows user to get host keys securely through console log -echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----" | $logger -ssh-keygen -l -f $rsa_key.pub | $logger -ssh-keygen -l -f $dsa_key.pub | $logger -echo "------END SSH HOST KEY FINGERPRINTS------" | $logger diff --git a/providers/raw/tasks/initd.py b/providers/raw/tasks/initd.py deleted file mode 100644 index 5a479fe..0000000 --- a/providers/raw/tasks/initd.py +++ /dev/null @@ -1,49 +0,0 @@ -from base import Task -from common import phases -import os.path - - -class ResolveInitScripts(Task): - description = 'Determining which startup scripts to install or disable' - phase = phases.system_modification - - def run(self, info): - init_scripts = {'ec2-get-credentials': 'ec2-get-credentials', - 'ec2-run-user-data': 'ec2-run-user-data', - 'expand-volume': 'expand-volume'} - - init_scripts['generate-ssh-hostkeys'] = 'generate-ssh-hostkeys' - if info.manifest.system['release'] == 'squeeze': - init_scripts['generate-ssh-hostkeys'] = 'squeeze/generate-ssh-hostkeys' - - disable_scripts = ['hwclock.sh'] - if info.manifest.system['release'] == 'squeeze': - disable_scripts.append('hwclockfirst.sh') - - for name, path in init_scripts.iteritems(): - init_scripts[name] = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/init.d', path)) - - info.initd = {'install': init_scripts, - 'disable': disable_scripts} - - -class InstallInitScripts(Task): - description = 'Installing startup scripts' - phase = phases.system_modification - after = [ResolveInitScripts] - - def run(self, info): - import stat - rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | - stat.S_IROTH | stat.S_IXOTH) - from shutil import copy - from common.tools import log_check_call - for name, src in info.initd['install'].iteritems(): - dst = os.path.join(info.root, 'etc/init.d', name) - copy(src, dst) - os.chmod(dst, rwxr_xr_x) - log_check_call(['/usr/sbin/chroot', info.root, '/sbin/insserv', '-d', name]) - - for name in info.initd['disable']: - log_check_call(['/usr/sbin/chroot', info.root, '/sbin/insserv', '-r', name])