#! /bin/bash
+# Copyright (C) 2011 GRNET S.A.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
### BEGIN TASK INFO
# Provides: InstallUnattend
# RunBefore: UmountImage
# RunAfter: MountImage
# Short-Description: Installs Unattend.xml for unattended windows setup
-### END TAST INFO
+### END TASK INFO
set -e
-. @commondir@/common.sh
+. "@commondir@/common.sh"
if [ -z "$SNF_IMAGE_TARGET" ]; then
- log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
+ log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
-if [ "$SNF_IMAGE_TYPE" != "ntfsdump" ]; then
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "windows" ]; then
exit 0
fi
-if [ -f @commondir@/unattend.xml ]; then
- cat @commondir@/unattend.xml > $SNF_IMAGE_TARGET/Unattend.xml
-else
+if [ ! -f "@commondir@/unattend.xml" ]; then
log_error "File \`@commondir@/unattend.xml' is missing."
fi
+target=$SNF_IMAGE_TARGET
+mkdir -p "$target/Windows/Setup/Scripts"
+
+cat "@commondir@/unattend.xml" > "$target/Unattend.xml"
+echo "del /Q /F C:\Unattend.xml" > \
+ "$target/Windows/Setup/Scripts/SetupComplete.cmd"
+
+mkdir -p "$target/Windows/SnfScripts"
+
+echo "exit" > "$target/Windows/SnfScripts/ExtendFilesystem"
+echo "del /Q /F C:\Windows\SnfScripts\ExtendFilesystem" >> \
+ "$target/Windows/Setup/Scripts/SetupComplete.cmd"
+
+echo "@echo off" > "$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
+# For security reasons, overwrite the file before deleting...
+spaces=$(printf "%200s");
+echo "echo ${spaces// /X} > C:\Windows\SnfScripts\ChangeAdminPassword.cmd" >> \
+ "$target/Windows/Setup/Scripts/SetupComplete.cmd"
+echo "del /Q /F C:\Windows\SnfScripts\ChangeAdminPassword.cmd" >> \
+ "$target/Windows/Setup/Scripts/SetupComplete.cmd"
+
+echo "rmdir C:\Windows\SnfScripts" >> \
+ "$target/Windows/Setup/Scripts/SetupComplete.cmd"
+
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :