Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-image
Commits
473f4fa5
Commit
473f4fa5
authored
Nov 09, 2011
by
Nikos Skalkotos
Browse files
Add image-properties support in helper
parent
2545cdc5
Changes
9
Hide whitespace changes
Inline
Side-by-side
snf-image-helper/Makefile.am
View file @
473f4fa5
...
...
@@ -7,7 +7,7 @@ SUBDIRS = tasks
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
\
...
...
snf-image-helper/decode-properties.py
0 → 100755
View file @
473f4fa5
#!/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 :
snf-image-helper/snf-image-helper.in
View file @
473f4fa5
...
...
@@ -59,6 +59,16 @@ else
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
"
...
...
snf-image-helper/tasks/40AddDeleteUnattendScript.in
View file @
473f4fa5
...
...
@@ -14,7 +14,7 @@ if [ ! -d "$SNF_IMAGE_TARGET" ]; then
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:
\U
nattend.xml"
>
"
$SNF_IMAGE_TARGET
/Windows/Setup/Scripts/SetupComplete.cmd"
...
...
snf-image-helper/tasks/40DeleteSSHKeys.in
View file @
473f4fa5
...
...
@@ -16,7 +16,7 @@ fi
target
=
"
$SNF_IMAGE_TARGET
"
if
[
"
$SNF_IMAGE_
OS
"
!=
"linux"
]
;
then
if
[
"
$SNF_IMAGE_
PROPERTY_OSFAMILY
"
!=
"linux"
]
;
then
cleanup
trap
- EXIT
exit
0
...
...
snf-image-helper/tasks/40InstallUnattend.in
View file @
473f4fa5
...
...
@@ -14,7 +14,7 @@ if [ -z "$SNF_IMAGE_TARGET" ]; then
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
...
...
snf-image-helper/tasks/40SELinuxAutorelabel.in
View file @
473f4fa5
...
...
@@ -14,7 +14,7 @@ if [ ! -d "$SNF_IMAGE_TARGET" ]; then
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
...
...
snf-image-helper/tasks/50AssignHostname.in
View file @
473f4fa5
...
...
@@ -62,9 +62,9 @@ if [ -z "$SNF_IMAGE_HOSTNAME" ]; 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
...
...
snf-image-helper/tasks/50ChangePassword.in
View file @
473f4fa5
...
...
@@ -66,9 +66,9 @@ if [ -z "$SNF_IMAGE_PASSWORD" ]; then
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment