Statistics
| Branch: | Tag: | Revision:

root / snf-image-helper / snf-image-helper.in @ fcae4e91

History | View | Annotate | Download (2.9 kB)

1
#!/bin/bash
2

    
3
# Copyright (C) 2011 GRNET S.A. 
4
#
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.
9
#
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.
14
#
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
18
# 02110-1301, USA.
19

    
20
. @commondir@/common.sh
21

    
22
set -e
23

    
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
27
    exit 1
28
fi
29

    
30
# terminate helper vm when the script exits
31
add_cleanup telinit 0
32

    
33
prepare_helper
34

    
35
if [ ! -b "$FLOPPY_DEV" ]; then
36
    log_error "Floppy device is not present!"
37
fi
38

    
39
floppy=$(mktemp -d --tmpdir floppy.XXXXXX)
40
add_cleanup rmdir "$floppy"
41

    
42
mount $FLOPPY_DEV $floppy
43
add_cleanup umount "$floppy"
44

    
45
if [ -f "$floppy/rules" ]; then
46
    source "$floppy/rules"
47
else
48
    log_error "Floppy does not contain \`rules\' file"
49
fi
50

    
51
if [ -f "$floppy/unattend.xml" ]; then
52
    export SNF_IMAGE_UNATTEND="$floppy/unattend.xml"
53
fi
54

    
55
if [ -n "$SNF_IMAGE_PROPERTIES" ]; then
56
    properties=$(mktemp --tmpdir properties.XXXXXX)
57
    add_cleanup rm "$properties"
58
    echo "$SNF_IMAGE_PROPERTIES" |
59
        "@scriptsdir@/decode-properties.py" "$properties"
60
    source "$properties"
61
fi
62

    
63
# Image mount point...
64
target=$(mktemp -d --tmpdir target.XXXXXX)
65
add_cleanup rmdir "$target"
66

    
67
export SNF_IMAGE_TARGET="$target"
68

    
69
if [ ! -d "@tasksdir@" ]; then
70
    log_error "snf-image/tasks directory is missing"
71
fi
72

    
73
RUN_PARTS=$(which run-parts)
74
if [ -z "$RUN_PARTS" ]; then
75
    log_error "run-parts program is missing from the system"
76
fi
77

    
78
# If something goes wrong with the tasks, try to umount the target filesystem
79
# in case it is left mounted...
80
trap '{ umount "$target"; }' ERR
81

    
82
if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
83

    
84
    export SNF_IMAGE_RESIZE_PART="$(get_partition_to_resize "$SNF_IMAGE_DEV")"
85

    
86
    if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows)$ ]]; then
87
        log_error "Supported values for OSFAMILY property are: linux|windows"
88
    fi
89

    
90
    # Redirect standard error to standard output,
91
    # prepend a timestamp before each line of output.
92
    echo "Execute all snf-image tasks...."
93
    $RUN_PARTS -v --exit-on-error "@tasksdir@" 2>&1|
94
        while IFS= read -r line; do
95
            echo $(date +%Y:%m:%d-%H:%M:%S.%N) "$line"
96
        done
97
fi
98

    
99
# Disable the trap. If code reaches here, the filesystem is unmounted.
100
trap - ERR
101

    
102
return_success
103

    
104
cleanup
105
trap - EXIT
106

    
107
# never called...
108
exit 0
109

    
110
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :