snf-image-helper.in 2.71 KB
Newer Older
Nikos Skalkotos's avatar
Nikos Skalkotos committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# Copyright 2011 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#   1. Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of GRNET S.A.

Nikos Skalkotos's avatar
Nikos Skalkotos committed
32
. @commondir@/common.sh
Nikos Skalkotos's avatar
Nikos Skalkotos committed
33

Nikos Skalkotos's avatar
Nikos Skalkotos committed
34
set -e
35
set -o pipefail
Nikos Skalkotos's avatar
Nikos Skalkotos committed
36

Nikos Skalkotos's avatar
Nikos Skalkotos committed
37
# terminate helper vm when the script exits
38
add_cleanup telinit 0
Nikos Skalkotos's avatar
Nikos Skalkotos committed
39

40
if [ ! -b "$FLOPPY_DEV" ]; then
Nikos Skalkotos's avatar
Nikos Skalkotos committed
41
42
43
    log_error "Floppy device is not present!"
fi

44
45
floppy=$(mktemp -d --tmpdir floppy.XXXXXX)
add_cleanup rmdir "$floppy"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
46

Nikos Skalkotos's avatar
Nikos Skalkotos committed
47
mount $FLOPPY_DEV $floppy
48
add_cleanup umount "$floppy"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
49

50
51
if [ -f "$floppy/rules" ]; then
    source "$floppy/rules"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
52
else
Nikos Skalkotos's avatar
Nikos Skalkotos committed
53
    log_error "Floppy does not contain \`rules\' file"
54
fi
Nikos Skalkotos's avatar
Nikos Skalkotos committed
55

Nikos Skalkotos's avatar
Nikos Skalkotos committed
56
# Image mount point...
57
58
target=$(mktemp -d --tmpdir target.XXXXXX)
add_cleanup rmdir "$target"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
59

60
export SNF_IMAGE_TARGET="$target"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
61

62
if [ ! -d "@tasksdir@" ]; then
63
64
    log_error "snf-image/tasks directory is missing"
fi
Nikos Skalkotos's avatar
Nikos Skalkotos committed
65

66
67
68
RUN_PARTS=$(which run-parts)
if [ -z "$RUN_PARTS" ]; then
    log_error "run-parts programe is missing from the system"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
69
70
fi

71
72
# If something goes wrong with the tasks, try to umount the target filesystem
# in case it is left mounted...
73
trap '{ umount "$target"; }' ERR
74

75
echo "Execute all snf-image tasks...."
Nikos Skalkotos's avatar
Nikos Skalkotos committed
76
$RUN_PARTS -v --exit-on-error "@tasksdir@"
77

78
79
80
# Disable the trap. If code reaches here, the filesystem is unmounted.
trap - ERR

81
echo "SUCCESS" > "$RESULT"
82

Nikos Skalkotos's avatar
Nikos Skalkotos committed
83
84
85
86
87
88
89
cleanup
trap - EXIT

# never called...
exit 0

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