Commit d0cfa909 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Check if a Windows image is sysprepped

In InstallUnattend task, check if the image is sysprepped. If this is
not the case, then fail.
parent e98f835b
# Copyright (C) 2011-2015 GRNET S.A. and individual contributors
# Copyright (C) 2011-2016 GRNET S.A. and individual contributors
# Copyright (C) 2007, 2008, 2009 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
......@@ -848,6 +848,57 @@ get_windows_nt_version() {
fi
}
check_windows_if_sysprepped() {
local target state
target="$1"
# https://technet.microsoft.com/en-us/library/hh824815.aspx
state=$($HIVEXGET "$target/windows/system32/config/software" \
'\Microsoft\Windows\CurrentVersion\Setup\State')
case "$(grep '^"ImageState"=' <<< "$state" | cut -d= -f2)" in
\"IMAGE_STATE_COMPLETE\")
log_error "Image is not sysprepped. Windows customization is only" \
"supported for sysprepped images."
;;
\"IMAGE_STATE_UNDEPLOYABLE\")
log_error "Image is in an undeployable state. Setup seems corrupted."
;;
\"IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE\")
;;
\"IMAGE_STATE_GENERALIZE_RESEAL_TO_AUDIT\")
;;
\"IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE\")
log_error "Customization is supported only for generalized images." \
"You must run sysprep /generalize when creating the image."
;;
\"IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT\")
log_error "Customization is supported only for generalized images." \
"You must run sysprep /generalize when creating the image."
;;
*)
log_error "Can't check if image is sysprepped. Unknown System State."
;;
esac
}
check_windows-legacy_if_sysprepped() {
local target setup
target="$1"
setup=$($HIVEXGET "$target/windows/system32/config/system" '\Setup')
if ! grep '"SystemSetupInProgress"=dword:00000001' <<<"$setup" &>/dev/null; then
log_error "Image is not sysprepped. Windows customization is only" \
"supported for sysprepped images."
fi
if ! grep '"MiniSetupInProgress"=dword:00000001' <<<"$setup" &>/dev/null; then
log_error "MiniSetup flag is not set in Sysprep. Windows" \
"customization is only supported for sysprepped images with" \
"MiniSetup enabled."
fi
}
check_if_root() {
local os fd device is_root args windows_fs linux_fs freebsd_fs netbsd_fs \
openbsd_fs supported_fs major minor
......
......@@ -81,6 +81,9 @@ if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = windows ]; then
log_error "Windows image seems older than Vista. Use 'windows-legacy' as OSFAMILY"
fi
# The system must be generalized in order to proceed
check_windows_if_sysprepped "$target"
unattend=$(get_unattend "$target")
if test -n "$unattend" && ! check_yes_no SNF_IMAGE_PROPERTY_IGNORE_UNATTEND; then
warn "Using the Unattend.xml file found in the image"
......@@ -141,6 +144,9 @@ elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows-legacy" ]; then
log_error "Windows image is not legacy. Use 'windows' as OSFAMILY"
fi
# Check if Mini-Setup is to be started at the next boot
check_windows-legacy_if_sysprepped "$target"
# If using an old-style (XP / Server 2003) SYSPREP.INF answer file,
# ensure C:\SnfScripts\SetupComplete.cmd is executed via CmdLines.txt
# which must be installed in the InstalledfilesPath from SYSPREP.INF.
......
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