| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 | #!/bin/bashgrubinstall=1while getopts ":tin" optiondo	case $option in		t)		emul=$OPTARG		;;		i)		initramfs=1		;;		n)		grubinstall=0		;;		*)		printf "Option not recognized\n"		exit 1		;;	esacdoneshift $(($OPTIND - 1))if [ $(id -u) -ne 0 ];then	printf "Installation is only possible as root\n"	exit 1fiprintf "Checking if grub is installed"grub=$(which grub)if [ -x $grub ];then	printf "...okay\n"else	printf "...failed\n"	exit 1fiprintf "Checking if parted is installed"parted=$(which parted)if [ -x $parted ];then	printf "...okay\n"else	printf "...failed\n"	exit 1fiprintf "Checking if qemu-img is installed"qimg=$(which qemu-img)if [ -x $qimg ];then	printf "...okay\n"else	printf "...failed\n"	exit 1fiif [ -z $1 ];then	printf "Please give the name of the image file\n"	exit 1fi	if [ -z $initramfs ];then	if [ -z $2 ];then		printf "Please give the name of the openadk archive file\n"		exit 1	fi	else	if [ -z $2 ];then		printf "Please give the full path prefix to kernel/initramfs\n"		exit 1	fifiprintf "Generate qemu image\n"$qimg create -f raw $1 300Mprintf "Create partition and filesystem\n"$parted -s $1 mklabel msdos$parted -s $1 mkpart primary ext2 0 300$parted -s $1 set 1 boot on$parted -s $1 mkfs 1 ext2if [ $? -eq 0 ];then	printf "Successfully created partition\n"	$parted $1 printelse	printf "Partition creation failed, Exiting.\n"	exit 1fitmp=$(mktemp -d)mount -o loop,offset=16384 -t ext2 $1 $tmpif [ -z $initramfs ];then	printf "Extracting install archive\n"	tar -C $tmp -xzpf $2 	printf "Fixing permissions\n"	chmod 1777 $tmp/tmp	chmod 4755 $tmp/bin/busyboxelse	printf "Copying kernel/initramfs\n"	mkdir $tmp/boot $tmp/dev	cp $2-kernel $tmp/boot/kernel	cp $2-initramfs $tmp/boot/initramfsfiif [ $grubinstall -eq 1 ];thenprintf "Copying grub files\n"mkdir $tmp/boot/grubcp /boot/grub/stage1 $tmp/boot/grubcp /boot/grub/stage2 $tmp/boot/grubcp /boot/grub/e2fs_stage1_5 $tmp/boot/grubif [ -z $initramfs ];thencat << EOF > $tmp/boot/grub/menu.lstserial --unit=0 --speed=115200 --word=8 --parity=no --stop=1terminal --timeout=2 serial consoletimeout 2default 0hiddenmenutitle linuxroot (hd0,0)kernel /boot/kernel root=/dev/sda1 init=/init console=ttyS0,115200 console=tty0 panic=10 rwEOFelsecat << EOF > $tmp/boot/grub/menu.lstserial --unit=0 --speed=115200 --word=8 --parity=no --stop=1terminal --timeout=2 serial consoletimeout 4default 0hiddenmenutitle linuxroot (hd0,0)kernel /boot/kernel root=/dev/sda1 console=ttyS0,115200 console=tty0 rwinitrd /boot/initramfsEOFfiprintf "Installing Grub bootloader\n"$grub --batch --no-curses --no-floppy --device-map=/dev/null >/dev/null << EOFdevice (hd0) $1root (hd0,0)setup (hd0)quitEOFfiprintf "Creating device nodes\n"mknod -m 666 $tmp/dev/zero c 1 5mknod -m 666 $tmp/dev/null c 1 3mknod -m 622 $tmp/dev/console c 5 1mknod -m 666 $tmp/dev/tty c 5 0mknod -m 666 $tmp/dev/tty0 c 4 0mknod -m 660 $tmp/dev/hda b 3 0mknod -m 660 $tmp/dev/hda1 b 3 1mknod -m 666 $tmp/dev/ttyS0 c 4 64umount $tmpprintf "Successfully installed.\n"exit 0
 |