#!/bin/sh
# Scripts created for www.phathack.com
#
# Copyright 2005 Jud Barron jud.barron@gmail.com
#
# Released under the GPL: http://www.gnu.org/licenses/licenses.html
#
#
# This script will patch your music keg or phatbox firmware to allow
#  any hard drive to be used provided it has been properly prepared.
# Proper preperation of a DMS drive includes having the first 1 megabyte
#  of the drive copied from an working phatnoise original DMS.
#
# The first partition must start AFTER the first 1 megabyte of the drive
#  so that the signature area is undisturbed.  Also an MSDOS boot sector
#  must be present on the drive.

/bin/dd if=/dev/hda of=/dos/backup/drive-sig-1mb.bin bs=512 count=2048

/dos/hdparm -q > /dos/backup/dms-serialnumber.txt

echo Starting Patch Process > /dos/log/PatchVerify.log
/dos/backup/phatpatch v >> /dos/log/PatchVerify.log 2>&1

while true;
 do
        /dos/backup/phatpatch v;
        case $? in
          0)
            [ -f /dos/ramdisk.sig.real ] && {
              rm -f /dos/ramdisk.sig
              mv /dos/ramdisk.sig.real /dos/ramdisk.sig
              sync
            }
            break
          ;;
          1|2|3)
            /dos/backup/phatpatch p 9 >> /dos/log/PatchWrite.log 2>&1
          ;; 
          4)
            mv /dos/ramdisk.sig /dos/ramdisk.sig.real
            cp /dos/rc.sig /dos/ramdisk.sig
            sync
            /dos/backup/phatpatch p 9 >> /dos/log/PatchWrite.log 2>&1
          ;;
          *)
            /dos/backup/phatpatch p 5 >> /dos/log/PatchWrite.log 2>&1
          ;;
        esac
        sleep 2
 done

/dos/nmp3 /dos/backup/patchcomplete.mp3

/dos/backup/phatpatch v >> /dos/log/PatchVerify.log 2>&1

/bin/dmesg > /dos/log/dmesg.log

