From 52a1884822ecb9474e12e6c16b62dbd0728a4a0e Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 28 Nov 2012 10:41:42 -0800 Subject: Check for running inside RHEL and adjust the logging options. It seems like at least RHEL does not have the "--stderr" option but instead only supports the short version "-s" so add a check that will switch from the long version to the short version when RHEL is detected. LP: #1083715 --- tools/write-ssh-key-fingerprints | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/write-ssh-key-fingerprints b/tools/write-ssh-key-fingerprints index aa1f3c38..d69c7fcc 100755 --- a/tools/write-ssh-key-fingerprints +++ b/tools/write-ssh-key-fingerprints @@ -1,5 +1,18 @@ #!/bin/sh + +logger_opts="-p user.info -t ec2" + +if [ -f "/etc/redhat-release" ] +then + # Seems like rhel only supports the short version + logger_opts="$logger_opts -s" +else + logger_opts="$logger_opts --stderr" +fi + +# Redirect stderr to stdout exec 2>&1 + fp_blist=",${1}," key_blist=",${2}," { @@ -16,9 +29,9 @@ done echo "-----END SSH HOST KEY FINGERPRINTS-----" echo "#############################################################" -} | logger -p user.info --stderr -t "ec2" +} | logger $logger_opts -echo -----BEGIN SSH HOST KEY KEYS----- +echo "-----BEGIN SSH HOST KEY KEYS-----" for f in /etc/ssh/ssh_host_*key.pub; do [ -f "$f" ] || continue read ktype line < "$f" @@ -26,4 +39,4 @@ for f in /etc/ssh/ssh_host_*key.pub; do [ "${key_blist#*,$ktype,}" = "${key_blist}" ] || continue cat $f done -echo -----END SSH HOST KEY KEYS----- +echo "-----END SSH HOST KEY KEYS-----" -- cgit v1.2.3 From 75d991b2e807d8bf26a2b94791870b86c43a1c96 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 4 Dec 2012 10:04:14 -0500 Subject: replace if..else based on presense of /etc/redhat-release with use of -s instead of using '--stderr' on non-rhel based on the presense of /etc/redhat-release, just use the short form '-s' everywhere. --- tools/write-ssh-key-fingerprints | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/write-ssh-key-fingerprints b/tools/write-ssh-key-fingerprints index d69c7fcc..6c3451fd 100755 --- a/tools/write-ssh-key-fingerprints +++ b/tools/write-ssh-key-fingerprints @@ -2,13 +2,9 @@ logger_opts="-p user.info -t ec2" -if [ -f "/etc/redhat-release" ] -then - # Seems like rhel only supports the short version - logger_opts="$logger_opts -s" -else - logger_opts="$logger_opts --stderr" -fi +# rhels' version of logger_opts does not support long +# for of -s (--stderr), so use short form. +logger_opts="$logger_opts -s" # Redirect stderr to stdout exec 2>&1 -- cgit v1.2.3 From aee23ad10ef7854a197ab664a6e0738cd042d716 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 21 Jan 2013 20:21:04 -0800 Subject: Add in a tool to help make mime multipart messages. --- tools/make-mime.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 tools/make-mime.py (limited to 'tools') diff --git a/tools/make-mime.py b/tools/make-mime.py new file mode 100755 index 00000000..72b29fb9 --- /dev/null +++ b/tools/make-mime.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +import argparse +import sys + +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +KNOWN_CONTENT_TYPES = [ + 'text/x-include-once-url', + 'text/x-include-url', + 'text/cloud-config-archive', + 'text/upstart-job', + 'text/cloud-config', + 'text/part-handler', + 'text/x-shellscript', + 'text/cloud-boothook', +] + + +def file_content_type(text): + try: + filename, content_type = text.split(":", 1) + return (open(filename, 'r'), filename, content_type.strip()) + except: + raise argparse.ArgumentError("Invalid value for %r" % (text)) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-a", "--attach", + dest="files", + type=file_content_type, + action='append', + default=[], + required=True, + metavar=":", + help="attach the given file in the specified " + "content type") + args = parser.parse_args() + sub_messages = [] + for i, (fh, filename, format_type) in enumerate(args.files): + contents = fh.read() + sub_message = MIMEText(contents, format_type, sys.getdefaultencoding()) + sub_message.add_header('Content-Disposition', + 'attachment; filename="%s"' % (filename)) + content_type = sub_message.get_content_type().lower() + if content_type not in KNOWN_CONTENT_TYPES: + sys.stderr.write(("WARNING: content type %r for attachment %s " + "may be incorrect!\n") % (content_type, i + 1)) + sub_messages.append(sub_message) + combined_message = MIMEMultipart() + for msg in sub_messages: + combined_message.attach(msg) + print(combined_message) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3