home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 October - Disc 1 / PCNET_CD_2006_10_1.iso / linux / INSERT-1.3.5a_en.iso / mkbootfloppy.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-02-07  |  5.3 KB  |  130 lines

  1. #!/bin/bash
  2. # insert-mkbootfloppy - Generate bootfloppies for INSERT
  3. # (works for INSERTs from 1.2.13)
  4. # (C) Klaus Knopper May 2004
  5. # Modifications: Matthias Mikuletz <mm@inside-security.de>
  6. #
  7.  
  8. PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
  9. export PATH
  10.  
  11. umask 022
  12.  
  13. # This does not need to run as root on INSERT.
  14. # [ "`id -u`" != "0" ] && exec sudo "$0" "$@"
  15.  
  16. # LANG et al.
  17. [ -f /etc/sysconfig/i18n ] && { . /etc/sysconfig/i18n;  export LANG LC_ALL; }
  18. [ -f /etc/sysconfig/insert-remote ] && . /etc/sysconfig/insert-remote
  19.  
  20. XDIALOG_HIGH_DIALOG_COMPAT=1
  21. export XDIALOG_HIGH_DIALOG_COMPAT
  22.  
  23. TMP="/tmp/insert-mkbootfloppy.$$"
  24.    
  25. KERNEL="$(uname -r)"
  26.  
  27. #case "$KERNEL" in 2.6*) KERNEL=linux26; MINIROOT=minirt26.gz ;; *) KERNEL=linux24; MINIROOT=minirt24.gz ;; esac
  28. KERNEL=vmlinuz
  29. MINIROOT=miniroot.gz
  30.  
  31. # Utility functions, usually called in $0 "start"
  32. # Variable substitution has to be finished before
  33.  
  34. bailout(){
  35. # Leave and remove temporary files
  36.    rm -f "$TMP"
  37.    exit $1
  38. }
  39.  
  40. trap bailout 2 15
  41.  
  42. DIALOG="dialog"
  43. [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"
  44.  
  45. case "$LANGUAGE" in
  46. de|at|ch)
  47. CONTINUE="Weiter"
  48. CANCEL="Abbruch"
  49. TITLE0="INSERT Bootdiskette erzeugen"
  50. MESSAGE0="Formatiere Diskette und kopiere Daten..."
  51. TITLE1="Diskette 1"
  52. MESSAGE="Dieses Programm erzeugt zwei Disketten, mit denen INSERT auf einem Rechner gestartet werden kann, dessen CD-Laufwerk nicht bootfhig ist. Sie bentigen neben der aktuellen INSERT-CD (ab 1.2.13) zwei 1.44MB Disketten, die vom Programm VOLLSTNDIG GELSCHT und mit dem Linux-Kernel bzw. einer initialen Ramdisk versehen werden. Wenn Sie fortfahren wollen, legen Sie jetzt bitte die INSERT-CD in ein CD-Rom Laufwerk ein, mounten sie, und klicken dann auf \"Weiter\"."
  53. ERROR="Kann die INSERT-CD in keinem CD-Laufwerk finden (durchsucht wurden /cdrom*, /mnt/cdrom* und /media/cdrom*. Nochmal versuchen?"
  54. MESSAGE1="Bitte legen Sie nun die 1. Diskette (zur Erzeugung der Kernel-Bootdiskette) ein."
  55. FLOPPYERROR="Es ist ein Fehler beim Schreiben auf /dev/fd0 aufgetreten. Diese Diskette ist vermutlich defekt oder schreibgeschtzt. Nochmal versuchen?"
  56. TITLE2="Diskette 2"
  57. MESSAGE2="Bitte legen Sie nun die 2. Diskette (zur Erzeugung der initialen Ramdisk) ein."
  58. SUCCESS="Das Erzeugen der Boot- und Initrd-Disketten war erfolgreich."
  59. ;;
  60. *)
  61. CONTINUE="Continue"
  62. CANCEL="Cancel"
  63. TITLE0="INSERT boot floppy creator"
  64. MESSAGE0="Formatting floppy disk and copying data..."
  65. TITLE1="Disk 1"
  66. MESSAGE="This program creates two floppy disks, which can be used in order to boot INSERT on a computer that cannot boot directly from CD. Besides a current INSERT-CD (1.2.13 and up), you will need two 1.44MB floppy disks, which be COMPLETELY ERASED and installed with a Linux-kernel and an initial ramdisk. If you want to continue, please insert the INSERT-CD into a CD-Rom drive now, mount the CD so that it is accessible, and click on \"Continue\"."
  67. ERROR="Can't find the INSERT-CD in any CD-Rom drive (searched /cdrom*, /mnt/cdrom* and /media/cdrom*). Try again?"
  68. MESSAGE1="Please insert the first floppy disk now (for creating the kernel boot floppy)."
  69. FLOPPYERROR="There has been an error while writing to /dev/fd0. The floppy disk is probably not writable or defective. Try again?"
  70. TITLE2="Disk 2"
  71. MESSAGE2="Please insert the second floppy disk now (for creating the initial ramdisk)."
  72. SUCCESS="Creation of boot- and initrd floppy disks was successful."
  73. ;;
  74. esac
  75.  
  76. gauge(){
  77. status=0
  78. while [ ! -e "$TMP.done" ]; do echo "$status" ; status="`expr \( 100 - $status \) / 8 + $status + 1`"; sleep 8; done | $DIALOG --title "$TITLE0" --gauge "$MESSAGE0" 8 65 0
  79. }
  80.  
  81. endgauge(){
  82. touch "$TMP.done" ; wait ; rm -f "$TMP.done"
  83. }
  84.  
  85. format(){
  86. fdformat /dev/fd0u1440 >/dev/null && mformat a: >/dev/null
  87. return "$?"
  88. }
  89.  
  90. $DIALOG --defaultno --ok-label "$CONTINUE" --yes-label "$CONTINUE" --no-label "$CANCEL" --cancel-label "$CANCEL" --title "$TITLE0" --yesno "$MESSAGE" 14 65 || bailout 1
  91. while :; do
  92. rm -f "$TMP" "$TMP".done
  93. # Find CD-Rom boot/isolinux directrory
  94. SRCDIR=""
  95. for i in / /mnt /media; do
  96.  for d in `ls -1d "$i"/*cdrom* 2>/dev/null`; do
  97.   [ -e "$d"/isolinux/"$KERNEL" -a -e "$d"/isolinux/"$MINIROOT" ] && SRCDIR="$d"/isolinux && break 2
  98.  done
  99. done
  100. [ -z "$SRCDIR" ] && { $DIALOG --title "$TITLE0" --yesno "$ERROR" 7 75 && continue || bailout 1; }
  101. break
  102. done
  103.  
  104.  
  105. $DIALOG --ok-label "$CONTINUE" --yes-label "$CONTINUE" --no-label "$CANCEL" --cancel-label "$CANCEL" --title "$TITLE1" --yesno "$MESSAGE1" 7 65 || bailout 1
  106. while :; do
  107. rm -f "$TMP" "$TMP".done
  108. gauge &
  109. format && syslinux /dev/fd0u1440 && \
  110. mcopy "$SRCDIR"/{"$KERNEL",boot.msg,logo.16,f2,memtest} a: && \
  111. { rm -f "$TMP"; perl -p -e 's|^APPEND|APPEND load_ramdisk=1 prompt_ramdisk=1 root=/dev/fd0 rw|g;s|quiet ||g;s|initrd=[^ ]* ||g;' "$SRCDIR"/isolinux.cfg | head -n 34 > "$TMP" && mcopy "$TMP" a:syslinux.cfg >/dev/null; }
  112. [ "$?" != "0" ] && { endgauge; $DIALOG --title "$TITLE1" --yesno "$FLOPPYERROR" 9 65 && continue || bailout 1; }
  113. for i in `ls -1 "$SRCDIR"/*.kbd 2>/dev/null`; do mcopy "$i" a:; done
  114. endgauge
  115. break
  116. done
  117.  
  118. $DIALOG --ok-label "$CONTINUE" --yes-label "$CONTINUE" --no-label "$CANCEL" --cancel-label "$CANCEL" --title "$TITLE2" --yesno "$MESSAGE2" 7 65 || bailout 1
  119. while :; do
  120. rm -f "$TMP" "$TMP".done
  121. gauge &
  122. format && dd if="$SRCDIR"/"$MINIROOT" of=/dev/fd0u1440 bs=18k
  123. [ "$?" != "0" ] && { endgauge; $DIALOG --title "$TITLE2" --yesno "$FLOPPYERROR" 9 65 && continue || bailout 1; }
  124. endgauge
  125. break
  126. done
  127.  
  128. $DIALOG --title "$TITLE0" --msgbox "$SUCCESS" 6 65
  129. bailout 0
  130.