#!/bin/ash
#
#
#
 if [ -e /sys/firmware/efi ]; then
   exit
 fi
 if [ x$1 = x ]; then
   exit
 fi
 if [ x$TARGET = x ]; then
   TARGET=$(echo $1 | cut -c 6-10)
 fi
 if [ ! -e /dev/$TARGET ]; then
   exit
 fi
 mkdir /tmp/slsetup 2>/dev/null
 mount /dev/$TARGET /tmp/slsetup 2>/dev/null
 rmdir /tmp/slsetup 2>/dev/null
 if [ ! -e /tmp/slsetup ]; then
   echo "ERROR: I can't mount /dev/$TARGET"
   exit
 fi
 touch /boot/map
 rmlilo
 fdisk -l /dev/sda | grep Disklabel | grep dos > /tmp/fdisk1.tmp
 echo $TARGET > /tmp/target.tmp
 ID=$(cat /tmp/target.tmp | cut -c 4,5)
 if [ -s /tmp/fdisk1.tmp ]; then
   printf "\x$ID" | cat /usr/share/syslinux/altmbr.bin - | dd bs=440 count=1 conv=notrunc iflag=fullblock of=/dev/sda
 fi
 if [ /dev/$TARGET = $(cat /etc/rootfs) ]; then
   extlinux -i /boot
   else
   extlinux -i /tmp/slsetup/boot
 fi
 echo "DEFAULT 4MLinux" > /tmp/slsetup/boot/extlinux.conf
 echo "LABEL 4MLinux" >> /tmp/slsetup/boot/extlinux.conf
 echo "KERNEL bzImage" >> /tmp/slsetup/boot/extlinux.conf
 echo "APPEND root=/dev/$TARGET" >> /tmp/slsetup/boot/extlinux.conf
 parted /dev/sda set $ID boot on >/dev/null 2>&1
 umount /tmp/slsetup
