Revision 473f4fa5
b/snf-image-helper/Makefile.am | ||
---|---|---|
7 | 7 |
|
8 | 8 |
dist_doc_DATA = COPYING AUTHORS ChangeLog |
9 | 9 |
dist_bin_SCRIPTS = snf-image-helper |
10 |
dist_scripts_SCRIPTS= snf-passtohash.py inject-files.py |
|
10 |
dist_scripts_SCRIPTS= snf-passtohash.py inject-files.py decode-properties.py
|
|
11 | 11 |
dist_common_DATA = common.sh unattend.xml |
12 | 12 |
|
13 | 13 |
edit = sed \ |
b/snf-image-helper/decode-properties.py | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
|
|
3 |
"""Decode a json encoded string with properties |
|
4 |
|
|
5 |
This program decodes a json encoded properties string and outputs it in a |
|
6 |
bash sourcable way. The properties are passed to the program through a JSON |
|
7 |
string either read from a file or from standard input and are outputed to a |
|
8 |
target file. |
|
9 |
""" |
|
10 |
|
|
11 |
import sys |
|
12 |
import os |
|
13 |
import subprocess |
|
14 |
import json |
|
15 |
from StringIO import StringIO |
|
16 |
from optparse import OptionParser |
|
17 |
|
|
18 |
def parse_arguments(input_args): |
|
19 |
usage = "Usage: %prog [options] <output_file>" |
|
20 |
parser = OptionParser(usage=usage) |
|
21 |
parser.add_option("-i", "--input", |
|
22 |
action="store",type='string', dest="input_file", |
|
23 |
help="get input from FILE instead of stdin", |
|
24 |
metavar="FILE") |
|
25 |
|
|
26 |
opts, args = parser.parse_args(input_args) |
|
27 |
|
|
28 |
if len(args) != 1: |
|
29 |
parser.error('output file is missing') |
|
30 |
output_file = args[0] |
|
31 |
|
|
32 |
if opts.input_file is not None: |
|
33 |
if not os.path.isfile(opts.input_file): |
|
34 |
parser.error('input file does not exist') |
|
35 |
|
|
36 |
return (opts.input_file, output_file) |
|
37 |
|
|
38 |
|
|
39 |
def main(): |
|
40 |
(input_file, output_file) = parse_arguments(sys.argv[1:]) |
|
41 |
|
|
42 |
infh = sys.stdin if input_file is None else open(input_file, 'r') |
|
43 |
outfh = open(output_file, 'w') |
|
44 |
|
|
45 |
properties = json.load(infh) |
|
46 |
for key, value in properties.items(): |
|
47 |
os.environ['SNF_IMAGE_PROPERTY_' + key] = value |
|
48 |
|
|
49 |
output = StringIO(subprocess.check_output(['bash', '-c', 'set'])) |
|
50 |
for line in iter(output): |
|
51 |
if line.startswith('SNF_IMAGE_PROPERTY_'): |
|
52 |
outfh.write(line) |
|
53 |
|
|
54 |
infh.close() |
|
55 |
outfh.close() |
|
56 |
return 0 |
|
57 |
|
|
58 |
|
|
59 |
if __name__ == "__main__": |
|
60 |
sys.exit(main()) |
|
61 |
|
|
62 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/snf-image-helper.in | ||
---|---|---|
59 | 59 |
log_error "Floppy does not contain \`rules\' file" |
60 | 60 |
fi |
61 | 61 |
|
62 |
if [ -n "$SNF_IMAGE_PROPERTIES" ]; then |
|
63 |
properties=$(mktemp --tmpdir properties.XXXXXX) |
|
64 |
add_cleanup rm "$properties" |
|
65 |
echo "SNF_IMAGE_PROPERTIES" | |
|
66 |
"@scriptsdir@/snf-decode-properties.py" > "$properties" |
|
67 |
source "$properties" |
|
68 |
else |
|
69 |
log_error "SNF_IMAGE_PROPERTIES variable is missing" |
|
70 |
fi |
|
71 |
|
|
62 | 72 |
# Image mount point... |
63 | 73 |
target=$(mktemp -d --tmpdir target.XXXXXX) |
64 | 74 |
add_cleanup rmdir "$target" |
b/snf-image-helper/tasks/40AddDeleteUnattendScript.in | ||
---|---|---|
14 | 14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
15 | 15 |
fi |
16 | 16 |
|
17 |
if [ "$SNF_IMAGE_OS" = "windows" ]; then
|
|
17 |
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
|
|
18 | 18 |
# Make sure Unattend.xml is removed after setup has finished |
19 | 19 |
mkdir -p "$SNF_IMAGE_TARGET/Windows/Setup/Scripts" |
20 | 20 |
echo "del /Q /F C:\Unattend.xml" > "$SNF_IMAGE_TARGET/Windows/Setup/Scripts/SetupComplete.cmd" |
b/snf-image-helper/tasks/40DeleteSSHKeys.in | ||
---|---|---|
16 | 16 |
|
17 | 17 |
target="$SNF_IMAGE_TARGET" |
18 | 18 |
|
19 |
if [ "$SNF_IMAGE_OS" != "linux" ]; then
|
|
19 |
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
|
|
20 | 20 |
cleanup |
21 | 21 |
trap - EXIT |
22 | 22 |
exit 0 |
b/snf-image-helper/tasks/40InstallUnattend.in | ||
---|---|---|
14 | 14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
15 | 15 |
fi |
16 | 16 |
|
17 |
if [ "$SNF_IMAGE_OS" != "windows" ]; then
|
|
17 |
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "windows" ]; then
|
|
18 | 18 |
exit 0 |
19 | 19 |
fi |
20 | 20 |
|
b/snf-image-helper/tasks/40SELinuxAutorelabel.in | ||
---|---|---|
14 | 14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
15 | 15 |
fi |
16 | 16 |
|
17 |
if [ "$SNF_IMAGE_OS" = "linux" ]; then
|
|
17 |
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
|
|
18 | 18 |
distro=$(get_base_distro $SNF_IMAGE_TARGET) |
19 | 19 |
|
20 | 20 |
if [ "$distro" = "redhat" ]; then |
b/snf-image-helper/tasks/50AssignHostname.in | ||
---|---|---|
62 | 62 |
log_error "Hostname is missing" |
63 | 63 |
fi |
64 | 64 |
|
65 |
if [ "$SNF_IMAGE_OS" = "windows" ]; then
|
|
65 |
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
|
|
66 | 66 |
windows_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME" |
67 |
elif [ "$SNF_IMAGE_OS" = "linux" ]; then
|
|
67 |
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
|
|
68 | 68 |
linux_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME" |
69 | 69 |
fi |
70 | 70 |
|
b/snf-image-helper/tasks/50ChangePassword.in | ||
---|---|---|
66 | 66 |
log_error "Password is missing" |
67 | 67 |
fi |
68 | 68 |
|
69 |
if [ "$SNF_IMAGE_OS" = "windows" ]; then
|
|
69 |
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
|
|
70 | 70 |
windows_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD" |
71 |
elif [ "$SNF_IMAGE_OS" = "linux" ]; then
|
|
71 |
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
|
|
72 | 72 |
linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD" |
73 | 73 |
fi |
74 | 74 |
|
Also available in: Unified diff