3 # Copyright (C) 2011 GRNET S.A.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
24 /etc/init.d/udev start
29 exit 0 # Hopefully this is never called...
32 . @commondir@/common.sh
36 if grep snf_image_activate_helper /proc/cmdline > /dev/null; then
37 # terminate helper vm when the script exits
38 add_cleanup system_poweroff
40 log_error "Kernel command line activation flag: " \
41 "\`snf_image_activate_helper' is missing"
44 if [ ! -b "$FLOPPY_DEV" ]; then
45 log_error "Floppy device is not present!"
48 floppy=$(mktemp -d --tmpdir floppy.XXXXXX)
49 add_cleanup rmdir "$floppy"
51 mount $FLOPPY_DEV $floppy
52 add_cleanup umount "$floppy"
54 if [ -f "$floppy/rules" ]; then
55 source "$floppy/rules"
57 log_error "Floppy does not contain \`rules\' file"
60 if [ -f "$floppy/unattend.xml" ]; then
61 export SNF_IMAGE_UNATTEND="$floppy/unattend.xml"
64 if [ -n "$SNF_IMAGE_PROPERTIES" ]; then
65 properties=$(mktemp --tmpdir properties.XXXXXX)
66 add_cleanup rm "$properties"
67 if ! echo "$SNF_IMAGE_PROPERTIES" | \
68 "@scriptsdir@/decode-properties.py" "$properties"; then
70 log_error "Unable to decode image properties. " \
71 "Please check if the variable is in valid json format."
76 # Image mount point...
77 target=$(mktemp -d --tmpdir target.XXXXXX)
78 add_cleanup rmdir "$target"
80 export SNF_IMAGE_TARGET="$target"
82 if [ ! -d "@tasksdir@" ]; then
83 log_error "snf-image/tasks directory is missing"
86 RUN_PARTS=$(which run-parts)
87 if [ -z "$RUN_PARTS" ]; then
88 log_error "run-parts program is missing from the system"
91 # If something goes wrong with the tasks, try to umount the target filesystem
92 # in case it is left mounted...
93 trap '{ umount "$target"; }' ERR
95 if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
97 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "" ]; then
98 log_error "Required image property \`OSFAMILY' is missing or empty."
101 if [ "$SNF_IMAGE_PROPERTY_ROOT_PARTITION" = "" ]; then
102 log_error "Required image property \`ROOT_PARTITION' is missing or empty."
105 export SNF_IMAGE_RESIZE_PART="$(get_partition_to_resize "$SNF_IMAGE_DEV")"
107 if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows)$ ]]; then
108 log_error "Supported values for OSFAMILY property are: linux|windows"
111 # Redirect standard error to standard output,
112 # prepend a timestamp before each line of output.
113 echo "Execute all snf-image tasks...."
114 $RUN_PARTS -v --exit-on-error "@tasksdir@" 2>&1|
115 while IFS= read -r line; do
116 echo $($DATE +%Y:%m:%d-%H:%M:%S.%N) "$line"
120 # Disable the trap. If code reaches here, the filesystem is unmounted.
123 echo "SUCCESS" > "$RESULT"
131 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :