root / create @ 8d77389f
History | View | Annotate | Download (4.9 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 | 5dc61974 | Nikos Skalkotos | OS_FAMILY="linux" |
27 | 5dc61974 | Nikos Skalkotos | |
28 | baca98f3 | Lance Albertson | if [ "$IMAGE_TYPE" = "tarball" ] ; then |
29 | baca98f3 | Lance Albertson | IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.tar.gz" |
30 | baca98f3 | Lance Albertson | elif [ "$IMAGE_TYPE" = "qemu" ] ; then |
31 | baca98f3 | Lance Albertson | IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.img" |
32 | 640e7e45 | Lance Albertson | elif [ "$IMAGE_TYPE" = "dump" ] ; then |
33 | 640e7e45 | Lance Albertson | IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}-root.dump" |
34 | a33d2ab2 | Nikos Skalkotos | elif [ "$IMAGE_TYPE" = "ntfsclone" ]; then |
35 | a33d2ab2 | Nikos Skalkotos | IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.img" |
36 | a33d2ab2 | Nikos Skalkotos | OS_FAMILY="windows" |
37 | baca98f3 | Lance Albertson | fi |
38 | 134c11c3 | Lance Albertson | |
39 | a33d2ab2 | Nikos Skalkotos | if [ "$OS_FAMILY" = "linux" ]; then |
40 | a33d2ab2 | Nikos Skalkotos | . common_linux.sh |
41 | a33d2ab2 | Nikos Skalkotos | elif [ "$OS_FAMILY" = "windows" ]; then |
42 | a33d2ab2 | Nikos Skalkotos | . common_windows.sh |
43 | a33d2ab2 | Nikos Skalkotos | SWAP="no" |
44 | a33d2ab2 | Nikos Skalkotos | fi |
45 | 5dc61974 | Nikos Skalkotos | |
46 | fcce5224 | Lance Albertson | if [ "$CDINSTALL" = "no" ] ; then |
47 | fcce5224 | Lance Albertson | # If the target device is not a real block device we'll first losetup it. |
48 | fcce5224 | Lance Albertson | # This is needed for file disks. |
49 | fcce5224 | Lance Albertson | if [ ! -b $blockdev ]; then |
50 | fcce5224 | Lance Albertson | ORIGINAL_BLOCKDEV=$blockdev |
51 | fcce5224 | Lance Albertson | blockdev=$($LOSETUP -sf $blockdev) |
52 | fcce5224 | Lance Albertson | CLEANUP+=("$LOSETUP -d $blockdev") |
53 | fcce5224 | Lance Albertson | fi |
54 | fcce5224 | Lance Albertson | |
55 | b05b1ab6 | Lance Albertson | if [ ! -f "$IMAGE_FILE" ] ; then |
56 | b05b1ab6 | Lance Albertson | log_error "Can't find image file: $IMAGE_FILE" |
57 | b05b1ab6 | Lance Albertson | exit 1 |
58 | b05b1ab6 | Lance Albertson | fi |
59 | b05b1ab6 | Lance Albertson | |
60 | b05b1ab6 | Lance Albertson | # If the image is tarball based, then we need to manually create the |
61 | b05b1ab6 | Lance Albertson | # volumes, filesystems, etc |
62 | 640e7e45 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then |
63 | b05b1ab6 | Lance Albertson | # Create 3 partitions, /boot, swap, & / |
64 | bb78ba49 | Nikos Skalkotos | ${OS_FAMILY}_format_disk0 $blockdev |
65 | b05b1ab6 | Lance Albertson | elif [ "${IMAGE_TYPE}" = "qemu" ] ; then |
66 | b05b1ab6 | Lance Albertson | # need a recent version of qemu for this |
67 | 78422bb3 | Lance Albertson | ${QEMU_IMG} convert ${IMAGE_FILE} -O host_device ${blockdev} > /dev/null |
68 | a33d2ab2 | Nikos Skalkotos | elif [ "${IMAGE_TYPE}" = "ntfsclone" ] ; then |
69 | a33d2ab2 | Nikos Skalkotos | ${OS_FAMILY}_format_disk0 $blockdev |
70 | b05b1ab6 | Lance Albertson | fi |
71 | b05b1ab6 | Lance Albertson | |
72 | 8727c57d | Lance Albertson | # deploying something like a windows image, skip the rest |
73 | 8727c57d | Lance Albertson | if [ "${NOMOUNT}" = "yes" ] ; then |
74 | 8727c57d | Lance Albertson | cleanup |
75 | 8727c57d | Lance Albertson | exit 0 |
76 | 8727c57d | Lance Albertson | fi |
77 | 8727c57d | Lance Albertson | |
78 | 494927a8 | Lance Albertson | filesystem_dev=$(map_disk0 $blockdev) |
79 | a1d43218 | Lance Albertson | CLEANUP+=("unmap_disk0 $blockdev") |
80 | 494927a8 | Lance Albertson | root_dev=$(map_partition $filesystem_dev root) |
81 | 494927a8 | Lance Albertson | boot_dev=$(map_partition $filesystem_dev boot) |
82 | 494927a8 | Lance Albertson | swap_dev=$(map_partition $filesystem_dev swap) |
83 | fcce5224 | Lance Albertson | |
84 | e9568fe9 | Nikos Skalkotos | # Check partition existence |
85 | e9568fe9 | Nikos Skalkotos | if [ ! -e "$root_dev" ] ; then |
86 | e9568fe9 | Nikos Skalkotos | log_error "Root partition: $root_dev does not exist!" |
87 | e9568fe9 | Nikos Skalkotos | exit 1; |
88 | e9568fe9 | Nikos Skalkotos | fi |
89 | 025dd949 | Nikos Skalkotos | if [ -n "$boot_dev" -a ! -e "$boot_dev" ] ; then |
90 | e9568fe9 | Nikos Skalkotos | log_error "Boot partition: $boot_dev does not exist!" |
91 | e9568fe9 | Nikos Skalkotos | exit 1; |
92 | e9568fe9 | Nikos Skalkotos | fi |
93 | 025dd949 | Nikos Skalkotos | if [ -n "$swap_dev" -a ! -e "$swap_dev" ] ; then |
94 | e9568fe9 | Nikos Skalkotos | log_error "Swap partiion: $swap_dev does not exist!" |
95 | e9568fe9 | Nikos Skalkotos | exit 1; |
96 | e9568fe9 | Nikos Skalkotos | fi |
97 | e9568fe9 | Nikos Skalkotos | |
98 | 640e7e45 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then |
99 | bb78ba49 | Nikos Skalkotos | ${OS_FAMILY}_mkfs_disk0 |
100 | 3903b7f1 | Lance Albertson | root_uuid="$($VOL_ID $root_dev)" |
101 | b8a540bb | Lance Albertson | [ -n "$boot_dev" ] && sleep 1 && boot_uuid="$($VOL_ID $boot_dev)" |
102 | b8a540bb | Lance Albertson | [ -n "$swap_dev" ] && sleep 1 && swap_uuid="$($VOL_ID $swap_dev)" |
103 | b05b1ab6 | Lance Albertson | fi |
104 | fcce5224 | Lance Albertson | |
105 | 916b6dd1 | Lance Albertson | TARGET=`mktemp -d` || exit 1 |
106 | 916b6dd1 | Lance Albertson | CLEANUP+=("rmdir $TARGET") |
107 | fcce5224 | Lance Albertson | |
108 | a33d2ab2 | Nikos Skalkotos | if [ "${IMAGE_TYPE}" = "ntfsclone" ] ; then |
109 | a33d2ab2 | Nikos Skalkotos | ntfsclone --restore-image --overwrite $root_dev $IMAGE_FILE |
110 | a33d2ab2 | Nikos Skalkotos | fi |
111 | a33d2ab2 | Nikos Skalkotos | |
112 | a1d43218 | Lance Albertson | # mount filesystems |
113 | 77449e7c | Lance Albertson | mount_disk0 $TARGET |
114 | b05b1ab6 | Lance Albertson | |
115 | b05b1ab6 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" ] ; then |
116 | b05b1ab6 | Lance Albertson | # unpack image |
117 | 916b6dd1 | Lance Albertson | tar pzxf $IMAGE_FILE -C $TARGET |
118 | 640e7e45 | Lance Albertson | elif [ "${IMAGE_TYPE}" = "dump" ] ; then |
119 | 0d9031a6 | Lance Albertson | root_dump="${IMAGE_FILE}" |
120 | 78422bb3 | Lance Albertson | ( cd ${TARGET}; restore -r -y -f ${root_dump} > /dev/null ) |
121 | 77449e7c | Lance Albertson | |
122 | 77449e7c | Lance Albertson | if [ -n "${boot_dev}" ] ; then |
123 | 77449e7c | Lance Albertson | boot_dump="${IMAGE_FILE/root.dump/boot.dump}" |
124 | 77449e7c | Lance Albertson | if [ ! -f "$boot_dump" ] ; then |
125 | 77449e7c | Lance Albertson | log_error "Can't find image file: $boot_dump" |
126 | 77449e7c | Lance Albertson | exit 1 |
127 | 77449e7c | Lance Albertson | fi |
128 | 78422bb3 | Lance Albertson | ( cd ${TARGET}/boot; restore -r -y -f ${boot_dump} > /dev/null ) |
129 | 77449e7c | Lance Albertson | fi |
130 | b05b1ab6 | Lance Albertson | fi |
131 | e5ec11e4 | Lance Albertson | |
132 | 3903b7f1 | Lance Albertson | if [ "${IMAGE_TYPE}" = "tarball" -o "${IMAGE_TYPE}" = "dump" ] ; then |
133 | bb78ba49 | Nikos Skalkotos | ${OS_FAMILY}_setup_fstab $TARGET |
134 | 3903b7f1 | Lance Albertson | fi |
135 | 3903b7f1 | Lance Albertson | |
136 | 9f4b2c31 | Lance Albertson | if [ "${INSTANCE_HV_serial_console}" = "True" ] ; then |
137 | bb78ba49 | Nikos Skalkotos | ${OS_FAMILY}_setup_console $TARGET |
138 | 9f4b2c31 | Lance Albertson | fi |
139 | 9f4b2c31 | Lance Albertson | |
140 | 86ddc018 | Nikos Skalkotos | ${OS_FAMILY}_epilogue $TARGET |
141 | 47e547ca | Nikos Skalkotos | |
142 | fcce5224 | Lance Albertson | RUN_PARTS=`which run-parts` |
143 | fcce5224 | Lance Albertson | |
144 | bb78ba49 | Nikos Skalkotos | if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "${CUSTOMIZE_DIR}/$OS_FAMILY" ]; then |
145 | 916b6dd1 | Lance Albertson | TARGET=$TARGET |
146 | fcce5224 | Lance Albertson | BLOCKDEV=$blockdev |
147 | f7959feb | Lance Albertson | ROOT_DEV=$root_dev |
148 | c29e092d | Lance Albertson | BOOT_DEV=$boot_dev |
149 | ab462591 | Constantinos Venetsanopoulos | IMG_PASSWD=$IMG_PASSWD |
150 | 8d77389f | Nikos Skalkotos | HOSTNAME=$instance |
151 | 8d77389f | Nikos Skalkotos | export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV IMAGE_TYPE IMG_PASSWD HOSTNAME |
152 | bb78ba49 | Nikos Skalkotos | $RUN_PARTS $CUSTOMIZE_DIR/$OS_FAMILY |
153 | fcce5224 | Lance Albertson | fi |
154 | 79224631 | Lance Albertson | fi |
155 | 79224631 | Lance Albertson | |
156 | 79224631 | Lance Albertson | # execute cleanups |
157 | 79224631 | Lance Albertson | cleanup |
158 | 79224631 | Lance Albertson | trap - EXIT |
159 | 79224631 | Lance Albertson | |
160 | 79224631 | Lance Albertson | exit 0 |