Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.5 kB)

1 54080484 Nikos Skalkotos
#!/bin/bash
2 54080484 Nikos Skalkotos
3 54080484 Nikos Skalkotos
# Copyright 2011 GRNET S.A. All rights reserved.
4 54080484 Nikos Skalkotos
#
5 54080484 Nikos Skalkotos
# Redistribution and use in source and binary forms, with or without
6 54080484 Nikos Skalkotos
# modification, are permitted provided that the following conditions
7 54080484 Nikos Skalkotos
# are met:
8 54080484 Nikos Skalkotos
#
9 54080484 Nikos Skalkotos
#   1. Redistributions of source code must retain the above copyright
10 54080484 Nikos Skalkotos
#      notice, this list of conditions and the following disclaimer.
11 54080484 Nikos Skalkotos
#
12 54080484 Nikos Skalkotos
#  2. Redistributions in binary form must reproduce the above copyright
13 54080484 Nikos Skalkotos
#     notice, this list of conditions and the following disclaimer in the
14 54080484 Nikos Skalkotos
#     documentation and/or other materials provided with the distribution.
15 54080484 Nikos Skalkotos
#
16 54080484 Nikos Skalkotos
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 54080484 Nikos Skalkotos
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 54080484 Nikos Skalkotos
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 54080484 Nikos Skalkotos
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 54080484 Nikos Skalkotos
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 54080484 Nikos Skalkotos
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 54080484 Nikos Skalkotos
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 54080484 Nikos Skalkotos
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 54080484 Nikos Skalkotos
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 54080484 Nikos Skalkotos
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 54080484 Nikos Skalkotos
# SUCH DAMAGE.
27 54080484 Nikos Skalkotos
#
28 54080484 Nikos Skalkotos
# The views and conclusions contained in the software and documentation are
29 54080484 Nikos Skalkotos
# those of the authors and should not be interpreted as representing official
30 54080484 Nikos Skalkotos
# policies, either expressed or implied, of GRNET S.A.
31 54080484 Nikos Skalkotos
32 bf7c33b2 Nikos Skalkotos
. @commondir@/common.sh
33 54080484 Nikos Skalkotos
34 c349d1b3 Nikos Skalkotos
set -e
35 c349d1b3 Nikos Skalkotos
36 54080484 Nikos Skalkotos
# terminate helper vm when the script exits
37 54080484 Nikos Skalkotos
CLEANUP+=("telinit 0")
38 54080484 Nikos Skalkotos
39 c349d1b3 Nikos Skalkotos
if [ ! -b $FLOPPY_DEV ]; then
40 c349d1b3 Nikos Skalkotos
    log_error "Floppy device is not present!"
41 c349d1b3 Nikos Skalkotos
fi
42 c349d1b3 Nikos Skalkotos
43 c349d1b3 Nikos Skalkotos
floppy=$(mktemp -d --tmpdir floppy.XXXXXXXX)
44 a93a31ee Nikos Skalkotos
CLEANUP+=("rmdir $floppy")
45 54080484 Nikos Skalkotos
46 c349d1b3 Nikos Skalkotos
mount $FLOPPY_DEV $floppy
47 c349d1b3 Nikos Skalkotos
CLEANUP+=("umount $floppy")
48 c349d1b3 Nikos Skalkotos
49 c349d1b3 Nikos Skalkotos
if [ -f $floppy/rules ]; then
50 c349d1b3 Nikos Skalkotos
    source $floppy/rules
51 54080484 Nikos Skalkotos
else
52 c349d1b3 Nikos Skalkotos
    log_error "Floppy does not contain \`rules\' file"
53 c308b9f9 Nikos Skalkotos
fi
54 54080484 Nikos Skalkotos
55 c349d1b3 Nikos Skalkotos
# Image mount point...
56 bf7c33b2 Nikos Skalkotos
target=$(mktemp -d --tmpdir target.XXXXXXXX)
57 a93a31ee Nikos Skalkotos
CLEANUP+=("rmdir $target")
58 54080484 Nikos Skalkotos
59 1bb3e009 Nikos Skalkotos
export SNF_IMAGE_TARGET=$target
60 54080484 Nikos Skalkotos
61 1bb3e009 Nikos Skalkotos
if [ ! -d "/usr/lib/snf-image/tasks" ]; then
62 1bb3e009 Nikos Skalkotos
    log_error "snf-image/tasks directory is missing"
63 1bb3e009 Nikos Skalkotos
fi
64 c349d1b3 Nikos Skalkotos
65 1bb3e009 Nikos Skalkotos
RUN_PARTS=$(which run-parts)
66 1bb3e009 Nikos Skalkotos
if [ -z "$RUN_PARTS" ]; then
67 1bb3e009 Nikos Skalkotos
    log_error "run-parts programe is missing from the system"
68 54080484 Nikos Skalkotos
fi
69 54080484 Nikos Skalkotos
70 1bb3e009 Nikos Skalkotos
echo "Execute all snf-image tasks...." 
71 bf7c33b2 Nikos Skalkotos
$RUN_PARTS -v --exit-on-error "@tasksdir@"
72 1bb3e009 Nikos Skalkotos
73 7f6bd8e0 Nikos Skalkotos
echo "SUCCESS" > $RESULT
74 7f6bd8e0 Nikos Skalkotos
75 54080484 Nikos Skalkotos
cleanup
76 54080484 Nikos Skalkotos
trap - EXIT
77 54080484 Nikos Skalkotos
78 54080484 Nikos Skalkotos
# never called...
79 54080484 Nikos Skalkotos
exit 0
80 54080484 Nikos Skalkotos
81 54080484 Nikos Skalkotos
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :