Statistics
| Branch: | Revision:

root / create @ 6f0a1fef

History | View | Annotate | Download (2.9 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
if [ "${IMAGE_DEBUG} " = 1 ] ; then
25
    set -x
26
fi
27

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

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

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

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

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

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

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

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

    
80
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
81
        # unpack image
82
        tar pzxf $IMAGE_FILE -C $TARGET
83
    fi
84

    
85
    RUN_PARTS=`which run-parts`
86

    
87
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
88
      TARGET=$TARGET
89
      BLOCKDEV=$blockdev
90
      ROOT_DEV=$root_dev
91
      BOOT_DEV=$boot_dev
92
      export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV
93
      $RUN_PARTS $CUSTOMIZE_DIR
94
    fi
95
fi
96

    
97
# execute cleanups
98
cleanup
99
trap - EXIT
100

    
101
exit 0