-
Notifications
You must be signed in to change notification settings - Fork 0
/
create
executable file
·138 lines (112 loc) · 3.59 KB
/
create
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# Stolen from ganeti-instance-debootstrap-0.7
# Copyright (C) 2007, 2008, 2009 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
set -e
if [ "$DEBUG_LEVEL" != "0" ] ; then
set -x
env
fi
. common.sh
. opensuse.sh
CLEANUP=( )
trap cleanup EXIT
if [ "$GENERATE_CACHE" = "yes" -a ! -d "$CACHE_DIR" ]; then
$MAKEDIR_P "$CACHE_DIR"
fi
CACHE_FILE="$CACHE_DIR/cache-opensuse-${VERSION}.tar"
# If the target device is not a real block device we'll first losetup it.
# This is needed for file disks.
if [ ! -b $blockdev ]; then
ORIGINAL_BLOCKDEV=$blockdev
blockdev=$($LOSETUP -sf $blockdev)
CLEANUP+=("$LOSETUP -d $blockdev")
fi
if [ "$PARTITION_STYLE" = "none" ]; then
filesystem_dev=$blockdev
elif [ "$PARTITION_STYLE" = "msdos" ]; then
# Create one big partition, and make it bootable
format_disk0 $blockdev
filesystem_dev=$(map_disk0 $blockdev)
CLEANUP+=("unmap_disk0 $blockdev")
else
echo "Unknown partition style $PARTITION_STYLE"
exit 1
fi
mke2fs -Fjq $filesystem_dev
root_uuid=$($VOL_ID -u $filesystem_dev )
if [ -n "$swapdev" ]; then
mkswap $swapdev
swap_uuid=$($VOL_ID -u $swapdev || true )
fi
TMPDIR=`mktemp -d` || exit 1
CLEANUP+=("rmdir $TMPDIR")
mount $filesystem_dev $TMPDIR
CLEANUP+=("umount $TMPDIR")
# Remove the cache file if it's old and writable by the owner (the
# default due to the standard umask)
if [ "$CLEAN_CACHE" -a -d "$CACHE_DIR" ]; then
find "$CACHE_DIR" -name 'cache-*.tar' -type f \
-daystart -mtime "+${CLEAN_CACHE}" -print0 | \
xargs -r0 rm -f
fi
if [ -f "$CACHE_FILE" ]; then
tar xf "$CACHE_FILE" -C $TMPDIR
else
if [ "$PROXY" ]; then
export http_proxy="$PROXY"
fi
opensuse_bootstrap $TMPDIR
if [ "$GENERATE_CACHE" = "yes" ]; then
TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"`
tar cf "$TMP_CACHE" -C $TMPDIR .
mv -f "$TMP_CACHE" "$CACHE_FILE"
fi
fi
cp -p /etc/hosts $TMPDIR/etc/hosts
cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
echo $instance > $TMPDIR/etc/hostname
echo $instance > $TMPDIR/etc/mailname
cat > $TMPDIR/etc/fstab <<EOF
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=$root_uuid / ext3 defaults 0 1
proc /proc proc defaults 0 0
EOF
[ -n "$swapdev" -a -n "$swap_uuid" ] && cat >> $TMPDIR/etc/fstab <<EOF
UUID=$swap_uuid swap swap defaults 0 0
EOF
if [ -e $TMPDIR/etc/inittab ]; then
cat $TMPDIR/etc/inittab | sed -re 's/\stty1$/ console/' \
> $TMPDIR/etc/inittab.new
mv $TMPDIR/etc/inittab.new $TMPDIR/etc/inittab
elif [ -e $TMPDIR/etc/event.d/tty1 ]; then
cat $TMPDIR/etc/event.d/tty1 | sed -re 's/tty1/console/' \
> $TMPDIR/etc/event.d/console
rm $TMPDIR/etc/event.d/tty1
fi
if [ -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
for script in `ls $CUSTOMIZE_DIR | sort`; do
chroot $TMPDIR $script
done
fi
# execute cleanups
set +e
cleanup
trap - EXIT
exit 0