Statistics
| Branch: | Revision:

root / create @ 640e7e45

History | View | Annotate | Download (3.3 kB)

1
#!/bin/bash
2

    
3
# Copyright (C) 2010 Oregon State University
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
set -e
21

    
22
. common.sh
23

    
24
debug set -x
25

    
26
if [ "$IMAGE_TYPE" = "tarball" ] ; then
27
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.tar.gz"
28
elif [ "$IMAGE_TYPE" = "qemu" ] ; then
29
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.img"
30
elif [ "$IMAGE_TYPE" = "dump" ] ; then
31
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}-root.dump"
32
fi
33

    
34
if [ "$CDINSTALL" = "no" ] ; then
35
    # If the target device is not a real block device we'll first losetup it.
36
    # This is needed for file disks.
37
    if [ ! -b $blockdev ]; then
38
      ORIGINAL_BLOCKDEV=$blockdev
39
      blockdev=$($LOSETUP -sf $blockdev)
40
      CLEANUP+=("$LOSETUP -d $blockdev")
41
    fi
42

    
43
    if [ ! -f "$IMAGE_FILE" ] ; then
44
      log_error "Can't find image file: $IMAGE_FILE"
45
      exit 1
46
    fi
47

    
48
    # If the image is tarball based, then we need to manually create the
49
    # volumes, filesystems, etc
50
    if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then
51
        # Create 3 partitions, /boot, swap, & /
52
        format_disk0 $blockdev
53
    elif [ "${IMAGE_TYPE}" = "qemu" ] ; then
54
        # need a recent version of qemu for this
55
        ${QEMU_IMG} convert ${IMAGE_FILE} -O host_device ${blockdev}
56
    fi
57

    
58
    filesystem_base_dev=$(map_disk0 $blockdev)
59
    if [ "${SWAP}" = "yes" ] ; then
60
        boot_dev="${filesystem_base_dev}-1"
61
        swap_dev="${filesystem_base_dev}-2"
62
        root_dev="${filesystem_base_dev}-3"
63
    else
64
        boot_dev="${filesystem_base_dev}-1"
65
        root_dev="${filesystem_base_dev}-2"
66
    fi
67
    CLEANUP+=("unmap_disk0 $blockdev")
68

    
69
    if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then
70
        mkfs_disk0 $boot_dev $root_dev $swap_dev
71
    fi
72

    
73
    TARGET=`mktemp -d` || exit 1
74
    CLEANUP+=("rmdir $TARGET")
75

    
76
    # mount filesystems
77
    mount_disk0 $TARGET $root_dev $boot_dev
78

    
79
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
80
        # unpack image
81
        tar pzxf $IMAGE_FILE -C $TARGET
82
    elif [ "${IMAGE_TYPE}" = "dump" ] ; then
83
        boot_dump="${IMAGE_FILE/root.dump/boot.dump}" 
84
        root_dump="${IMAGE_FILE}"
85
        if [ ! -f "$boot_dump" ] ; then
86
          log_error "Can't find image file: $boot_dump"
87
          exit 1
88
        fi
89
        ( cd ${TARGET}; restore -r -y -f ${root_dump} )
90
        ( cd ${TARGET}/boot; restore -r -y -f ${boot_dump} )
91
    fi
92

    
93
    RUN_PARTS=`which run-parts`
94

    
95
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
96
      TARGET=$TARGET
97
      BLOCKDEV=$blockdev
98
      ROOT_DEV=$root_dev
99
      BOOT_DEV=$boot_dev
100
      export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV
101
      $RUN_PARTS $CUSTOMIZE_DIR
102
    fi
103
fi
104

    
105
# execute cleanups
106
cleanup
107
trap - EXIT
108

    
109
exit 0