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 . @commondir@/common.sh
24 if [ "x$1" != "x--force" ]; then
25 echo "WARNING: Exiting, this command would cause the system to halt." >&2
26 echo "Use --force if you know what you're doing." >&2
30 # terminate helper vm when the script exits
33 if [ ! -b "$FLOPPY_DEV" ]; then
34 log_error "Floppy device is not present!"
37 floppy=$(mktemp -d --tmpdir floppy.XXXXXX)
38 add_cleanup rmdir "$floppy"
40 mount $FLOPPY_DEV $floppy
41 add_cleanup umount "$floppy"
43 if [ -f "$floppy/rules" ]; then
44 source "$floppy/rules"
46 log_error "Floppy does not contain \`rules\' file"
49 if [ -n "$SNF_IMAGE_PROPERTIES" ]; then
50 properties=$(mktemp --tmpdir properties.XXXXXX)
51 add_cleanup rm "$properties"
52 echo "$SNF_IMAGE_PROPERTIES" |
53 "@scriptsdir@/decode-properties.py" "$properties"
57 # Image mount point...
58 target=$(mktemp -d --tmpdir target.XXXXXX)
59 add_cleanup rmdir "$target"
61 export SNF_IMAGE_TARGET="$target"
63 if [ ! -d "@tasksdir@" ]; then
64 log_error "snf-image/tasks directory is missing"
67 RUN_PARTS=$(which run-parts)
68 if [ -z "$RUN_PARTS" ]; then
69 log_error "run-parts program is missing from the system"
72 # If something goes wrong with the tasks, try to umount the target filesystem
73 # in case it is left mounted...
74 trap '{ umount "$target"; }' ERR
76 if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
78 if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows)$ ]]; then
79 log_error "Supported values for OSFAMILY property are: linux|windows"
82 # Redirect standard error to standard output,
83 # prepend a timestamp before each line of output.
84 echo "Execute all snf-image tasks...."
85 $RUN_PARTS -v --exit-on-error "@tasksdir@" 2>&1|
86 while IFS= read -r line; do
87 echo $(date +%Y:%m:%d-%H:%M:%S.%N) "$line"
91 # Disable the trap. If code reaches here, the filesystem is unmounted.
94 echo "SUCCESS" > "$RESULT"
102 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :