home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / grub-floppy < prev    next >
Encoding:
Text File  |  2007-04-10  |  2.9 KB  |  113 lines

  1. #!/bin/sh
  2.  
  3. # Create GRUB boot floppy.
  4. #   Copyright (C) 2001 Jason Thomas <jason@debian.org>
  5. #
  6. # This file is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  19.  
  20. # Initialize some variables.
  21. dd=`which dd`
  22. ls=`which ls`
  23. head=`which head`
  24. pkglibdir=/usr/lib/grub/*-*
  25. stage1=`$ls -1 $pkglibdir/stage1 | $head -1`
  26. stage2=`$ls -1 $pkglibdir/stage2 | $head -1`
  27.  
  28. # I like functions.
  29.  
  30. abort()
  31. {
  32.         /bin/echo -e "\n$@\n" >&2
  33.                 exit 1
  34. }
  35.  
  36. checkfiles()
  37. {
  38.         [ -x "$dd" ] || abort "Can't find $dd, aborting"
  39.         [ -f "$stage1" ] || abort "Can't find $stage1, aborting"
  40.         [ -f "$stage2" ] || abort "Can't find $stage2, aborting"
  41. }
  42.  
  43. usage()
  44. {
  45.         cat <<EOF
  46. Usage: $0 [options] <block device>
  47. Create GRUB boot floppy.
  48.  
  49. options:
  50.         -h, --help      print this message and exit
  51.  
  52. EOF
  53.         exit 1
  54. }
  55.  
  56. checkdevice()
  57. {
  58.         [ -z "$1" ] && abort "checkdevice() takes block device as parameter"
  59.  
  60.         [ -b "$1" ] || abort "$1 is not a block device, aborting"
  61.         [ -w "$1" ] || abort "$1 is not a writeable block device, aborting"
  62. }
  63.  
  64. questiondevice()
  65. {
  66.         [ -z "$1" ] && abort "questiondevice() takes block device as parameter"
  67.  
  68.         echo "You are about to overwrite the boot sector of the following device:"
  69.         echo "$1"
  70.         echo -n "Are you sure you want to take this action (y/N) "
  71.         read answer
  72.         case "$answer" in
  73.                 y* | Y*)
  74.                         # let this fall through to the next function
  75.                         ;;
  76.                 *)
  77.                         abort "Not continuing as you wish"
  78.                 ;;
  79.         esac
  80. }
  81.  
  82. createfloppy()
  83. {
  84.         [ -z "$1" ] && abort "createfloppy() takes block device as parameter"
  85.  
  86.         /bin/echo -e "Creating grub boot floppy now, please be patient ...\n"
  87.  
  88.         # heres where we actually create the floppy :-p
  89.         $dd if="$stage1" of="$1" bs="512" count="1"
  90.         $dd if="$stage2" of="$1" bs="512" seek="1"
  91.  
  92.         /bin/echo -e "\nThat's All Folks!"
  93. }
  94.  
  95. case "$1" in
  96.         -h | --help)
  97.                 usage
  98.                 ;;
  99.  
  100.         *)
  101.                 if [ -z "$1" ] ; then
  102.                         usage
  103.                 else
  104.                         checkfiles
  105.                         checkdevice "$1"
  106.                         questiondevice "$1"
  107.                         createfloppy "$1"
  108.                 fi
  109.                 ;;
  110. esac
  111.  
  112. exit 0
  113.