Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.9 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 bad5ca1f Nikos Skalkotos
set -o pipefail
36 c349d1b3 Nikos Skalkotos
37 ff7783b8 Vangelis Koukis
if [ "x$1" != "x--force" ]; then
38 af4a3462 Vangelis Koukis
    echo "WARNING: Exiting, this command would cause the system to halt." >&2
39 af4a3462 Vangelis Koukis
    echo "Use --force if you know what you're doing." >&2
40 ff7783b8 Vangelis Koukis
    exit 1
41 ff7783b8 Vangelis Koukis
fi
42 ff7783b8 Vangelis Koukis
43 54080484 Nikos Skalkotos
# terminate helper vm when the script exits
44 bad5ca1f Nikos Skalkotos
add_cleanup telinit 0
45 54080484 Nikos Skalkotos
46 bad5ca1f Nikos Skalkotos
if [ ! -b "$FLOPPY_DEV" ]; then
47 c349d1b3 Nikos Skalkotos
    log_error "Floppy device is not present!"
48 c349d1b3 Nikos Skalkotos
fi
49 c349d1b3 Nikos Skalkotos
50 bad5ca1f Nikos Skalkotos
floppy=$(mktemp -d --tmpdir floppy.XXXXXX)
51 bad5ca1f Nikos Skalkotos
add_cleanup rmdir "$floppy"
52 54080484 Nikos Skalkotos
53 c349d1b3 Nikos Skalkotos
mount $FLOPPY_DEV $floppy
54 bad5ca1f Nikos Skalkotos
add_cleanup umount "$floppy"
55 c349d1b3 Nikos Skalkotos
56 bad5ca1f Nikos Skalkotos
if [ -f "$floppy/rules" ]; then
57 bad5ca1f Nikos Skalkotos
    source "$floppy/rules"
58 54080484 Nikos Skalkotos
else
59 c349d1b3 Nikos Skalkotos
    log_error "Floppy does not contain \`rules\' file"
60 c308b9f9 Nikos Skalkotos
fi
61 54080484 Nikos Skalkotos
62 c349d1b3 Nikos Skalkotos
# Image mount point...
63 bad5ca1f Nikos Skalkotos
target=$(mktemp -d --tmpdir target.XXXXXX)
64 bad5ca1f Nikos Skalkotos
add_cleanup rmdir "$target"
65 54080484 Nikos Skalkotos
66 bad5ca1f Nikos Skalkotos
export SNF_IMAGE_TARGET="$target"
67 54080484 Nikos Skalkotos
68 27b1de98 Nikos Skalkotos
if [ ! -d "@tasksdir@" ]; then
69 1bb3e009 Nikos Skalkotos
    log_error "snf-image/tasks directory is missing"
70 1bb3e009 Nikos Skalkotos
fi
71 c349d1b3 Nikos Skalkotos
72 1bb3e009 Nikos Skalkotos
RUN_PARTS=$(which run-parts)
73 1bb3e009 Nikos Skalkotos
if [ -z "$RUN_PARTS" ]; then
74 1bb3e009 Nikos Skalkotos
    log_error "run-parts programe is missing from the system"
75 54080484 Nikos Skalkotos
fi
76 54080484 Nikos Skalkotos
77 0468a748 Nikos Skalkotos
# If something goes wrong with the tasks, try to umount the target filesystem
78 0468a748 Nikos Skalkotos
# in case it is left mounted...
79 bad5ca1f Nikos Skalkotos
trap '{ umount "$target"; }' ERR
80 0468a748 Nikos Skalkotos
81 bad5ca1f Nikos Skalkotos
echo "Execute all snf-image tasks...."
82 bf7c33b2 Nikos Skalkotos
$RUN_PARTS -v --exit-on-error "@tasksdir@"
83 1bb3e009 Nikos Skalkotos
84 cb6b4f68 Nikos Skalkotos
# Disable the trap. If code reaches here, the filesystem is unmounted.
85 cb6b4f68 Nikos Skalkotos
trap - ERR
86 cb6b4f68 Nikos Skalkotos
87 bad5ca1f Nikos Skalkotos
echo "SUCCESS" > "$RESULT"
88 7f6bd8e0 Nikos Skalkotos
89 54080484 Nikos Skalkotos
cleanup
90 54080484 Nikos Skalkotos
trap - EXIT
91 54080484 Nikos Skalkotos
92 54080484 Nikos Skalkotos
# never called...
93 54080484 Nikos Skalkotos
exit 0
94 54080484 Nikos Skalkotos
95 54080484 Nikos Skalkotos
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :