dist_doc_DATA = COPYING AUTHORS ChangeLog
dist_bin_SCRIPTS = snf-image-helper
-dist_scripts_SCRIPTS= snf-passtohash.py inject-files.py
+dist_scripts_SCRIPTS= snf-passtohash.py inject-files.py decode-properties.py
dist_common_DATA = common.sh unattend.xml
edit = sed \
--- /dev/null
+#!/usr/bin/env python
+
+"""Decode a json encoded string with properties
+
+This program decodes a json encoded properties string and outputs it in a
+bash sourcable way. The properties are passed to the program through a JSON
+string either read from a file or from standard input and are outputed to a
+target file.
+"""
+
+import sys
+import os
+import subprocess
+import json
+from StringIO import StringIO
+from optparse import OptionParser
+
+def parse_arguments(input_args):
+ usage = "Usage: %prog [options] <output_file>"
+ parser = OptionParser(usage=usage)
+ parser.add_option("-i", "--input",
+ action="store",type='string', dest="input_file",
+ help="get input from FILE instead of stdin",
+ metavar="FILE")
+
+ opts, args = parser.parse_args(input_args)
+
+ if len(args) != 1:
+ parser.error('output file is missing')
+ output_file = args[0]
+
+ if opts.input_file is not None:
+ if not os.path.isfile(opts.input_file):
+ parser.error('input file does not exist')
+
+ return (opts.input_file, output_file)
+
+
+def main():
+ (input_file, output_file) = parse_arguments(sys.argv[1:])
+
+ infh = sys.stdin if input_file is None else open(input_file, 'r')
+ outfh = open(output_file, 'w')
+
+ properties = json.load(infh)
+ for key, value in properties.items():
+ os.environ['SNF_IMAGE_PROPERTY_' + key] = value
+
+ output = StringIO(subprocess.check_output(['bash', '-c', 'set']))
+ for line in iter(output):
+ if line.startswith('SNF_IMAGE_PROPERTY_'):
+ outfh.write(line)
+
+ infh.close()
+ outfh.close()
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
+
+# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
log_error "Floppy does not contain \`rules\' file"
fi
+if [ -n "$SNF_IMAGE_PROPERTIES" ]; then
+ properties=$(mktemp --tmpdir properties.XXXXXX)
+ add_cleanup rm "$properties"
+ echo "SNF_IMAGE_PROPERTIES" |
+ "@scriptsdir@/snf-decode-properties.py" > "$properties"
+ source "$properties"
+else
+ log_error "SNF_IMAGE_PROPERTIES variable is missing"
+fi
+
# Image mount point...
target=$(mktemp -d --tmpdir target.XXXXXX)
add_cleanup rmdir "$target"
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
-if [ "$SNF_IMAGE_OS" = "windows" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
# Make sure Unattend.xml is removed after setup has finished
mkdir -p "$SNF_IMAGE_TARGET/Windows/Setup/Scripts"
echo "del /Q /F C:\Unattend.xml" > "$SNF_IMAGE_TARGET/Windows/Setup/Scripts/SetupComplete.cmd"
target="$SNF_IMAGE_TARGET"
-if [ "$SNF_IMAGE_OS" != "linux" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
cleanup
trap - EXIT
exit 0
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
-if [ "$SNF_IMAGE_OS" != "windows" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "windows" ]; then
exit 0
fi
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
-if [ "$SNF_IMAGE_OS" = "linux" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
distro=$(get_base_distro $SNF_IMAGE_TARGET)
if [ "$distro" = "redhat" ]; then
log_error "Hostname is missing"
fi
-if [ "$SNF_IMAGE_OS" = "windows" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
windows_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
-elif [ "$SNF_IMAGE_OS" = "linux" ]; then
+elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
linux_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
fi
log_error "Password is missing"
fi
-if [ "$SNF_IMAGE_OS" = "windows" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
windows_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
-elif [ "$SNF_IMAGE_OS" = "linux" ]; then
+elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
fi