Statistics
| Branch: | Revision:

root / create @ 0d9031a6

History | View | Annotate | Download (3.5 kB)

1 79224631 Lance Albertson
#!/bin/bash
2 79224631 Lance Albertson
3 f1afb4b1 Lance Albertson
# Copyright (C) 2010 Oregon State University
4 79224631 Lance Albertson
#
5 79224631 Lance Albertson
# This program is free software; you can redistribute it and/or modify
6 79224631 Lance Albertson
# it under the terms of the GNU General Public License as published by
7 79224631 Lance Albertson
# the Free Software Foundation; either version 2 of the License, or
8 79224631 Lance Albertson
# (at your option) any later version.
9 79224631 Lance Albertson
#
10 79224631 Lance Albertson
# This program is distributed in the hope that it will be useful, but
11 79224631 Lance Albertson
# WITHOUT ANY WARRANTY; without even the implied warranty of
12 79224631 Lance Albertson
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 79224631 Lance Albertson
# General Public License for more details.
14 79224631 Lance Albertson
#
15 79224631 Lance Albertson
# You should have received a copy of the GNU General Public License
16 79224631 Lance Albertson
# along with this program; if not, write to the Free Software
17 79224631 Lance Albertson
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 79224631 Lance Albertson
# 02110-1301, USA.
19 79224631 Lance Albertson
20 79224631 Lance Albertson
set -e
21 79224631 Lance Albertson
22 6f0a1fef Lance Albertson
. common.sh
23 6f0a1fef Lance Albertson
24 e7a2d1ad Lance Albertson
debug set -x
25 e84e87cd Lance Albertson
26 baca98f3 Lance Albertson
if [ "$IMAGE_TYPE" = "tarball" ] ; then
27 baca98f3 Lance Albertson
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.tar.gz"
28 baca98f3 Lance Albertson
elif [ "$IMAGE_TYPE" = "qemu" ] ; then
29 baca98f3 Lance Albertson
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.img"
30 640e7e45 Lance Albertson
elif [ "$IMAGE_TYPE" = "dump" ] ; then
31 640e7e45 Lance Albertson
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}-root.dump"
32 baca98f3 Lance Albertson
fi
33 134c11c3 Lance Albertson
34 fcce5224 Lance Albertson
if [ "$CDINSTALL" = "no" ] ; then
35 fcce5224 Lance Albertson
    # If the target device is not a real block device we'll first losetup it.
36 fcce5224 Lance Albertson
    # This is needed for file disks.
37 fcce5224 Lance Albertson
    if [ ! -b $blockdev ]; then
38 fcce5224 Lance Albertson
      ORIGINAL_BLOCKDEV=$blockdev
39 fcce5224 Lance Albertson
      blockdev=$($LOSETUP -sf $blockdev)
40 fcce5224 Lance Albertson
      CLEANUP+=("$LOSETUP -d $blockdev")
41 fcce5224 Lance Albertson
    fi
42 fcce5224 Lance Albertson
43 b05b1ab6 Lance Albertson
    if [ ! -f "$IMAGE_FILE" ] ; then
44 b05b1ab6 Lance Albertson
      log_error "Can't find image file: $IMAGE_FILE"
45 b05b1ab6 Lance Albertson
      exit 1
46 b05b1ab6 Lance Albertson
    fi
47 b05b1ab6 Lance Albertson
48 b05b1ab6 Lance Albertson
    # If the image is tarball based, then we need to manually create the
49 b05b1ab6 Lance Albertson
    # volumes, filesystems, etc
50 640e7e45 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then
51 b05b1ab6 Lance Albertson
        # Create 3 partitions, /boot, swap, & /
52 b05b1ab6 Lance Albertson
        format_disk0 $blockdev
53 b05b1ab6 Lance Albertson
    elif [ "${IMAGE_TYPE}" = "qemu" ] ; then
54 b05b1ab6 Lance Albertson
        # need a recent version of qemu for this
55 ab712029 Lance Albertson
        ${QEMU_IMG} convert ${IMAGE_FILE} -O host_device ${blockdev}
56 b05b1ab6 Lance Albertson
    fi
57 b05b1ab6 Lance Albertson
58 494927a8 Lance Albertson
    filesystem_dev=$(map_disk0 $blockdev)
59 a1d43218 Lance Albertson
    CLEANUP+=("unmap_disk0 $blockdev")
60 494927a8 Lance Albertson
    root_dev=$(map_partition $filesystem_dev root)
61 494927a8 Lance Albertson
    boot_dev=$(map_partition $filesystem_dev boot)
62 494927a8 Lance Albertson
    swap_dev=$(map_partition $filesystem_dev swap)
63 fcce5224 Lance Albertson
64 640e7e45 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then
65 77449e7c Lance Albertson
        mkfs_disk0
66 3903b7f1 Lance Albertson
        root_uuid="$($VOL_ID $root_dev)"
67 3903b7f1 Lance Albertson
        [ -n "$boot_dev" ] && boot_uuid="$($VOL_ID $boot_dev)"
68 3903b7f1 Lance Albertson
        [ -n "$swap_dev" ] && swap_uuid="$($VOL_ID $swap_dev)"
69 b05b1ab6 Lance Albertson
    fi
70 fcce5224 Lance Albertson
71 916b6dd1 Lance Albertson
    TARGET=`mktemp -d` || exit 1
72 916b6dd1 Lance Albertson
    CLEANUP+=("rmdir $TARGET")
73 fcce5224 Lance Albertson
74 a1d43218 Lance Albertson
    # mount filesystems
75 77449e7c Lance Albertson
    mount_disk0 $TARGET
76 b05b1ab6 Lance Albertson
77 b05b1ab6 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
78 b05b1ab6 Lance Albertson
        # unpack image
79 916b6dd1 Lance Albertson
        tar pzxf $IMAGE_FILE -C $TARGET
80 640e7e45 Lance Albertson
    elif [ "${IMAGE_TYPE}" = "dump" ] ; then
81 0d9031a6 Lance Albertson
        root_dump="${IMAGE_FILE}"
82 640e7e45 Lance Albertson
        ( cd ${TARGET}; restore -r -y -f ${root_dump} )
83 77449e7c Lance Albertson
84 77449e7c Lance Albertson
        if [ -n "${boot_dev}" ] ; then
85 77449e7c Lance Albertson
            boot_dump="${IMAGE_FILE/root.dump/boot.dump}"
86 77449e7c Lance Albertson
            if [ ! -f "$boot_dump" ] ; then
87 77449e7c Lance Albertson
              log_error "Can't find image file: $boot_dump"
88 77449e7c Lance Albertson
              exit 1
89 77449e7c Lance Albertson
            fi
90 77449e7c Lance Albertson
            ( cd ${TARGET}/boot; restore -r -y -f ${boot_dump} )
91 77449e7c Lance Albertson
        fi
92 b05b1ab6 Lance Albertson
    fi
93 e5ec11e4 Lance Albertson
94 3903b7f1 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then
95 3903b7f1 Lance Albertson
        setup_fstab $TARGET
96 3903b7f1 Lance Albertson
    fi
97 3903b7f1 Lance Albertson
98 fcce5224 Lance Albertson
    RUN_PARTS=`which run-parts`
99 fcce5224 Lance Albertson
100 fcce5224 Lance Albertson
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
101 916b6dd1 Lance Albertson
      TARGET=$TARGET
102 fcce5224 Lance Albertson
      BLOCKDEV=$blockdev
103 f7959feb Lance Albertson
      ROOT_DEV=$root_dev
104 c29e092d Lance Albertson
      BOOT_DEV=$boot_dev
105 e0f1ce56 Lance Albertson
      export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV
106 fcce5224 Lance Albertson
      $RUN_PARTS $CUSTOMIZE_DIR
107 fcce5224 Lance Albertson
    fi
108 79224631 Lance Albertson
fi
109 79224631 Lance Albertson
110 79224631 Lance Albertson
# execute cleanups
111 79224631 Lance Albertson
cleanup
112 79224631 Lance Albertson
trap - EXIT
113 79224631 Lance Albertson
114 79224631 Lance Albertson
exit 0