Revision 5dc61974 common.sh.in

b/common.sh.in
109 109
  IMG_PASSWD=$OSP_IMG_PASSWD
110 110
}
111 111

  
112
get_os_type() {
113
    target=$1
114
    if [ -z "${target}" ] ; then
115
        log_error "target is not set in get_os_type"
116
        exit 1
117
    fi
118
    if [ -e ${target}/etc/redhat-release ] ; then
119
        OS_TYPE="redhat"
120
    elif [ -e ${target}/etc/debian_version ] ; then
121
        OS_TYPE="debian"
122
    elif [ -e ${target}/etc/gentoo-release ] ; then
123
        OS_TYPE="gentoo"
124
    elif [ -e ${target}/etc/SuSE-release ] ; then
125
        OS_TYPE="suse"
126
    fi
127
}
128

  
129
get_os() {
130
    target=$1
131
    if [ -z "${target}" ] ; then
132
        log_error "target is not set in get_os"
133
        exit 1
134
    fi
135
    lsb="/usr/bin/lsb_release"
136
    if [ -e ${target}/$lsb ] ; then
137
        OPERATING_SYSTEM="$(chroot ${target} ${lsb} -i -s | tr "[:upper:]" "[:lower:]")"
138
    elif [ -e ${target}/etc/debian_version ] ; then
139
        OPERATING_SYSTEM="debian"
140
    elif [ -e ${target}/etc/gentoo-release ] ; then
141
        OPERATING_SYSTEM="gentoo"
142
    elif [ -e ${target}/etc/fedora-release ] ; then
143
        OPERATING_SYSTEM="fedora"
144
    elif [ -e ${target}/etc/redhat-release ] ; then
145
        if [ -n "$(grep -i centos ${target}/etc/redhat-release)" ] ; then
146
            OPERATING_SYSTEM="centos"
147
        else
148
            OPERATING_SYSTEM="redhat"
149
        fi
150
    fi
151
}
152

  
153
get_os_release() {
154
    target=$1
155
    if [ -z "${target}" ] ; then
156
        log_error "target is not set in get_os_release"
157
        exit 1
158
    fi
159
    lsb="/usr/bin/lsb_release"
160
    if [ -e ${target}/$lsb ] ; then
161
        OS_RELEASE="$(chroot ${target} ${lsb} -r -s | tr "[:upper:]" "[:lower:]")"
162
    elif [ -e ${target}/etc/debian_version ] ; then
163
        OS_RELEASE="$(cat ${target}/etc/debian_version)"
164
    elif [ -e ${target}/etc/fedora-release ] ; then
165
        OS_RELEASE="$(cat ${target}/etc/fedora-release | awk '{print $3}')"
166
    elif [ -e ${$target}/etc/redhat-release ] ; then
167
        OS_RELEASE="$(cat ${target}/etc/redhat-release | awk '{print $3}')"
168
    fi
169
}
170

  
171
format_disk0() {
172
    local sfdisk_cmd="$SFDISK -uM -H 255 -S 63 --quiet --Linux --DOS $1"
173
    if [  "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then
174
        # Create three partitions:
175
        # 1 - 100MB /boot, bootable
176
        # 2 - Size of Memory, swap
177
        # 3 - Rest
178
        $sfdisk_cmd > /dev/null <<EOF
179
,100,L,*
180
,${SWAP_SIZE},S
181
,,L
182
EOF
183
    elif [  "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then
184
        # Create two partitions:
185
        # 1 - 100MB /boot, bootable
186
        # 2 - Rest
187
        $sfdisk_cmd > /dev/null <<EOF
188
,100,L,*
189
,,L
190
EOF
191
    elif [  "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then
192
        # Create two partitions:
193
        # 1 - Size of Memory, swap
194
        # 2 - Rest
195
        $sfdisk_cmd > /dev/null <<EOF
196
,$SWAP_SIZE,S
197
,,L
198
EOF
199
    elif [  "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then
200
        # Create two partitions:
201
        # 1 - Whole
202
        $sfdisk_cmd > /dev/null <<EOF
203
,,L
204
EOF
205
    fi
206
}
207

  
208
mkfs_disk0() {
209
    local mkfs="mkfs.${FILESYSTEM}"
210
    # Format /
211
    $mkfs -Fq -L / $root_dev > /dev/null
212
    # Format /boot
213
    if [ -n "${boot_dev}" ] ; then
214
        $mkfs -Fq -L /boot $boot_dev > /dev/null
215
    fi
216
    # Format swap
217
    if [ -n "${swap_dev}" ] ; then
218
        # Format swap
219
        mkswap -f $swap_dev > /dev/null
220
    fi
221
    # During reinstalls, ext4 needs a little time after a mkfs so add it here
222
    # and also run a sync to be sure.
223
    sync
224
    sleep 2
225
}
226

  
227 112
mount_disk0() {
228 113
    local target=$1
229 114
    mount $root_dev $target
......
279 164
  $KPARTX -d -p- $1
280 165
}
281 166

  
282
setup_fstab() {
283
    local target=$1 fs=${FILESYSTEM}
284
    get_os_type $target
285
    cat > $target/etc/fstab <<EOF
286
# /etc/fstab: static file system information.
287
#
288
# <file system>   <mount point>   <type>  <options>       <dump>  <pass>
289
UUID=$root_uuid   /               $fs     defaults        0       1
290
proc              /proc           proc    defaults        0       0
291
EOF
292

  
293
if [ -n "$boot_dev" -a -n "$boot_uuid" ] ; then
294
    cat >> $target/etc/fstab <<EOF
295
UUID=$boot_uuid   /boot           $fs     defaults        1       2
296
EOF
297
fi
298

  
299
if [ -n "$swap_dev" -a -n "$swap_uuid" ] ; then
300
    cat >> $target/etc/fstab <<EOF
301
UUID=$swap_uuid   swap            swap    defaults        0       0
302
EOF
303
fi
304

  
305
# OS Specific fstabs
306
if [ "$OS_TYPE" = "redhat" ] ; then
307
    cat >> $target/etc/fstab <<EOF
308
tmpfs             /dev/shm        tmpfs   defaults        0       0
309
devpts            /dev/pts        devpts  gid=5,mode=620  0       0
310
sysfs             /sys            sysfs   defaults        0       0
311
EOF
312
fi
313

  
314
if [ "$OS_TYPE" = "gentoo" ] ; then
315
    cat >> $target/etc/fstab <<EOF
316
shm               /dev/shm        tmpfs   nodev,nosuid,noexec 0   0
317
EOF
318
fi
319
}
320

  
321
setup_console() {
322
    local target=$1
323
    if [ -z "$target" ] ; then
324
        log_error "target not set for setup_console"
325
        exit 1
326
    fi
327
    # Upstart is on this system, so do this instead
328
    if [ -e ${target}/etc/event.d/tty1 ] ; then
329
        cat ${target}/etc/event.d/tty1 | sed -re 's/tty1/ttyS0/' \
330
            > ${target}/etc/event.d/ttyS0
331
        return
332
    fi
333
    # upstart in karmic and newer
334
    if [ -e ${target}/etc/init/tty1.conf ] ; then
335
        cat ${target}/etc/init/tty1.conf | \
336
        sed -re 's/^exec.*/exec \/sbin\/getty -L 115200 ttyS0 vt102/' \
337
            > ${target}/etc/init/ttyS0.conf
338
        sed -ie 's/tty1/ttyS0/g' ${target}/etc/init/ttyS0.conf
339
        return
340
    fi
341
    get_os $target
342
    case $OPERATING_SYSTEM in
343
        gentoo)
344
            sed -i -e 's/.*ttyS0.*/s0:12345:respawn:\/sbin\/agetty 115200 ttyS0 vt100/' \
345
                ${target}/etc/inittab
346
            ;;
347
        centos)
348
            echo "s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100" >> \
349
                ${target}/etc/inittab
350
            ;;
351
        debian|ubuntu)
352
            sed -i -e 's/.*T0.*/T0:23:respawn:\/sbin\/getty -L ttyS0 115200 vt100/' \
353
                ${target}/etc/inittab
354
            ;;
355
        *)
356
            echo "No support for your OS in instance-image, skipping..."
357
            ;;
358
    esac
359
}
360

  
361
filesystem_check() {
362
    local target=$1
363
    if [ -z "$target" ] ; then
364
        log_error "target not set for filesystem_check"
365
        exit 1
366
    fi
367

  
368
    get_os $target
369

  
370
    if [ "${OPERATING_SYSTEM}" = "fedora" ]; then
371
        # we have to force a filesystem relabeling for SELinux after messing
372
        # around with the filesystem in fedora
373
        echo "Enforce an automatic relabeling in the initial boot process..."
374
        touch $target/.autorelabel
375
    fi
376
}
377

  
378 167
cleanup() {
379 168
  if [ ${#CLEANUP[*]} -gt 0 ]; then
380 169
    LAST_ELEMENT=$((${#CLEANUP[*]}-1))

Also available in: Unified diff