Commit 4dae7b02 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add new os_answer_file image property

This can be used to specify a URI hosting a Windows answer file to be
injected to the image during deployment. Depending on the image (windows
or windows-legacy) this file can either be an xml file (unattend.xml) or
an inf one (sysprep.inf). The file gets higher priority than the file
that may be hosted inside the image.
parent b687eb2c
......@@ -130,11 +130,13 @@ get_api20_arguments() {
get_api10_arguments
if [ "$SCRIPT_NAME" = "create" ]; then
local osparams="IMG_ID IMG_FORMAT IMG_PASSWD IMG_PASSWD_HASH IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL OS_PRODUCT_KEY"
local osp
local osparams osp
osparams=(IMG_ID IMG_FORMAT IMG_PASSWD IMG_PASSWD_HASH IMG_PROPERTIES
IMG_PERSONALITY CONFIG_URL OS_PRODUCT_KEY OS_ANSWER_FILE)
# Store OSP_VAR in VAR
for param in $osparams; do
for param in "${osparams[@]}"; do
# This is black magic. Only execute the eval command if the "param"
# variable is set. This way we can distinguish between variables
# with value "" and variables that have not been set at all
......@@ -148,7 +150,7 @@ get_api20_arguments() {
local config config_params
echo "Downloading configuration parameters from: \`$CONFIG_URL'" >&2
config=$($CURL -f "$CONFIG_URL")
config_params=$(./decode-config.py $osparams <<< "$config")
config_params=$(./decode-config.py "${osparams[@]}" <<< "$config")
eval "$config_params"
fi
fi
......@@ -228,20 +230,34 @@ create_floppy() {
dd bs=512 count=2880 if=/dev/zero of="$img"
mkfs.ext2 -F "$img" > /dev/null
mount "$img" "$target" -o loop
set | egrep ^snf_export_\\w+= | sed -e 's/^snf_export_/export SNF_IMAGE_/' \
> "$target/rules"
if [ -n "$UNATTEND" ]; then
log_warning "Used deprecated variable UNATTEND which may be removed in the future"
if [ -f "$UNATTEND" ]; then
cat "$UNATTEND" > "$target/unattend.xml"
else
log_error "Unattend file: \`"$UNATTEND"' does not exist"
log_error "File defined with UNATTEND variable (=$UNATTEND) does not exist"
exit 1
fi
elif [ -n "$OS_ANSWER_FILE" ]; then
$CURL -f "$OS_ANSWER_FILE" > "$target/unattend.xml"
# This file has higher priority than the one in the image
snf_export_PROPERTY_IGNORE_UNATTEND=yes
else
sed -e "s/@TIMEZONE@/$name/g" unattend.xml.in > "$target/unattend.xml"
fi
sed -e "s/@TIMEZONE_INDEX@/$index/g" sysprep.inf.in > "$target/sysprep.inf"
# Since unattend.xml and sysprep.inf are used mutually exclusive, if the
# user has defined an OS Answer File, make both of them point to it.
if [ -n "$OS_ANSWER_FILE" ]; then
ln -s unattend.xml "$target/sysprep.inf"
else
sed -e "s/@TIMEZONE_INDEX@/$index/g" sysprep.inf.in > "$target/sysprep.inf"
fi
set | egrep ^snf_export_\\w+= | sed -e 's/^snf_export_/export SNF_IMAGE_/' \
> "$target/rules"
# Put all the NIC info in the floppy
set | egrep ^NIC_ | sed -e 's/^/export SNF_IMAGE_/' >> "$target/rules"
umount "$target"
......
......@@ -110,8 +110,10 @@
# UNATTEND: This variable overwrites the unattend.xml file used when deploying
# a Windows image. snf-image-helper will use its own unattend.xml file if this
# variable is empty. Please leave this empty, unless you really know what you
# are doing.
# variable is empty.
# WARNING: This variable is DEPRECATED. If you need to define an answer file
# different that the one shipped with snf-image, which is very likely, put it
# inside the image or use the os_answer_file OS parameter.
# UNATTEND="@UNATTEND@"
# WINDOWS_TIMEZONE: This variable is used to specify the time zone when
......
......@@ -5,4 +5,5 @@ img_passwd_hash Hashed version of the password to be assigned to the user accoun
img_properties The image properties that are used to customize the image (json.dumps format)
img_personality The files to be injected into the image (base64 encoded in a json.dumps format)
os_product_key A product key to be used to license a Windows deployment (windows-only)
os_answer_file An answer file used by Windows to automate the setup process (windows-only)
config_url The URL to download configuration data from
......@@ -24,7 +24,7 @@ set -e
check_required() {
local required_params="IMG_ID IMG_FORMAT"
local osparams="$required_params IMG_PASSWD IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL OS_PRODUCT_KEY"
local osparams="$required_params IMG_PASSWD IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL OS_PRODUCT_KEY OS_ANSWER_FILE"
local osp
source_variant
......@@ -53,6 +53,15 @@ check_required() {
exit 1
fi
fi
if [ -n "${OS_ANSWER_FILE+dummy}" ]; then
# Not the perfect regexp but should catch most errors.
if [[ ! "${OS_ANSWER_FILE}" =~ ^(https?|ftps?|file)://.+ ]]; then
log_error "Invalid OS API Parameter: os_answer_file."
log_error "Valid value is an file,ftp[s] or http[s] URI".
exit 1
fi
fi
}
if [ -z "$OSP_CONFIG_URL" ]; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment