#!/bin/bash
#
#
#
# Now let's apply all the patches and look for failed HUNKS afterwards !

cat << EOF > /tmp/tmpmsg
The patches will now be applied to the your kernel tree !
After they were patched in you will be notified in case 
of trouble ! Please watch out for *.rej files appearing in the
REJECTION LOGFILE window. Hopefully there aren't any !

EOF

dialog --title "PATCHING THE KERNEL FOR CYCLOM MUX" \
       --menu "`cat /tmp/tmpmsg`" 12 70 2 \
"1" "Let me do a BACKUP OF THE KERNEL ... just in case ..." \
"2" "APPLY the patches IMMEDIATELY" 2> /tmp/cdtype
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/tmpmsg /tmp/cdtype
  exit
fi

SEL="`cat /tmp/cdtype`";rm -f /tmp/cdtype
if [ "$SEL" = "1" ]; then
  bck_kernel
  elif [ "$SEL" = "2" ]; then
    cd /usr/src/linux
    cp /tmp/cyc/cyclades.h /usr/src/linux/include/linux
    cp /tmp/cyc/cyclades.c /usr/src/linux/drivers/char
    cat /tmp/cyc/*.pat | patch -p0
    dialog --title "PATCHING THE KERNEL FOR CYCLOM MUX" \
           --msgbox "DONE !" 5 40
  fi

# Now find rejections
echo This is the rejections logfile > /tmp/msgtmp
find . -name "*.rej" >> /tmp/msgtmp
dialog --title "REJECTION LOGFILE (should contain NO *.rej files)" \
       --msgbox "`cat /tmp/msgtmp`" 15 70
cat << EOF > /tmp/msgtmp
                     CONGRATULATIONS !!!
                     ===================

You can now create a new kernel as usual ! Just type
make config, make dep, make clean, make zImage to build
a new kernel with the cyclom driver included.

In case you got some *.rej files you should restore the 
source tree from the Linux-1.1.xx.tar.gz file located in
/usr/src. Hopefully you were careful and made a backup !
Please e-mail me any problems with this script !

             e-mail : steffen@laguna.schiele-ct.de
EOF
dialog --title "WHAT TO DO NOW..." \
       --msgbox "`cat /tmp/msgtmp`" 18 70

cd /tmp/cyc;INST_CYCLOM 
