Advertisement
opexxx

multicd.sh

Nov 24th, 2013
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.51 KB | None | 0 0
  1.  
  2. #!/bin/bash
  3. trap exit ERR
  4.  
  5. #MCDDIR: directory where functions.sh, plugins.md5 and plugins folder are
  6. #expected to be. Not used in a combined .sh file.
  7.  
  8. export MCDDIR=$(cd "$(dirname "$0")" && pwd)
  9. PATH=$PATH:$MCDDIR:$MCDDIR/plugins
  10. . functions.sh
  11.  
  12. MCDVERSION="20130127"
  13. #multicd.sh Jan. 27, 2013
  14. #Copyright (c) 2013 Isaac Schemm
  15. #
  16. #Permission is hereby granted, free of charge, to any person obtaining a copy
  17. #of this software and associated documentation files (the "Software"), to deal
  18. #in the Software without restriction, including without limitation the rights
  19. #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  20. #copies of the Software, and to permit persons to whom the Software is
  21. #furnished to do so, subject to the following conditions:
  22. #
  23. #The above copyright notice and this permission notice shall be included in
  24. #all copies or substantial portions of the Software.
  25. #
  26. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29. #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  31. #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  32. #THE SOFTWARE.
  33.  
  34. #Needs to be changed when a new version of syslinux comes out.
  35. RECENT_SYSLINUX="4.06"
  36.  
  37. mcdclean() {
  38.     for i in *;do
  39.         if [ -n "$(readlink "$i"|grep -v '/')" ];then
  40.             rm -v "$i"
  41.         fi
  42.     done
  43.     rm -fv *.defaultname 2> /dev/null
  44.     rm -fv *.version 2> /dev/null
  45. }
  46.  
  47. #Clean operation runs here
  48. if [ "$1" = "clean" ];then
  49.     mcdclean
  50.     exit 0 #quit program
  51. else
  52.     mcdclean
  53. fi
  54.  
  55. #GUI helper - calls a terminal emulator which calls another multicd
  56. if [ "$1" = "gui" ];then
  57.     if which zenity &> /dev/null;then
  58.         DIR=$(zenity --file-selection --directory --filename=$HOME/ --title="MultiCD - Choose directory")
  59.         cd "$DIR"
  60.         RUN="$0 -w"
  61.     else
  62.         RUN="$0 give-error"
  63.     fi
  64.     if which x-terminal-emulator &> /dev/null;then
  65.         exec x-terminal-emulator -e $RUN
  66.     else
  67.         exec xterm -e $RUN
  68.     fi
  69. fi
  70.  
  71. if [ "$1" = "give-error" ];then
  72.     echo "Zenity is not installed. Please navigate to your ISO directory in the terminal, and run multicd from there."
  73.     echo "Press ENTER to continue..."
  74.     read
  75.     exit 1
  76. fi
  77.  
  78. #if getopt -T > /dev/null;then
  79. #   echo "You have a non-GNU getopt. Don't use an output path with spaces in it."
  80.     ARGS=$(getopt cdmviVo:tw $*)
  81. #else
  82. #   ARGS=$(getopt cdmviVo:tw "$@")
  83. #fi
  84. export MD5=false
  85. export MEMTEST=true
  86. export VERBOSE=true
  87. export INTERACTIVE=false
  88. export DEBUG=false
  89. export OUTPUT='multicd.iso'
  90. export TESTISO=false
  91. export WAIT=false
  92. eval set -- $ARGS
  93. for i do
  94.     case "$i" in
  95.         -c) shift;export MD5=true;;
  96.         -d) shift;export DEBUG=true;;
  97.         -i) shift;export INTERACTIVE=true;;
  98.         -m) shift;export MEMTEST=false;;
  99.         -o) shift;export OUTPUT="$1";shift;;
  100.         -t) shift;export TESTISO=true;shift;;
  101.         -v) shift;export VERBOSE=true;;
  102.         -V) shift;echo $MCDVERSION;exit 0;; #quit program
  103.         -w) shift;export WAIT=true;shift;;
  104.     esac
  105. done
  106.  
  107. if ! touch "${OUTPUT}" 2> /dev/null;then
  108.     echo "Error: cannot write to "${OUTPUT}""
  109.     exit 1
  110. else
  111.     rm "${OUTPUT}"
  112. fi
  113.  
  114. #--------Directory Variables--------#
  115. #WORK: the directory that the eventual CD/DVD contents will be stored temporarily.
  116. export WORK="$(pwd)/multicd-working"
  117. #MNT: the directory inside which new folders will be made to mount the ISO images.
  118. export MNT="$(pwd)/temporary-mountpoints"
  119. mkdir -p "${MNT}"
  120. #TAGS: used to store small text files (temporary)
  121. export TAGS="${MNT}/tags"
  122.  
  123. if [ $(whoami) = root ] && uname|grep -q Linux;then
  124.     export EXTRACTOR=mount #When possible, loop-mount is preferred because it is faster (files are copied once, not twice, before the ISO is generated) and because it runs without an X server. However, it is only available to root, which opens up security risks.
  125. elif which fuseiso &> /dev/null; then
  126.     export EXTRACTOR=fuseiso
  127. elif which 7z &> /dev/null;then
  128.     export EXTRACTOR=7z #7z is a command line application
  129. elif which ark &> /dev/null;then
  130.     export EXTRACTOR=ark #Ark is a KDE application
  131. elif which file-roller &> /dev/null;then
  132.     export EXTRACTOR=file-roller #file-roller is a GNOME application
  133. else
  134.     if !(uname|grep -q Linux);then
  135.         echo "Unless fuseiso, file-roller or ark is installed to extract ISOs, only Linux kernels are supported (due to the use of \"-o loop\")."
  136.         exit 1
  137.     elif [ $(whoami) != "root" ];then
  138.         echo "Unless file-roller, ark or 7z is installed to extract ISOs, this script must be run as root, so it can mount ISO images on the filesystem during the building process."
  139.         exit 1
  140.     fi
  141. fi
  142. if ( [ $EXTRACTOR = file-roller ] || [ $EXTRACTOR = ark ] ) && [ ! -n "$DISPLAY" ];then
  143.     echo "This script cannot use file-roller or ark to extract ISOs, because no X server  is available. Please launch an X server or run this script as root."
  144.     exit 1
  145. fi
  146.  
  147. if [ -d "${TAGS}" ];then rm -r "${TAGS}";fi
  148. mkdir -p "${TAGS}"
  149. mkdir "${TAGS}"/puppies
  150. mkdir "${TAGS}"/debians
  151. chmod -R 777 "${TAGS}"
  152.  
  153. #START PREPARE#
  154.  
  155. #Plugin check currently disabled because it seems like more of a distraction than it's worth.
  156. #One parenthesis is for md5sums that don't match; the other is for plugins that are not listed in plugins.md5
  157. #UNKNOWNS="$(md5sum -c "${MCDDIR}"/plugins.md5|grep FAILED|awk -F: '{print $1}') $(for i in "${MCDDIR}"/plugins/*.sh;do grep -q $(basename $i) "${MCDDIR}"/plugins.md5||echo $i;done)"
  158. #if [ "$UNKNOWNS" != " " ];then
  159. #   echo
  160. #   echo "Plugins that are not from the official release: $UNKNOWNS"
  161. #   if [ $(whoami) = root ];then
  162. #       echo "Make sure you trust every script in the plugins folder - all these scripts will get root access!"
  163. #   fi
  164. #   echo "Press Ctrl+C to cancel"
  165. #   echo
  166. #   sleep 2
  167. #fi
  168.  
  169. #END PREPARE#
  170.  
  171. isoaliases #This function is in functions.sh
  172.  
  173. echo "multicd.sh $MCDVERSION"
  174. echo "Extracting ISO images with $EXTRACTOR; will build "${OUTPUT}"; UID $(id -u)."
  175. echo
  176.  
  177. #START SCAN
  178. for i in "${MCDDIR}"/plugins/*.sh;do
  179.     "$i" scan
  180. done
  181. #END SCAN
  182.  
  183. for i in *.im[agz]; do
  184.     test -r "$i" || continue
  185.     echo $i|sed 's/\.im.//'
  186. done
  187. GAMES=0 #Will be changed if there are games
  188. for i in games/*.im[agz]; do
  189.     test -r "$i" || continue
  190.     echo Game: $(echo $i|sed 's/\.im.//'|sed 's/games\///')
  191.     GAMES=1
  192. done
  193. if [ -f grub.exe ];then
  194.     echo "GRUB4DOS"
  195. fi
  196. if $MEMTEST;then
  197.     echo "Memtest86+"
  198. fi
  199.  
  200. if [ $EXTRACTOR == file-roller ];then
  201.     FRVER=$(file-roller --version 2>/dev/null|awk '{print $2}'|head -c 3)
  202.     if [ $(echo "${FRVER}<3.5"|bc) == 0 ];then
  203.         echo
  204.         echo "WARNING: versions of file-roller newer than 3.4.xx may not successfully extract ISOs! Installing fuseiso is recommended." 1>&2
  205.     fi
  206. fi
  207.  
  208. echo
  209. echo "Continuing in 2 seconds - press Ctrl+C to cancel"
  210. sleep 2
  211.  
  212. if $INTERACTIVE;then
  213.     if ! which dialog &> /dev/null;then
  214.         echo "You must install dialog to use the interactive options."
  215.         exit 1
  216.     fi
  217.  
  218.     dialog --inputbox "What would you like the title of the CD's main menu to be?" 8 70 "MultiCD - Created $(LANG=C date +"%b %d, %Y")" 2> /tmp/cdtitle
  219.     CDTITLE=$(cat /tmp/cdtitle)
  220.     rm /tmp/cdtitle
  221.  
  222.     dialog --inputbox "What would you like the CD label to be?" 9 40 "MultiCD" 2> /tmp/cdlabel
  223.     export CDLABEL=$(cat /tmp/cdlabel)
  224.     rm /tmp/cdlabel
  225.  
  226.     dialog --menu "What menu BACKGROUND color would you like?" 0 0 0 40 black 41 red 42 green 43 brown 44 blue 45 magenta 46 cyan 47 white 2> /tmp/color
  227.     MENUCOLOR=$(cat /tmp/color)
  228.     echo $(echo -e "\r\033[0;$(cat /tmp/color)m")Color chosen.$(echo -e '\033[0;39m')
  229.     rm /tmp/color
  230.  
  231.     dialog --menu "What menu TEXT color would you like?" 0 0 0 37 white 30 black 31 red 32 green 33 brown 34 blue 35 magenta 36 cyan 2> /tmp/color
  232.     TEXTCOLOR=$(cat /tmp/color)
  233.     echo $(echo -e "\r\033[0;$(cat /tmp/color)m")Color chosen.$(echo -e '\033[0;39m')
  234.     rm /tmp/color
  235.  
  236.     dialog --inputbox "Enter the language code for the language you would like to use.\n\
  237. Leaving this empty will leave the choice up to the plugin (usually English.)\n\
  238. Examples: fr_FR = Francais (France); es_ES = Espanol (Espana)" 12 50 "${LANGFULL}" 2> "${TAGS}"/lang-full
  239.  
  240.     dialog --inputbox "Enter the code for your keyboard layout.\n
  241. Leaving this blank will typically default to QWERTY (US).\n\
  242. Examples: fr (AZERTY France), fr_CH (QWERTZ Switzerland)" 12 50 "${COUNTRY}" 2> "${TAGS}"/country
  243.  
  244.     if [ -f slax.iso ];then
  245.         dialog --checklist "Slax modules to include:" 13 45 6 \
  246.         002 Xorg on \
  247.         003 KDE on \
  248.         004 "KDE applications" on \
  249.         005 "KDE Office" on \
  250.         006 Development on \
  251.         007 Firefox on \
  252.         2> "${TAGS}"/slaxlist0
  253.         echo >> "${TAGS}"/slaxlist0
  254.         cat "${TAGS}"/slaxlist0|sed -e 's/"//g' -e 's/ /\n/g'>"${TAGS}"/slaxlist
  255.         rm "${TAGS}"/slaxlist0
  256.         if wc -c "${TAGS}"/slaxlist|grep -q 24;then #24 bytes means they are all checked
  257.             rm "${TAGS}"/slaxlist #If they are all checked, delete the file
  258.         fi
  259.     fi
  260.     if [ -f porteus.iso ];then
  261.         dialog --checklist "Porteus modules to include:" 13 45 6 \
  262.         002 Xorg on \
  263.         003 LXDE on \
  264.         004 KDE on \
  265.         005 "KDE apps" on \
  266.         006 KOffice on \
  267.         007 Development on \
  268.         008 Firefox on \
  269.         2> "${TAGS}"/porteuslist0
  270.         echo >> "${TAGS}"/porteuslist0
  271.         cat "${TAGS}"/porteuslist0|sed -e 's/"//g' -e 's/ /\n/g'>"${TAGS}"/porteuslist
  272.         rm "${TAGS}"/porteuslist0
  273.         if wc -c "${TAGS}"/porteuslist|grep -q 28;then #28 bytes means they are all checked
  274.             rm "${TAGS}"/porteuslist #If they are all checked, delete the file
  275.         fi
  276.     fi
  277.     if [ -f win98se.iso ] || [ -f winme.iso ];then
  278.         if dialog --yesno "Would you like to copy the \"tools\" and \"add-ons\" folders from the Windows 9x/Me CD?" 0 0;then
  279.             touch "${TAGS}"/9xextras
  280.         fi
  281.     fi
  282.     if [ $(find "${TAGS}"/puppies -maxdepth 1 -type f|wc -l) -gt 1 ] && which dialog &> /dev/null;then
  283.         echo "dialog --radiolist \"Which Puppy variant would you like to be installable to HD from the disc?\" 13 45 6 \\">puppychooser
  284.         for i in "${TAGS}"/puppies/*;do
  285.             echo $(basename $i) \"\" off \\ >> puppychooser
  286.         done
  287.         echo "2> puppyresult" >> puppychooser
  288.         sh puppychooser
  289.         touch "${TAGS}"/puppies/$(cat puppyresult).inroot
  290.         rm puppychooser puppyresult
  291.     elif [ $(find "${TAGS}"/puppies -maxdepth 1 -type f|wc -l) -eq 1 ];then
  292.         NAME=$(ls "${TAGS}"/puppies)
  293.         true>$(find "${TAGS}"/puppies -maxdepth 1 -type f).inroot
  294.     fi
  295.     if [ $(find "${TAGS}"/debians -maxdepth 1 -type f|wc -l) -gt 1 ] && which dialog &> /dev/null;then
  296.         echo "dialog --radiolist \"Which Debian-Live variant would you like to be installable to HD from the disc?\" 13 45 6 \\">debianschooser
  297.         for i in "${TAGS}"/debians/*;do
  298.             echo $(basename $i) \"\" off \\ >> debianschooser
  299.         done
  300.         echo "2> debiansresult" >> debianschooser
  301.         sh debianschooser
  302.         touch "${TAGS}"/debians/$(cat debiansresult).inroot
  303.         rm debianschooser debiansresult
  304.     elif [ $(find "${TAGS}"/debians -maxdepth 1 -type f|wc -l) -eq 1 ];then
  305.         NAME=$(ls "${TAGS}"/debians)
  306.         TAG_TO_TOUCH=$(find "${TAGS}"/debians -maxdepth 1 -type f).inroot
  307.         true>"$TAG_TO_TOUCH"
  308.     fi
  309.     if which dialog &> /dev/null;then
  310.         find "${TAGS}" -maxdepth 1 -name \*.needsname|while read i;do
  311.             BASENAME=$(basename "$i"|sed -e 's/\.needsname//g')
  312.             if [ -f $BASENAME.defaultname ];then
  313.                 DEFUALTTEXT=$(cat $BASENAME.defaultname)
  314.             else
  315.                 DEFAULTTEXT=""
  316.             fi
  317.             NAME_FILE=$(echo $i|sed -e 's/needsname/name/g')
  318.             dialog --inputbox "What would you like $BASENAME to be called on the CD boot menu?\n(Leave blank for the default.)" 10 70 \
  319.             2> "$NAME_FILE"
  320.             if [ "$(cat "${TAGS}"/$BASENAME.name)" = "" ] && [ -f $BASENAME.defaultname ];then
  321.                 cp $BASENAME.defaultname "${TAGS}"/$BASENAME.name
  322.             fi
  323.         done
  324.     else
  325.         for i in $(find "${TAGS}" -maxdepth 1 -name \*.needsname);do
  326.             BASENAME=$(basename $i|sed -e 's/\.needsname//g')
  327.             if [ -f $BASENAME.defaultname ];then
  328.                 cp $BASENAME.defaultname "${TAGS}"/$BASENAME.name
  329.             fi
  330.         done
  331.     fi
  332. else
  333.     #Do these things if interactive options are not enabled with "-i"
  334.     CDTITLE="MultiCD - Created $(LANG=C date +"%b %d, %Y")"
  335.     export CDLABEL=MultiCD
  336.     MENUCOLOR=44
  337.     TEXTCOLOR=37
  338.     if [ "$LANGFULL" ] && [ "$LANGFULL" != "C" ];then
  339.         echo "$LANGFULL" > "${TAGS}"/lang-full
  340.     fi
  341.     if [ $COUNTRY ];then
  342.         echo "$COUNTRY" > "${TAGS}"/country
  343.     fi
  344.     touch "${TAGS}"/9xextras
  345.     for i in puppies debians;do
  346.         if [ $(find "${TAGS}"/$i -maxdepth 1 -type f|wc -l) -ge 1 ] && which dialog &> /dev/null;then #Greater or equal to 1 puppy installed
  347.             FILE=$(find "${TAGS}"/$i -maxdepth 1 -type f|head -n 1)
  348.             touch "$FILE.inroot" #This way, the first one alphabetically will be in the root dir
  349.         fi
  350.     done
  351.     for i in $(find "${TAGS}" -maxdepth 1 -name \*.needsname);do
  352.         BASENAME=$(basename $i|sed -e 's/\.needsname//g')
  353.         if [ -f $BASENAME.defaultname ];then
  354.             cp $BASENAME.defaultname "${TAGS}"/$BASENAME.name
  355.         fi
  356.     done
  357. fi
  358.  
  359. for i in lang-full country;do
  360.     if [ -f "${TAGS}"/$i ] && ( [ -z $(cat "${TAGS}"/$i) ] || [ $(cat "${TAGS}"/$i) = "C" ] ); then
  361.         rm "${TAGS}"/$i #The user didn't enter anything - removing this tag file will let the plugin decide which language to use.
  362.     fi
  363. done
  364. if [ -f "${TAGS}"/lang-full ];then
  365.     #Get two-letter code (e.g. the first part) for plugins that only use that part of the lang code
  366.     cut -c1-2 < "${TAGS}"/lang-full > "${TAGS}"/lang
  367. fi
  368.  
  369. if [ -d "${WORK}" ];then
  370.  rm -r "${WORK}"/*
  371. else
  372.  mkdir "${WORK}"
  373. fi
  374.  
  375. #Make sure it exists, you need to put stuff there later
  376. mkdir -p "${WORK}"/boot/isolinux
  377.  
  378. #START COPY
  379. echo "Copying files for each plugin...";
  380. for i in "${MCDDIR}"/plugins/*.sh;do
  381.     [ ! -x "$i" ]&&chmod +x "$i"
  382.     "$i" copy
  383. done
  384. #END COPY
  385.  
  386. #The below chunk copies floppy images.
  387. j="0"
  388. for i in *.im[agz]; do
  389.     test -r "$i" || continue
  390.     cp "$i" "${WORK}"/boot/$j.img
  391.     echo -n Copying $(echo $i|sed 's/\.im.//')"... "
  392.     if $VERBOSE;then
  393.         echo "Saved as "$j".img."
  394.     else
  395.         echo
  396.     fi
  397.     j=$( expr $j + 1 )
  398. done
  399.  
  400. #This chunk copies floppy images in the "games" folder. They will have their own submenu.
  401. if [ $GAMES = 1 ];then
  402.     k="0"
  403.     mkdir -p "${WORK}"/boot/games
  404.     for i in games/*.im[agz]; do
  405.         test -r "$i" || continue
  406.         echo -n Copying $(echo $i|sed 's/\.im.//'|sed 's/games\///')"... "
  407.         cp "$i" "${WORK}"/boot/games/$k.img
  408.         if $VERBOSE;then
  409.             echo "Saved as games/"$k".img."
  410.         else
  411.             echo
  412.         fi
  413.         k=$( expr $k + 1 )
  414.     done
  415. fi
  416.  
  417. if [ -f grub.exe ];then
  418.  echo "Copying GRUB4DOS..."
  419.  cp grub.exe "${WORK}"/boot/grub.exe
  420. fi
  421.  
  422. if [ -f syslinux-4.03.tar.gz ] && [ ! -f syslinux.tar.gz ];then
  423.     ln -s syslinux-4.03.tar.gz syslinux.tar.gz #Link newest version
  424. fi
  425.  
  426. if [ ! -f syslinux.tar.gz ];then
  427.     echo "Downloading SYSLINUX..."
  428.     if $VERBOSE ;then #These will only be run if there is no syslinux.tar.gz
  429.         #Both of these need to be changed when a new version of syslinux comes out.
  430.         if ! wget -t 1 -O syslinux.tar.gz https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-$RECENT_SYSLINUX.tar.gz;then
  431.             echo "Error: could not download SYSLINUX. Please update the URL in $0."
  432.             rm syslinux.tar.gz
  433.             false #quits script
  434.         fi
  435.     else
  436.         if ! wget -t 1 -qO syslinux.tar.gz https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-$RECENT_SYSLINUX.tar.gz;then
  437.             echo "Error: could not download SYSLINUX. Please update the URL in $0."
  438.             rm syslinux.tar.gz
  439.             false #quits script
  440.         fi
  441.     fi
  442. fi
  443. echo "Unpacking and copying SYSLINUX files..."
  444. tar -C /tmp -xzf syslinux.tar.gz
  445. cp /tmp/syslinux-*/core/isolinux.bin "${WORK}"/boot/isolinux/
  446. cp /tmp/syslinux-*/memdisk/memdisk "${WORK}"/boot/isolinux/
  447. cp /tmp/syslinux-*/com32/menu/menu.c32 "${WORK}"/boot/isolinux/
  448. cp /tmp/syslinux-*/com32/menu/vesamenu.c32 "${WORK}"/boot/isolinux/
  449. cp /tmp/syslinux-*/com32/chain/chain.c32 "${WORK}"/boot/isolinux/
  450. cp /tmp/syslinux-*/utils/isohybrid "${TAGS}"/isohybrid
  451. chmod -R +w "$WORK/boot/isolinux"
  452. chmod +x "${TAGS}"/isohybrid
  453. rm -r /tmp/syslinux-*/
  454.  
  455. if $MEMTEST;then
  456.     if [ -f memtest ] && [ "$(wc -c memtest)" != "0" ];then
  457.         cp memtest "${WORK}"/boot/memtest
  458.     else
  459.         echo "Downloading memtest86+ 4.20 from memtest.org..."
  460.         if $VERBOSE;then
  461.             wget -O- http://memtest.org/download/4.20/memtest86+-4.20.bin.gz|gzip -cd>memtest
  462.         else
  463.             wget -qO- http://memtest.org/download/4.20/memtest86+-4.20.bin.gz|gzip -cd>memtest
  464.         fi
  465.         if [ -f memtest ] && [ "$(wc -c memtest)" != "0 memtest" ];then
  466.             cp memtest "${WORK}"/boot/memtest
  467.             echo 'v4.20' > memtestver
  468.         else
  469.             echo "Download of memtest failed."
  470.         fi
  471.     fi
  472. fi
  473.  
  474. echo "Writing isolinux.cfg..."
  475.  
  476. ##BEGIN ISOLINUX MENU CODE##
  477. #The ISOLINUX menu can be rearranged by renaming your plugin scripts - they are processed in alphabetical order.
  478.  
  479. #BEGIN HEADER#
  480. #Don't move this part. You can change the timeout and menu title, however.
  481. echo "DEFAULT menu.c32
  482. TIMEOUT 0
  483. PROMPT 0" > "${WORK}"/boot/isolinux/isolinux.cfg
  484. #Changed to use $TAGS/country instead of the old $ccTLD
  485. if [ -f "${TAGS}/country" ];then #PDV
  486.     cp -r maps "${WORK}"/boot/isolinux
  487.     echo "KBDMAP maps/$(cat "${TAGS}"/country).ktl" >> "${WORK}"/boot/isolinux/isolinux.cfg
  488. fi
  489. echo "menu title $CDTITLE" >> "${WORK}"/boot/isolinux/isolinux.cfg
  490. #END HEADER#
  491.  
  492. #BEGIN COLOR CODE#
  493.     if [ $MENUCOLOR = 40 ];then
  494.         BORDERCOLOR=37 #white border
  495.     else
  496.         BORDERCOLOR=30 #black border
  497.     fi
  498.     echo "  menu color screen 37;40
  499.     menu color border 30;44
  500.     menu color title 1;36;44
  501.     menu color unsel 37;44
  502.     menu color hotkey 1;37;44
  503.     menu color sel 7;37;40
  504.     menu color hotsel 1;7;37;40
  505.     menu color disabled 1;30;44
  506.     menu color scrollbar 30;44
  507.     menu color tabmsg 31;40
  508.     menu color cmdmark 1;36;40
  509.     menu color cmdline 37;40
  510.     menu color pwdborder 30;47
  511.     menu color pwdheader 31;47
  512.     menu color pwdentry 30;47
  513.     menu color timeout_msg 37;40
  514.     menu color timeout 1;37;40
  515.     menu color help 37;40
  516.     menu color msg07 37;40"|sed \
  517.     -e "s/30/$BORDERCOLOR/g" -e "s/44/$MENUCOLOR/g"|sed \
  518.     -e "s/unsel 37/unsel $TEXTCOLOR/g" >>"${WORK}"/boot/isolinux/isolinux.cfg
  519. #END COLOR CODE#
  520.  
  521. #BEGIN HD BOOT OPTION#
  522. #If this bugs you, get rid of it.
  523. echo "label local
  524. menu label Boot from ^hard drive
  525. kernel chain.c32
  526. append hd0" >> "${WORK}"/boot/isolinux/isolinux.cfg
  527. #END HD BOOT OPTION#
  528. #START WRITE
  529. for i in "${MCDDIR}"/plugins/*.sh;do
  530.     [ ! -x "$i" ]&&chmod +x "$i"
  531.     "$i" writecfg
  532. done
  533. #END WRITE
  534.  
  535. #BEGIN DISK IMAGE ENTRY#
  536. j="0"
  537. for i in *.im[agz]; do
  538.     test -r "$i" || continue
  539.     BASICNAME=$(echo $i|sed 's/\.im.//')
  540.     echo label "$BASICNAME" >> "${WORK}"/boot/isolinux/isolinux.cfg
  541.     echo kernel memdisk >> "${WORK}"/boot/isolinux/isolinux.cfg
  542.     echo initrd /boot/$j.img >> "${WORK}"/boot/isolinux/isolinux.cfg
  543.     j=$( expr $j + 1 )
  544. done
  545. #END DISK IMAGE ENTRY#
  546.  
  547. #BEGIN GRUB4DOS ENTRY#
  548. if [ -f "${WORK}"/boot/grub.exe ];then
  549. echo "label grub4dos
  550. menu label ^GRUB4DOS
  551. kernel /boot/grub.exe">>"${WORK}"/boot/isolinux/isolinux.cfg
  552. elif [ -f "${WORK}"/boot/riplinux/grub4dos/grub.exe ];then
  553. echo "label grub4dos
  554. menu label ^GRUB4DOS
  555. kernel /boot/riplinux/grub4dos/grub.exe">>"${WORK}"/boot/isolinux/isolinux.cfg
  556. fi
  557. #END GRUB4DOS ENTRY#
  558.  
  559. #BEGIN GAMES ENTRY#
  560. if [ $GAMES = 1 ];then
  561. echo "label games
  562. menu label ^Games on disk images
  563. com32 menu.c32
  564. append games.cfg">>"${WORK}"/boot/isolinux/isolinux.cfg
  565. fi
  566. #END GAMES ENTRY#
  567.  
  568. #BEGIN MEMTEST ENTRY#
  569. if [ -f "${WORK}"/boot/memtest ];then
  570. echo "label memtest
  571. menu label ^Memtest86+ $(cat memtestver)
  572. kernel /boot/memtest">>"${WORK}"/boot/isolinux/isolinux.cfg
  573. fi
  574. #END MEMTEST ENTRY#
  575. ##END ISOLINUX MENU CODE##
  576.  
  577. if [ $GAMES = 1 ];then
  578. k="0"
  579. cat > "${WORK}"/boot/isolinux/games.cfg << "EOF"
  580. default menu.c32
  581. timeout 300
  582.  
  583. menu title "Choose a game to play:"
  584. EOF
  585. for i in games/*.im[agz]; do
  586.     test -r "$i" || continue
  587.     BASICNAME=$(echo $i|sed 's/\.im.//'|sed 's/games\///')
  588.     echo label "$BASICNAME" >> "${WORK}"/boot/isolinux/games.cfg
  589.     echo kernel memdisk >> "${WORK}"/boot/isolinux/games.cfg
  590.     echo initrd /boot/games/$k.img >> "${WORK}"/boot/isolinux/games.cfg
  591.     k=$( expr $k + 1 )
  592. done
  593. echo "label back
  594. menu label Back to main menu
  595. com32 menu.c32
  596. append isolinux.cfg">>"${WORK}"/boot/isolinux/games.cfg
  597. fi
  598.  
  599. if [ -d includes ] && [ "$(echo empty/.* empty/*)" != 'empty/. empty/.. empty/*' ] ;then
  600.  echo "Copying includes..."
  601.  cp -r includes/* "${WORK}"/
  602. fi
  603.  
  604. if $DEBUG;then
  605.     chmod -R a+w "${WORK}"/boot/isolinux #So regular users can edit menus
  606.     echo "    Dropping to $(whoami) prompt. Type \"exit\" to build the ISO image."
  607.     echo "    Don't do anything hasty."
  608.     echo "PS1=\"    mcd debug# \"">/tmp/mcdprompt
  609.     bash --rcfile /tmp/mcdprompt
  610.     rm /tmp/mcdprompt || true
  611. fi
  612.  
  613. if $MD5;then
  614.     echo "Generating MD5 checksums..."
  615.     if which md5sum &> /dev/null;then
  616.         MD5SUM=md5sum
  617.     else
  618.         MD5SUM=md5
  619.     fi
  620.     if $VERBOSE;then
  621.         find "${WORK}"/ -type f -not -name md5sum.txt -not -name boot.cat -not -name isolinux.bin \
  622.         -exec $MD5SUM '{}' \; | sed "s^"${WORK}"^^g" | tee "${WORK}"/md5sum.txt
  623.     else
  624.         find "${WORK}"/ -type f -not -name md5sum.txt -not -name boot.cat -not -name isolinux.bin\
  625.         -exec $MD5SUM '{}' \; | sed "s^"${WORK}"^^g" > "${WORK}"/md5sum.txt
  626.     fi
  627. fi
  628.  
  629. if which genisoimage > /dev/null;then
  630.  GENERATOR="genisoimage"
  631. elif which mkisofs > /dev/null;then
  632.  GENERATOR="mkisofs"
  633. else
  634.  echo "Neither genisoimage nor mkisofs was found."
  635.  exit 1
  636. fi
  637. EXTRAARGS=""
  638. if ! $VERBOSE;then
  639.     EXTRAARGS="$EXTRAARGS -quiet"
  640. fi
  641. if [ ! -f "${TAGS}"/win9x ];then
  642.     EXTRAARGS="$EXTRAARGS -iso-level 4" #To ensure that Windows 9x installation CDs boot properly
  643. fi
  644. echo "Building CD image..."
  645. $GENERATOR -o ""${OUTPUT}"" \
  646. -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
  647. -no-emul-boot -boot-load-size 4 -boot-info-table \
  648. -r -J $EXTRAARGS \
  649. -V "$CDLABEL" "${WORK}"/
  650. rm -rf "${WORK}"/
  651.  
  652. echo "Running isohybrid..."
  653. #if which isohybrid > /dev/null;then
  654. #   isohybrid ""${OUTPUT}"" 2> /dev/null || echo "The installed isohybrid gave an error status of $?. The ISO might not work on a flash drive."
  655. #else
  656.     "${TAGS}"/isohybrid ""${OUTPUT}"" 2> /dev/null || echo "isohybrid gave an error status of $?. The ISO might not work on a flash drive."
  657.     rm "${TAGS}"/isohybrid
  658. #fi
  659. if [ $(whoami) == "root" ];then
  660.     chmod 666 ""${OUTPUT}""
  661. fi
  662. rm -r "${TAGS}" "${MNT}"
  663.  
  664. if $TESTISO;then
  665.     RAM_FREE=$(free -m|awk 'NR == 3 {print $4}') #Current free RAM in MB, without buffers/cache
  666.     #Determine how much RAM to use. There is no science to this; I just arbitrarily chose these cutoff points.
  667.     if [ $RAM_FREE -ge 2048 ];then
  668.         RAM_TO_USE=1024
  669.     elif [ $RAM_FREE -ge 1024 ];then
  670.         RAM_TO_USE=512
  671.     elif [ $RAM_FREE -ge 512 ];then
  672.         RAM_TO_USE=256
  673.     else
  674.         RAM_TO_USE=128
  675.     fi
  676.     if which kvm &> /dev/null;then
  677.         kvm -m $RAM_TO_USE -cdrom ""${OUTPUT}""&
  678.     elif which qemu &> /dev/null;then
  679.         qemu -m $RAM_TO_USE -cdrom ""${OUTPUT}""&
  680.     else
  681.         echo "Cannot test "${OUTPUT}" in a VM. Please install qemu or qemu-kvm."
  682.     fi
  683. fi
  684.  
  685. echo "Cleaning current directory..."
  686. mcdclean
  687.  
  688. if $WAIT;then
  689.     echo "Done. Press ENTER to exit."
  690.     read
  691. fi
  692. #END SCRIPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement