root / common.sh.in @ 9f4b2c31
History | View | Annotate | Download (11.7 kB)
1 | 79224631 | Lance Albertson | # |
---|---|---|---|
2 | 79224631 | Lance Albertson | |
3 | 79224631 | Lance Albertson | # Copyright (C) 2007, 2008, 2009 Google Inc. |
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 | 8d0132dc | Lance Albertson | AWK="@AWK@" |
21 | 8d0132dc | Lance Albertson | DUMP="@DUMP@" |
22 | 8d0132dc | Lance Albertson | LOSETUP="@LOSETUP@" |
23 | 8d0132dc | Lance Albertson | KPARTX="@KPARTX@" |
24 | 8d0132dc | Lance Albertson | SFDISK="@SFDISK@" |
25 | ab712029 | Lance Albertson | QEMU_IMG="@QEMU_IMG@" |
26 | 8d0132dc | Lance Albertson | MKDIR_P="@MKDIR_P@" |
27 | 8d0132dc | Lance Albertson | |
28 | 79224631 | Lance Albertson | CLEANUP=( ) |
29 | 79224631 | Lance Albertson | |
30 | 79224631 | Lance Albertson | log_error() { |
31 | 79224631 | Lance Albertson | echo "$@" >&2 |
32 | 79224631 | Lance Albertson | } |
33 | 79224631 | Lance Albertson | |
34 | e7a2d1ad | Lance Albertson | debug() { |
35 | e7a2d1ad | Lance Albertson | [ "$IMAGE_DEBUG" == "1" ] && $@ || : |
36 | e7a2d1ad | Lance Albertson | } |
37 | e7a2d1ad | Lance Albertson | |
38 | 79224631 | Lance Albertson | get_api5_arguments() { |
39 | 79224631 | Lance Albertson | GETOPT_RESULT=$* |
40 | 79224631 | Lance Albertson | # Note the quotes around `$TEMP': they are essential! |
41 | 79224631 | Lance Albertson | eval set -- "$GETOPT_RESULT" |
42 | 79224631 | Lance Albertson | while true; do |
43 | 79224631 | Lance Albertson | case "$1" in |
44 | 79224631 | Lance Albertson | -i|-n) instance=$2; shift 2;; |
45 | 79224631 | Lance Albertson | |
46 | 79224631 | Lance Albertson | -o) old_name=$2; shift 2;; |
47 | 79224631 | Lance Albertson | |
48 | 79224631 | Lance Albertson | -b) blockdev=$2; shift 2;; |
49 | 79224631 | Lance Albertson | |
50 | 79224631 | Lance Albertson | -s) swapdev=$2; shift 2;; |
51 | 79224631 | Lance Albertson | |
52 | 79224631 | Lance Albertson | --) shift; break;; |
53 | 79224631 | Lance Albertson | |
54 | 79224631 | Lance Albertson | *) log_error "Internal error!" >&2; exit 1;; |
55 | 79224631 | Lance Albertson | esac |
56 | 79224631 | Lance Albertson | done |
57 | 79224631 | Lance Albertson | if [ -z "$instance" -o -z "$blockdev" ]; then |
58 | 79224631 | Lance Albertson | log_error "Missing OS API Argument (-i, -n, or -b)" |
59 | 79224631 | Lance Albertson | exit 1 |
60 | 79224631 | Lance Albertson | fi |
61 | 79224631 | Lance Albertson | if [ "$SCRIPT_NAME" != "export" -a -z "$swapdev" ]; then |
62 | 79224631 | Lance Albertson | log_error "Missing OS API Argument -s (swapdev)" |
63 | 79224631 | Lance Albertson | exit 1 |
64 | 79224631 | Lance Albertson | fi |
65 | 79224631 | Lance Albertson | if [ "$SCRIPT_NAME" = "rename" -a -z "$old_name" ]; then |
66 | 79224631 | Lance Albertson | log_error "Missing OS API Argument -o (old_name)" |
67 | 79224631 | Lance Albertson | exit 1 |
68 | 79224631 | Lance Albertson | fi |
69 | 79224631 | Lance Albertson | } |
70 | 79224631 | Lance Albertson | |
71 | 79224631 | Lance Albertson | get_api10_arguments() { |
72 | 79224631 | Lance Albertson | if [ -z "$INSTANCE_NAME" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then |
73 | 79224631 | Lance Albertson | log_error "Missing OS API Variable:" |
74 | 79224631 | Lance Albertson | log_error "(INSTANCE_NAME HYPERVISOR or DISK_COUNT)" |
75 | 79224631 | Lance Albertson | exit 1 |
76 | 79224631 | Lance Albertson | fi |
77 | 79224631 | Lance Albertson | instance=$INSTANCE_NAME |
78 | 79224631 | Lance Albertson | if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then |
79 | 79224631 | Lance Albertson | log_error "At least one disk is needed" |
80 | 79224631 | Lance Albertson | exit 1 |
81 | 79224631 | Lance Albertson | fi |
82 | 79224631 | Lance Albertson | if [ "$SCRIPT_NAME" = "export" ]; then |
83 | 79224631 | Lance Albertson | if [ -z "$EXPORT_DEVICE" ]; then |
84 | 79224631 | Lance Albertson | log_error "Missing OS API Variable EXPORT_DEVICE" |
85 | 79224631 | Lance Albertson | fi |
86 | 79224631 | Lance Albertson | blockdev=$EXPORT_DEVICE |
87 | 79224631 | Lance Albertson | elif [ "$SCRIPT_NAME" = "import" ]; then |
88 | 79224631 | Lance Albertson | if [ -z "$IMPORT_DEVICE" ]; then |
89 | 79224631 | Lance Albertson | log_error "Missing OS API Variable IMPORT_DEVICE" |
90 | 79224631 | Lance Albertson | fi |
91 | 79224631 | Lance Albertson | blockdev=$IMPORT_DEVICE |
92 | 79224631 | Lance Albertson | else |
93 | 79224631 | Lance Albertson | blockdev=$DISK_0_PATH |
94 | 79224631 | Lance Albertson | fi |
95 | 79224631 | Lance Albertson | if [ "$SCRIPT_NAME" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then |
96 | 79224631 | Lance Albertson | log_error "Missing OS API Variable OLD_INSTANCE_NAME" |
97 | 79224631 | Lance Albertson | fi |
98 | 79224631 | Lance Albertson | old_name=$OLD_INSTANCE_NAME |
99 | 79224631 | Lance Albertson | } |
100 | 79224631 | Lance Albertson | |
101 | f6f223b8 | Lance Albertson | get_os_type() { |
102 | abade4ea | Lance Albertson | target=$1 |
103 | abade4ea | Lance Albertson | if [ -z "${target}" ] ; then |
104 | abade4ea | Lance Albertson | log_error "target is not set in get_os_type" |
105 | abade4ea | Lance Albertson | exit 1 |
106 | abade4ea | Lance Albertson | fi |
107 | abade4ea | Lance Albertson | if [ -e ${target}/etc/redhat-release ] ; then |
108 | f6f223b8 | Lance Albertson | OS_TYPE="redhat" |
109 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/debian_version ] ; then |
110 | f6f223b8 | Lance Albertson | OS_TYPE="debian" |
111 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/gentoo-release ] ; then |
112 | f6f223b8 | Lance Albertson | OS_TYPE="gentoo" |
113 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/SuSE-release ] ; then |
114 | f6f223b8 | Lance Albertson | OS_TYPE="suse" |
115 | f6f223b8 | Lance Albertson | fi |
116 | f6f223b8 | Lance Albertson | } |
117 | f6f223b8 | Lance Albertson | |
118 | abade4ea | Lance Albertson | get_os() { |
119 | abade4ea | Lance Albertson | target=$1 |
120 | abade4ea | Lance Albertson | if [ -z "${target}" ] ; then |
121 | abade4ea | Lance Albertson | log_error "target is not set in get_os" |
122 | abade4ea | Lance Albertson | exit 1 |
123 | abade4ea | Lance Albertson | fi |
124 | abade4ea | Lance Albertson | lsb="$(which lsb_release)" |
125 | abade4ea | Lance Albertson | if [ -n "$lsb" ] ; then |
126 | abade4ea | Lance Albertson | OPERATING_SYSTEM="$(${lsb} -i -s | tr "[:upper:]" "[:lower:]")" |
127 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/debian_version ] ; then |
128 | abade4ea | Lance Albertson | OPERATING_SYSTEM="debian" |
129 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/gentoo-release ] ; then |
130 | abade4ea | Lance Albertson | OPERATING_SYSTEM="gentoo" |
131 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/fedora-release ] ; then |
132 | abade4ea | Lance Albertson | OPERATING_SYSTEM="fedora" |
133 | abade4ea | Lance Albertson | elif [ -e ${$target}/etc/redhat-release ] ; then |
134 | abade4ea | Lance Albertson | if [ -n "$(grep -i centos ${target}/etc/redhat-release)" ] ; then |
135 | abade4ea | Lance Albertson | OPERATING_SYSTEM="centos" |
136 | abade4ea | Lance Albertson | else |
137 | abade4ea | Lance Albertson | OPERATING_SYSTEM="redhat" |
138 | abade4ea | Lance Albertson | fi |
139 | abade4ea | Lance Albertson | fi |
140 | abade4ea | Lance Albertson | } |
141 | abade4ea | Lance Albertson | |
142 | abade4ea | Lance Albertson | get_os_release() { |
143 | abade4ea | Lance Albertson | target=$1 |
144 | abade4ea | Lance Albertson | if [ -z "${target}" ] ; then |
145 | abade4ea | Lance Albertson | log_error "target is not set in get_os_release" |
146 | abade4ea | Lance Albertson | exit 1 |
147 | abade4ea | Lance Albertson | fi |
148 | abade4ea | Lance Albertson | lsb="$(which lsb_release)" |
149 | abade4ea | Lance Albertson | if [ -n "$lsb" ] ; then |
150 | abade4ea | Lance Albertson | OS_RELEASE="$(${lsb} -r -s | tr "[:upper:]" "[:lower:]")" |
151 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/debian_version ] ; then |
152 | abade4ea | Lance Albertson | OS_RELEASE="$(cat ${target}/etc/debian_version)" |
153 | abade4ea | Lance Albertson | elif [ -e ${target}/etc/fedora-release ] ; then |
154 | abade4ea | Lance Albertson | OS_RELEASE="$(cat ${target}/etc/fedora-release | awk '{print $3}')" |
155 | abade4ea | Lance Albertson | elif [ -e ${$target}/etc/redhat-release ] ; then |
156 | abade4ea | Lance Albertson | OS_RELEASE="$(cat ${target}/etc/redhat-release | awk '{print $3}')" |
157 | abade4ea | Lance Albertson | fi |
158 | abade4ea | Lance Albertson | } |
159 | abade4ea | Lance Albertson | |
160 | 79224631 | Lance Albertson | format_disk0() { |
161 | 9a259787 | Lance Albertson | local sfdisk_cmd="$SFDISK -uM -H 255 -S 63 --quiet --Linux $1" |
162 | 77449e7c | Lance Albertson | if [ "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then |
163 | e21b8802 | Lance Albertson | # Create three partitions: |
164 | e21b8802 | Lance Albertson | # 1 - 100MB /boot, bootable |
165 | e21b8802 | Lance Albertson | # 2 - Size of Memory, swap |
166 | e21b8802 | Lance Albertson | # 3 - Rest |
167 | 77449e7c | Lance Albertson | $sfdisk_cmd <<EOF |
168 | 22b570d6 | Lance Albertson | ,100,L,* |
169 | 240140b7 | Lance Albertson | ,$INSTANCE_BE_memory,S |
170 | 22b570d6 | Lance Albertson | ,,L |
171 | 79224631 | Lance Albertson | EOF |
172 | 77449e7c | Lance Albertson | elif [ "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then |
173 | e21b8802 | Lance Albertson | # Create two partitions: |
174 | e21b8802 | Lance Albertson | # 1 - 100MB /boot, bootable |
175 | e21b8802 | Lance Albertson | # 2 - Rest |
176 | 77449e7c | Lance Albertson | $sfdisk_cmd <<EOF |
177 | e21b8802 | Lance Albertson | ,100,L,* |
178 | e21b8802 | Lance Albertson | ,,L |
179 | e21b8802 | Lance Albertson | EOF |
180 | 77449e7c | Lance Albertson | elif [ "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then |
181 | 77449e7c | Lance Albertson | # Create two partitions: |
182 | 77449e7c | Lance Albertson | # 1 - Size of Memory, swap |
183 | 77449e7c | Lance Albertson | # 2 - Rest |
184 | 77449e7c | Lance Albertson | $sfdisk_cmd <<EOF |
185 | 77449e7c | Lance Albertson | ,$INSTANCE_BE_memory,S |
186 | 77449e7c | Lance Albertson | ,,L |
187 | 77449e7c | Lance Albertson | EOF |
188 | 77449e7c | Lance Albertson | elif [ "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then |
189 | 77449e7c | Lance Albertson | # Create two partitions: |
190 | 77449e7c | Lance Albertson | # 1 - Whole |
191 | 77449e7c | Lance Albertson | $sfdisk_cmd <<EOF |
192 | 77449e7c | Lance Albertson | ,,L |
193 | 77449e7c | Lance Albertson | EOF |
194 | e21b8802 | Lance Albertson | fi |
195 | 79224631 | Lance Albertson | } |
196 | 79224631 | Lance Albertson | |
197 | cc927a76 | Lance Albertson | mkfs_disk0() { |
198 | cc927a76 | Lance Albertson | # Format / |
199 | 77449e7c | Lance Albertson | mkfs.ext3 -Fq -L / $root_dev |
200 | 77449e7c | Lance Albertson | # Format /boot |
201 | 77449e7c | Lance Albertson | if [ -n "${boot_dev}" ] ; then |
202 | 77449e7c | Lance Albertson | mkfs.ext3 -Fq -L /boot $boot_dev |
203 | 77449e7c | Lance Albertson | fi |
204 | 77449e7c | Lance Albertson | # Format swap |
205 | 77449e7c | Lance Albertson | if [ -n "${swap_dev}" ] ; then |
206 | cc927a76 | Lance Albertson | # Format swap |
207 | 70054ca5 | Lance Albertson | mkswap -f $swap_dev |
208 | cc927a76 | Lance Albertson | fi |
209 | cc927a76 | Lance Albertson | } |
210 | cc927a76 | Lance Albertson | |
211 | b05b1ab6 | Lance Albertson | mount_disk0() { |
212 | 77449e7c | Lance Albertson | local target=$1 |
213 | 3173a4bc | Lance Albertson | mount $root_dev $target |
214 | 3173a4bc | Lance Albertson | CLEANUP+=("umount $target") |
215 | 77449e7c | Lance Albertson | if [ -n "${boot_dev}" ] ; then |
216 | 77449e7c | Lance Albertson | $MKDIR_P $target/boot |
217 | 77449e7c | Lance Albertson | mount $boot_dev $target/boot |
218 | 77449e7c | Lance Albertson | CLEANUP+=("umount $target/boot") |
219 | 77449e7c | Lance Albertson | fi |
220 | b05b1ab6 | Lance Albertson | } |
221 | b05b1ab6 | Lance Albertson | |
222 | 79224631 | Lance Albertson | map_disk0() { |
223 | 77449e7c | Lance Albertson | blockdev="$1" |
224 | 77449e7c | Lance Albertson | filesystem_dev_base=`$KPARTX -l -p- $blockdev | \ |
225 | 77449e7c | Lance Albertson | grep -m 1 -- "-1.*$blockdev" | \ |
226 | 77449e7c | Lance Albertson | $AWK '{print $1}'` |
227 | 77449e7c | Lance Albertson | if [ -z "$filesystem_dev_base" ]; then |
228 | 77449e7c | Lance Albertson | log_error "Cannot interpret kpartx output and get partition mapping" |
229 | 77449e7c | Lance Albertson | exit 1 |
230 | 77449e7c | Lance Albertson | fi |
231 | 77449e7c | Lance Albertson | $KPARTX -a -p- $blockdev > /dev/null |
232 | 77449e7c | Lance Albertson | filesystem_dev="/dev/mapper/${filesystem_dev_base/%-1/}" |
233 | 77449e7c | Lance Albertson | if [ ! -b "/dev/mapper/$filesystem_dev_base" ]; then |
234 | 77449e7c | Lance Albertson | log_error "Can't find kpartx mapped partition: /dev/mapper/$filesystem_dev_base" |
235 | 77449e7c | Lance Albertson | exit 1 |
236 | 77449e7c | Lance Albertson | fi |
237 | 494927a8 | Lance Albertson | echo "$filesystem_dev" |
238 | 494927a8 | Lance Albertson | } |
239 | 494927a8 | Lance Albertson | |
240 | 494927a8 | Lance Albertson | map_partition() { |
241 | 494927a8 | Lance Albertson | filesystem_dev="$1" |
242 | 494927a8 | Lance Albertson | partition="$2" |
243 | 77449e7c | Lance Albertson | if [ "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then |
244 | 494927a8 | Lance Albertson | boot_dev="${filesystem_dev}-1" |
245 | 494927a8 | Lance Albertson | swap_dev="${filesystem_dev}-2" |
246 | 494927a8 | Lance Albertson | root_dev="${filesystem_dev}-3" |
247 | 77449e7c | Lance Albertson | elif [ "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then |
248 | 494927a8 | Lance Albertson | boot_dev="${filesystem_dev}-1" |
249 | 494927a8 | Lance Albertson | root_dev="${filesystem_dev}-2" |
250 | 77449e7c | Lance Albertson | elif [ "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then |
251 | 494927a8 | Lance Albertson | swap_dev="${filesystem_dev}-1" |
252 | 494927a8 | Lance Albertson | root_dev="${filesystem_dev}-2" |
253 | 77449e7c | Lance Albertson | elif [ "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then |
254 | 494927a8 | Lance Albertson | root_dev="${filesystem_dev}-1" |
255 | 77449e7c | Lance Albertson | fi |
256 | 494927a8 | Lance Albertson | echo "$(eval "echo \${$(echo ${partition}_dev)"})" |
257 | 79224631 | Lance Albertson | } |
258 | 79224631 | Lance Albertson | |
259 | 79224631 | Lance Albertson | unmap_disk0() { |
260 | 8d0132dc | Lance Albertson | $KPARTX -d -p- $1 |
261 | 79224631 | Lance Albertson | } |
262 | 79224631 | Lance Albertson | |
263 | 3903b7f1 | Lance Albertson | setup_fstab() { |
264 | 3903b7f1 | Lance Albertson | local target=$1 |
265 | 3903b7f1 | Lance Albertson | get_os_type |
266 | 3903b7f1 | Lance Albertson | cat > $target/etc/fstab <<EOF |
267 | 3903b7f1 | Lance Albertson | # /etc/fstab: static file system information. |
268 | 3903b7f1 | Lance Albertson | # |
269 | 3903b7f1 | Lance Albertson | # <file system> <mount point> <type> <options> <dump> <pass> |
270 | 3903b7f1 | Lance Albertson | UUID=$root_uuid / ext3 defaults 0 1 |
271 | 3903b7f1 | Lance Albertson | proc /proc proc defaults 0 0 |
272 | 3903b7f1 | Lance Albertson | EOF |
273 | 3903b7f1 | Lance Albertson | |
274 | 3903b7f1 | Lance Albertson | [ -n "$boot_dev" -a -n "$boot_uuid" ] && cat >> $target/etc/fstab <<EOF |
275 | 3903b7f1 | Lance Albertson | UUID=$boot_uuid /boot ext3 defaults 1 2 |
276 | 3903b7f1 | Lance Albertson | EOF |
277 | 3903b7f1 | Lance Albertson | |
278 | 3903b7f1 | Lance Albertson | [ -n "$swap_dev" -a -n "$swap_uuid" ] && cat >> $target/etc/fstab <<EOF |
279 | 3903b7f1 | Lance Albertson | UUID=$swap_uuid swap swap defaults 0 0 |
280 | 3903b7f1 | Lance Albertson | EOF |
281 | 3903b7f1 | Lance Albertson | |
282 | 3903b7f1 | Lance Albertson | # OS Specific fstabs |
283 | 3903b7f1 | Lance Albertson | [ "$OS_TYPE" = "redhat" ] && cat >> $target/etc/fstab <<EOF |
284 | 3903b7f1 | Lance Albertson | tmpfs /dev/shm tmpfs defaults 0 0 |
285 | 3903b7f1 | Lance Albertson | devpts /dev/pts devpts gid=5,mode=620 0 0 |
286 | 3903b7f1 | Lance Albertson | sysfs /sys sysfs defaults 0 0 |
287 | 3903b7f1 | Lance Albertson | EOF |
288 | 3903b7f1 | Lance Albertson | |
289 | 3903b7f1 | Lance Albertson | [ "$OS_TYPE" = "gentoo" ] && cat >> $target/etc/fstab <<EOF |
290 | 3903b7f1 | Lance Albertson | shm /dev/shm tmpfs nodev,nosuid,noexec 0 0 |
291 | 3903b7f1 | Lance Albertson | EOF |
292 | 3903b7f1 | Lance Albertson | } |
293 | 3903b7f1 | Lance Albertson | |
294 | 9f4b2c31 | Lance Albertson | setup_console() { |
295 | 9f4b2c31 | Lance Albertson | local target=$1 |
296 | 9f4b2c31 | Lance Albertson | if [ -z "$target" ] ; then |
297 | 9f4b2c31 | Lance Albertson | log_error "target not set for setup_console" |
298 | 9f4b2c31 | Lance Albertson | exit 1 |
299 | 9f4b2c31 | Lance Albertson | fi |
300 | 9f4b2c31 | Lance Albertson | # Upstart is on this system, so do this instead |
301 | 9f4b2c31 | Lance Albertson | if [ -e ${target}/etc/event.d/tty1 ] ; then |
302 | 9f4b2c31 | Lance Albertson | cat ${target}/etc/event.d/tty1 | sed -re 's/tty1/ttyS0/' \ |
303 | 9f4b2c31 | Lance Albertson | > ${target}/etc/event.d/ttyS0 |
304 | 9f4b2c31 | Lance Albertson | return |
305 | 9f4b2c31 | Lance Albertson | fi |
306 | 9f4b2c31 | Lance Albertson | get_os $target |
307 | 9f4b2c31 | Lance Albertson | case $OPERATING_SYSTEM in |
308 | 9f4b2c31 | Lance Albertson | gentoo) |
309 | 9f4b2c31 | Lance Albertson | sed -i -e 's/.*ttyS0.*/s0:12345:respawn:\/sbin\/agetty 115200 ttyS0 vt100/' \ |
310 | 9f4b2c31 | Lance Albertson | ${target}/etc/inittab |
311 | 9f4b2c31 | Lance Albertson | ;; |
312 | 9f4b2c31 | Lance Albertson | centos) |
313 | 9f4b2c31 | Lance Albertson | echo "s0:12345:respawn:/sbin/mingetty 115200 ttyS0 vt100" >> \ |
314 | 9f4b2c31 | Lance Albertson | ${target}/etc/inittab |
315 | 9f4b2c31 | Lance Albertson | ;; |
316 | 9f4b2c31 | Lance Albertson | debian|ubuntu) |
317 | 9f4b2c31 | Lance Albertson | sed -i -e 's/.*T0.*/T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100' \ |
318 | 9f4b2c31 | Lance Albertson | ${target}/etc/inittab |
319 | 9f4b2c31 | Lance Albertson | ;; |
320 | 9f4b2c31 | Lance Albertson | *) |
321 | 9f4b2c31 | Lance Albertson | echo "No support for your OS in instance-image, skipping..." |
322 | 9f4b2c31 | Lance Albertson | ;; |
323 | 9f4b2c31 | Lance Albertson | esac |
324 | 9f4b2c31 | Lance Albertson | } |
325 | 9f4b2c31 | Lance Albertson | |
326 | 79224631 | Lance Albertson | cleanup() { |
327 | 79224631 | Lance Albertson | if [ ${#CLEANUP[*]} -gt 0 ]; then |
328 | 79224631 | Lance Albertson | LAST_ELEMENT=$((${#CLEANUP[*]}-1)) |
329 | 79224631 | Lance Albertson | REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0) |
330 | 79224631 | Lance Albertson | for i in $REVERSE_INDEXES; do |
331 | 79224631 | Lance Albertson | ${CLEANUP[$i]} |
332 | 79224631 | Lance Albertson | done |
333 | 79224631 | Lance Albertson | fi |
334 | 79224631 | Lance Albertson | } |
335 | 79224631 | Lance Albertson | |
336 | 79224631 | Lance Albertson | trap cleanup EXIT |
337 | 79224631 | Lance Albertson | |
338 | c4661256 | Lance Albertson | DEFAULT_FILE="@DEFAULTS_DIR@/ganeti-instance-image" |
339 | 79224631 | Lance Albertson | if [ -f "$DEFAULT_FILE" ]; then |
340 | 79224631 | Lance Albertson | . "$DEFAULT_FILE" |
341 | 79224631 | Lance Albertson | fi |
342 | 79224631 | Lance Albertson | |
343 | 79224631 | Lance Albertson | # note: we don't set a default mirror since debian and ubuntu have |
344 | 79224631 | Lance Albertson | # different defaults, and it's better to use the default |
345 | 79224631 | Lance Albertson | |
346 | 79224631 | Lance Albertson | # only if the user want to specify a mirror in the defaults file we |
347 | 79224631 | Lance Albertson | # will use it, this declaration is to make sure the variable is set |
348 | fcce5224 | Lance Albertson | : ${CDINSTALL:="yes"} |
349 | e21b8802 | Lance Albertson | : ${SWAP:="yes"} |
350 | 134c11c3 | Lance Albertson | : ${IMAGE_NAME:=""} |
351 | b05b1ab6 | Lance Albertson | : ${IMAGE_TYPE:="qemu"} |
352 | 79224631 | Lance Albertson | : ${ARCH:=""} |
353 | f5aa7725 | Lance Albertson | : ${CUSTOMIZE_DIR:="@sysconfdir@/ganeti/instance-image.d"} |
354 | f5aa7725 | Lance Albertson | : ${VARIANTS_DIR:="@sysconfdir@/ganeti/instance-image/variants"} |
355 | 2e0988ec | Lance Albertson | : ${IMAGE_DIR:="@localstatedir@/cache/ganeti-instance-image"} |
356 | 611fa6b0 | Lance Albertson | : ${IMAGE_DEBUG:="0"} |
357 | f7959feb | Lance Albertson | |
358 | 79224631 | Lance Albertson | SCRIPT_NAME=$(basename $0) |
359 | 77449e7c | Lance Albertson | KERNEL_PATH="$INSTANCE_HV_kernel_path" |
360 | 79224631 | Lance Albertson | |
361 | 103d261e | Lance Albertson | if [ -f /sbin/blkid -a -x /sbin/blkid ]; then |
362 | 103d261e | Lance Albertson | VOL_ID="/sbin/blkid -o value -s UUID" |
363 | 103d261e | Lance Albertson | VOL_TYPE="/sbin/blkid -o value -s TYPE" |
364 | 103d261e | Lance Albertson | else |
365 | 103d261e | Lance Albertson | for dir in /lib/udev /sbin; do |
366 | 103d261e | Lance Albertson | if [ -f $dir/vol_id -a -x $dir/vol_id ]; then |
367 | 103d261e | Lance Albertson | VOL_ID="$dir/vol_id -u" |
368 | 103d261e | Lance Albertson | VOL_TYPE="$dir/vol_id -t" |
369 | 103d261e | Lance Albertson | fi |
370 | 103d261e | Lance Albertson | done |
371 | 103d261e | Lance Albertson | fi |
372 | 103d261e | Lance Albertson | |
373 | 103d261e | Lance Albertson | if [ -z "$VOL_ID" ]; then |
374 | 103d261e | Lance Albertson | log_error "vol_id or blkid not found, please install udev or util-linux" |
375 | 103d261e | Lance Albertson | exit 1 |
376 | 103d261e | Lance Albertson | fi |
377 | 103d261e | Lance Albertson | |
378 | 103d261e | Lance Albertson | |
379 | 79224631 | Lance Albertson | if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then |
380 | 79224631 | Lance Albertson | OS_API_VERSION=5 |
381 | 79224631 | Lance Albertson | GETOPT_RESULT=`getopt -o o:n:i:b:s: -n '$0' -- "$@"` |
382 | 79224631 | Lance Albertson | if [ $? != 0 ] ; then log_error "Terminating..."; exit 1 ; fi |
383 | 79224631 | Lance Albertson | get_api5_arguments $GETOPT_RESULT |
384 | 79224631 | Lance Albertson | elif [ "$OS_API_VERSION" = "10" -o "$OS_API_VERSION" = "15" ]; then |
385 | 79224631 | Lance Albertson | get_api10_arguments |
386 | 79224631 | Lance Albertson | else |
387 | 79224631 | Lance Albertson | log_error "Unknown OS API VERSION $OS_API_VERSION" |
388 | 79224631 | Lance Albertson | exit 1 |
389 | 79224631 | Lance Albertson | fi |
390 | 79224631 | Lance Albertson | |
391 | 79224631 | Lance Albertson | if [ -n "$OS_VARIANT" ]; then |
392 | 79224631 | Lance Albertson | if [ ! -d "$VARIANTS_DIR" ]; then |
393 | 79224631 | Lance Albertson | log_error "OS Variants directory $VARIANTS_DIR doesn't exist" |
394 | 79224631 | Lance Albertson | exit 1 |
395 | 79224631 | Lance Albertson | fi |
396 | 79224631 | Lance Albertson | VARIANT_CONFIG="$VARIANTS_DIR/$OS_VARIANT.conf" |
397 | 79224631 | Lance Albertson | if [ -f "$VARIANT_CONFIG" ]; then |
398 | 79224631 | Lance Albertson | . "$VARIANT_CONFIG" |
399 | 79224631 | Lance Albertson | else |
400 | 79224631 | Lance Albertson | if grep -qxF "$OS_VARIANT" variants.list; then |
401 | f5aa7725 | Lance Albertson | log_error "ERROR: instance-image configuration error" |
402 | 79224631 | Lance Albertson | log_error " Published variant $OS_VARIANT is missing its config file" |
403 | 79224631 | Lance Albertson | log_error " Please create $VARIANT_CONFIG or unpublish the variant" |
404 | 79224631 | Lance Albertson | log_error " (by removing $OS_VARIANT from variants.list)" |
405 | 79224631 | Lance Albertson | else |
406 | 79224631 | Lance Albertson | log_error "Unofficial variant $OS_VARIANT is unsupported" |
407 | 79224631 | Lance Albertson | log_error "Most probably this is a user error, forcing a wrong name" |
408 | 79224631 | Lance Albertson | log_error "To support this variant please create file $VARIANT_CONFIG" |
409 | 79224631 | Lance Albertson | fi |
410 | 79224631 | Lance Albertson | exit 1 |
411 | 79224631 | Lance Albertson | fi |
412 | 79224631 | Lance Albertson | fi |