root / create @ 6f3e718d
History | View | Annotate | Download (4.3 kB)
1 | 6f3e718d | Nikos Skalkotos | #!/bin/bas |
---|---|---|---|
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 | 78422bb3 | Lance Albertson | ${QEMU_IMG} convert ${IMAGE_FILE} -O host_device ${blockdev} > /dev/null |
56 | b05b1ab6 | Lance Albertson | fi |
57 | b05b1ab6 | Lance Albertson | |
58 | 8727c57d | Lance Albertson | # deploying something like a windows image, skip the rest |
59 | 8727c57d | Lance Albertson | if [ "${NOMOUNT}" = "yes" ] ; then |
60 | 8727c57d | Lance Albertson | cleanup |
61 | 8727c57d | Lance Albertson | exit 0 |
62 | 8727c57d | Lance Albertson | fi |
63 | 8727c57d | Lance Albertson | |
64 | 494927a8 | Lance Albertson | filesystem_dev=$(map_disk0 $blockdev) |
65 | a1d43218 | Lance Albertson | CLEANUP+=("unmap_disk0 $blockdev") |
66 | 494927a8 | Lance Albertson | root_dev=$(map_partition $filesystem_dev root) |
67 | 494927a8 | Lance Albertson | boot_dev=$(map_partition $filesystem_dev boot) |
68 | 494927a8 | Lance Albertson | swap_dev=$(map_partition $filesystem_dev swap) |
69 | fcce5224 | Lance Albertson | |
70 | 2e8db6b9 | Nikos Skalkotos | # Check partition existence |
71 | 2e8db6b9 | Nikos Skalkotos | if [ ! -e "$root_dev" ] ; then |
72 | 2e8db6b9 | Nikos Skalkotos | log_error "Root partition: $root_dev does not exist!" |
73 | 2e8db6b9 | Nikos Skalkotos | exit 1; |
74 | 2e8db6b9 | Nikos Skalkotos | fi |
75 | d577183a | Nikos Skalkotos | if [ -n "$boot_dev" -a ! -e "$boot_dev" ] ; then |
76 | 2e8db6b9 | Nikos Skalkotos | log_error "Boot partition: $boot_dev does not exist!" |
77 | 2e8db6b9 | Nikos Skalkotos | exit 1; |
78 | 2e8db6b9 | Nikos Skalkotos | fi |
79 | d577183a | Nikos Skalkotos | if [ -n "$swap_dev" -a ! -e "$swap_dev" ] ; then |
80 | 2e8db6b9 | Nikos Skalkotos | log_error "Swap partiion: $swap_dev does not exist!" |
81 | 2e8db6b9 | Nikos Skalkotos | exit 1; |
82 | 2e8db6b9 | Nikos Skalkotos | fi |
83 | 2e8db6b9 | Nikos Skalkotos | |
84 | 640e7e45 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then |
85 | 77449e7c | Lance Albertson | mkfs_disk0 |
86 | 3903b7f1 | Lance Albertson | root_uuid="$($VOL_ID $root_dev)" |
87 | b8a540bb | Lance Albertson | [ -n "$boot_dev" ] && sleep 1 && boot_uuid="$($VOL_ID $boot_dev)" |
88 | b8a540bb | Lance Albertson | [ -n "$swap_dev" ] && sleep 1 && swap_uuid="$($VOL_ID $swap_dev)" |
89 | b05b1ab6 | Lance Albertson | fi |
90 | fcce5224 | Lance Albertson | |
91 | 916b6dd1 | Lance Albertson | TARGET=`mktemp -d` || exit 1 |
92 | 916b6dd1 | Lance Albertson | CLEANUP+=("rmdir $TARGET") |
93 | fcce5224 | Lance Albertson | |
94 | a1d43218 | Lance Albertson | # mount filesystems |
95 | 77449e7c | Lance Albertson | mount_disk0 $TARGET |
96 | b05b1ab6 | Lance Albertson | |
97 | b05b1ab6 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" ] ; then |
98 | b05b1ab6 | Lance Albertson | # unpack image |
99 | 916b6dd1 | Lance Albertson | tar pzxf $IMAGE_FILE -C $TARGET |
100 | 640e7e45 | Lance Albertson | elif [ "${IMAGE_TYPE}" = "dump" ] ; then |
101 | 0d9031a6 | Lance Albertson | root_dump="${IMAGE_FILE}" |
102 | 78422bb3 | Lance Albertson | ( cd ${TARGET}; restore -r -y -f ${root_dump} > /dev/null ) |
103 | 77449e7c | Lance Albertson | |
104 | 77449e7c | Lance Albertson | if [ -n "${boot_dev}" ] ; then |
105 | 77449e7c | Lance Albertson | boot_dump="${IMAGE_FILE/root.dump/boot.dump}" |
106 | 77449e7c | Lance Albertson | if [ ! -f "$boot_dump" ] ; then |
107 | 77449e7c | Lance Albertson | log_error "Can't find image file: $boot_dump" |
108 | 77449e7c | Lance Albertson | exit 1 |
109 | 77449e7c | Lance Albertson | fi |
110 | 78422bb3 | Lance Albertson | ( cd ${TARGET}/boot; restore -r -y -f ${boot_dump} > /dev/null ) |
111 | 77449e7c | Lance Albertson | fi |
112 | b05b1ab6 | Lance Albertson | fi |
113 | e5ec11e4 | Lance Albertson | |
114 | 3903b7f1 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then |
115 | 3903b7f1 | Lance Albertson | setup_fstab $TARGET |
116 | 3903b7f1 | Lance Albertson | fi |
117 | 3903b7f1 | Lance Albertson | |
118 | 9f4b2c31 | Lance Albertson | if [ "${INSTANCE_HV_serial_console}" = "True" ] ; then |
119 | 9f4b2c31 | Lance Albertson | setup_console $TARGET |
120 | 9f4b2c31 | Lance Albertson | fi |
121 | 9f4b2c31 | Lance Albertson | |
122 | 6f3e718d | Nikos Skalkotos | epilogue $TARGET |
123 | 47e547ca | Nikos Skalkotos | |
124 | fcce5224 | Lance Albertson | RUN_PARTS=`which run-parts` |
125 | fcce5224 | Lance Albertson | |
126 | fcce5224 | Lance Albertson | if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then |
127 | 916b6dd1 | Lance Albertson | TARGET=$TARGET |
128 | fcce5224 | Lance Albertson | BLOCKDEV=$blockdev |
129 | f7959feb | Lance Albertson | ROOT_DEV=$root_dev |
130 | c29e092d | Lance Albertson | BOOT_DEV=$boot_dev |
131 | ab462591 | Constantinos Venetsanopoulos | IMG_PASSWD=$IMG_PASSWD |
132 | 43c9dece | Nikos Skalkotos | HOSTNAME=$instance |
133 | 43c9dece | Nikos Skalkotos | export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV IMAGE_TYPE IMG_PASSWD HOSTNAME |
134 | fcce5224 | Lance Albertson | $RUN_PARTS $CUSTOMIZE_DIR |
135 | fcce5224 | Lance Albertson | fi |
136 | 79224631 | Lance Albertson | fi |
137 | 79224631 | Lance Albertson | |
138 | 79224631 | Lance Albertson | # execute cleanups |
139 | 79224631 | Lance Albertson | cleanup |
140 | 79224631 | Lance Albertson | trap - EXIT |
141 | 79224631 | Lance Albertson | |
142 | 79224631 | Lance Albertson | exit 0 |