minix3/llvm/clientctl

114 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

2020-02-21 00:59:27 +05:30
#!/bin/bash
set -o errexit
mode=$1
shift || mode="no_action"
ROOT=../..
MYPWD=$( pwd )
IMAGE=$( readlink -f $ROOT/minix_x86.img )
DISK=$( readlink -f $ROOT/minix_x86.disk )
RC=$( readlink -f $ROOT/minix_x86.rc )
MKFS=$( readlink -f $ROOT/../obj.i386/tooldir*/bin/nbmkfs.mfs )
HYPER=${HYPER:-}
DISK_SIZE=${DISK_SIZE:-1024}
DISK_MNT=${DISK_MNT:-/media/minix-disk}
SERIALOUT=${SERIALOUT:-0}
function rc_create {
cat <<EOF
#!/bin/sh
set -o errexit
[ -d /ext ] || mkdir /ext
mount /dev/c0d1 /ext
if [ -f /ext/etc/rc ]; then
sh /ext/etc/rc
fi
EOF
}
function rc_ext_default_create {
cat <<EOF
#!/bin/sh
echo "/ext/etc/rc: /ext mounted correctly."
EOF
}
function disk_mount {
local mnt=$1
echo "* Mounting ${DISK} to $mnt..."
[ -d $mnt ] || sudo mkdir -p $mnt
umountdisk &> /dev/null || true
sudo mount -o loop $DISK $mnt
}
function disk_umount {
echo "* Unmounting ${DISK}..."
sudo umount $DISK
}
function disk_build {
local size=$1
local tmp_mnt=$( mktemp -d /tmp/clientctl-XXXXX )
echo "* Building ${size} MB disk image..."
dd if=/dev/zero of=$DISK bs=1M count=$size
$MKFS $DISK
echo "* Setting up /ext/etc/rc file executed at startup..."
rc_create > $RC
disk_mount $tmp_mnt
[ -d $tmp_mnt/etc ] || mkdir -p $tmp_mnt/etc
rc_ext_default_create > $tmp_mnt/etc/rc
disk_umount
rm -rf $tmp_mnt
}
case "$mode" in
'buildimage')
(cd $ROOT && CREATE_IMAGE_ONLY=1 releasetools/x86_hdimage.sh)
;;
'builddisk')
rm -f $DISK
disk_build $DISK_SIZE
;;
'mountdisk')
disk_mount $DISK_MNT
;;
'umountdisk')
disk_umount
;;
'run')
if [ "$HYPER" == "" ]; then
if which kvm2 > /dev/null; then
HYPER=kvm
elif [ -e /dev/kvm ]; then
HYPER="qemu-system-i386 --enable-kvm"
else
HYPER=qemu-system-i386
fi
fi
opts="-hda $IMAGE"
append="rootdevname=c0d0p1"
[ ! -f $DISK ] || opts="$opts -hdb $DISK"
if [ $SERIALOUT -eq 1 ]; then
opts="$opts -curses -serial file:$MYPWD/serial.out"
append="$append cttyline=0"
else
opts="$opts -nographic"
append="$append console=tty00"
fi
(cd ../../../obj.i386/destdir.i386/boot/minix/.temp && $HYPER -kernel kernel -append "$append" $opts -initrd "mod01_ds,mod02_rs,mod03_pm,mod04_sched,mod05_vfs,mod06_memory,mod07_tty,mod08_mfs,mod09_vm,mod10_pfs,mod11_init")
;;
*)
echo "Invalid action: $mode"
exit 1
;;
esac