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 mount -t tmpfs -o size=20m tmpfs /tmp
25 /etc/init.d/udev start
30 exit 0 # Hopefully this is never called...
35 . @commondir@/common.sh
39 # Enable errtrace to make functions inherit the ERR trap
44 if grep snf_image_activate_helper /proc/cmdline > /dev/null; then
45 # terminate helper vm when the script exits
46 add_cleanup system_poweroff
48 log_error "Kernel command line activation flag: " \
49 "\`snf_image_activate_helper' is missing"
54 if [ ! -b "$RULES_DEV" ]; then
55 log_error "Device file hosting the rules file: \`$RULES_DEV' does not exist"
58 rules=$(mktemp -d --tmpdir rules.XXXXXX)
59 add_cleanup rmdir "$rules"
61 $MOUNT $RULES_DEV $rules
62 add_cleanup umount "$rules"
64 if [ -f "$rules/rules" ]; then
67 log_error "$RULES_DEV does not contain \`rules\' file"
70 if [ -f "$rules/unattend.xml" ]; then
71 export SNF_IMAGE_UNATTEND="$rules/unattend.xml"
74 if [ -n "$SNF_IMAGE_PROPERTIES" ]; then
75 properties=$(mktemp --tmpdir properties.XXXXXX)
76 add_cleanup rm "$properties"
77 if ! echo "$SNF_IMAGE_PROPERTIES" | \
78 "@scriptsdir@/decode-properties.py" "$properties"; then
80 log_error "Unable to decode image properties. " \
81 "Please check if the variable is in valid json format."
86 # Image mount point...
87 target=$(mktemp -d --tmpdir target.XXXXXX)
88 add_cleanup rmdir "$target"
90 export SNF_IMAGE_TARGET="$target"
92 if [ ! -d "@tasksdir@" ]; then
93 log_error "snf-image/tasks directory is missing"
96 RUN_PARTS=$(which run-parts)
97 if [ -z "$RUN_PARTS" ]; then
98 log_error "run-parts program is missing from the system"
102 if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
104 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "" ]; then
105 log_error "Required image property \`OSFAMILY' is missing or empty."
108 if [ "$SNF_IMAGE_PROPERTY_ROOT_PARTITION" = "" ]; then
109 log_error "Required image property \`ROOT_PARTITION' is missing or empty."
112 export SNF_IMAGE_RESIZE_PART="$(get_partition_to_resize "$SNF_IMAGE_DEV")"
114 if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows|freebsd)$ ]]; then
115 log_error "Supported values for OSFAMILY property are: linux|windows|freebsd"
118 # If something goes wrong with the tasks, try to umount the disk file
119 # systems that are still mounted.
120 trap '{ umount_all "$target"; }' ERR
122 # Redirect standard error to standard output,
123 # prepend a timestamp before each line of output.
124 echo "Execute all snf-image tasks...."
125 $RUN_PARTS -v --exit-on-error "@tasksdir@" 2>&1|
126 while read -r line; do
127 echo $($DATE +%Y:%m:%d-%H:%M:%S.%N) "$line"
130 # Reset the handler to its original value
131 trap report_error ERR
143 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :