daily pastebin goal
91%
SHARE
TWEET

Untitled

texla Mar 12th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. VERSION='0.61';
  3. RELEASE_DATE='1 April 2012';
  4. LAST_GIT_COMMIT='';
  5. RETRIEVAL_DATE='';
  6. ################################################################################
  7. #                                                                              #
  8. # Copyright (c) 2009-2010      Ulrich Meierfrankenfeld                         #
  9. # Copyright (c) 2011-2012      Gert Hulselmans                                 #
  10. #                                                                              #
  11. # Permission is hereby granted, free of charge, to any person obtaining a copy #
  12. # of this software and associated documentation files (the "Software"), to     #
  13. # deal in the Software without restriction, including without limitation the   #
  14. # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  #
  15. # sell copies of the Software, and to permit persons to whom the Software is   #
  16. # furnished to do so, subject to the following conditions:                     #
  17. #                                                                              #
  18. # The above copyright notice and this permission notice shall be included in   #
  19. # all copies or substantial portions of the Software.                          #
  20. #                                                                              #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR   #
  22. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,     #
  23. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  #
  24. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER       #
  25. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      #
  26. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS #
  27. # IN THE SOFTWARE.                                                             #
  28. #                                                                              #
  29. ################################################################################
  30. #                                                                              #
  31. # Current developer:  Gert Hulselmans                                          #
  32. #                                                                              #
  33. # Past developer:     Ulrich Meierfrankenfeld (meierfra) (ubuntuforums.org)    #
  34. # Past contributor:   caljohnsmith (ubuntuforums.org)                          #
  35. #                                                                              #
  36. # Hosted at:          http://sourceforge.net/projects/bootinfoscript/          #
  37. #                                                                              #
  38. # The birth of Boot Info Script:                                               #
  39. #                     http://ubuntuforums.org/showthread.php?t=837791          #
  40. #                                                                              #
  41. # Tab width:          8 spaces                                                 #
  42. #                                                                              #
  43. ################################################################################
  44.  
  45.  
  46.  
  47. ## Check if the script is run with bash as shell interpreter.
  48.  
  49. if [ -z "$BASH_VERSION" ] ; then
  50.    echo 'Boot Info Script needs to be run with bash as shell interpreter.' >&2;
  51.    exit 1;
  52. fi
  53.  
  54.  
  55.  
  56. ## Display help text ##
  57. #
  58. #   ./bootinfoscript -h
  59. #   ./bootinfoscript -help
  60. #   ./bootinfoscript --help
  61.  
  62. help () {
  63.    cat <<- HELP
  64.    
  65.     Usage Boot Info Script:
  66.     -----------------------
  67.    
  68.       Run the script as sudoer:
  69.    
  70.         sudo ${0} <outputfile>
  71.    
  72.       or if your operating system does not use sudo:
  73.    
  74.         su -
  75.         ${0} <outputfile>
  76.    
  77.    
  78.       When running the script, without specifying an output file, all the output
  79.       is written to the file "RESULTS.txt" in the same folder as the script.
  80.    
  81.       But when run from /bin, /sbin, /usr/bin, or another system folder, the file
  82.       "RESULTS.txt" is written to the home directory of the user.
  83.    
  84.       When the file "RESULTS.txt" already exists, the results will be written to
  85.       "RESULTS1.txt". If "RESULTS1.txt" exists, the results will be written to
  86.       "RESULTS2.txt", ...
  87.    
  88.    
  89.       To get version number, release date, last git commit and git retrieval date
  90.       of this script, use (no root rights needed):
  91.    
  92.         ${0} -v
  93.         ${0} -V
  94.         ${0} --version
  95.    
  96.    
  97.       To get this help text, use (no root rights needed):
  98.    
  99.         ${0} -h
  100.         ${0} -help
  101.         ${0} --help
  102.    
  103.        
  104.       To automatically gzip a copy of the output file, use (root rights needed):
  105.    
  106.         ${0} -g <outputfile>
  107.         ${0} --gzip <outputfile>
  108.    
  109.        
  110.       To write the output to stdout instead of a file, use (root rights needed):
  111.    
  112.         ${0} --stdout
  113.    
  114.    
  115.       The last development version of Boot Info Script can be downloaded, with:
  116.         (no root rights needed)
  117.    
  118.         ${0} --update <filename>
  119.    
  120.       If no filename is specified, the file will be saved in the home dir as
  121.       "bootinfoscript_YYYY-MM-DD_hh:mm:ss".
  122.    
  123.    
  124.       If multiple versions of Boot Info Script are detected in the same directory,
  125.       Boot Info Script will list all versions found.
  126.       In that case you need to force Boot Info Script to run a certain version,
  127.       by adding "--this" as first argument (root rights needed):
  128.    
  129.         ${0} --this <outputfile>
  130.    
  131.     HELP
  132.  
  133.    exit 0;
  134. }
  135.  
  136.  
  137.  
  138. ## Download the last development version of BIS from git: ##
  139. #
  140. #   ./bootinfoscript --update <filename>
  141. #
  142. #   If no filename is specified, the file will be saved in the home dir as
  143. #   "bootinfoscript_YYYY-MM-DD_hh:mm:ss".
  144.  
  145. update () {
  146.   local git_bis_url='http://bootinfoscript.git.sourceforge.net/git/gitweb.cgi?p=bootinfoscript/bootinfoscript;a=blob_plain;f=bootinfoscript;hb=HEAD';
  147.   local git_commit_url='http://bootinfoscript.sourceforge.net/bis-last-commit.txt'
  148.  
  149.   # Check if date is available.
  150.   if [ $(type date > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
  151.      echo '"date" could not be found.' >&2;
  152.      exit 1;
  153.   fi
  154.  
  155.   # Get current UTC time in YYYY-MM-DD-hh:mm:ss format.
  156.   UTC_TIME=$(date --utc "+%Y-%m-%d %T");
  157.  
  158.   if [ ! -z "$1" ] ; then
  159.      GIT_BIS_FILENAME="$1";
  160.   else
  161.      GIT_BIS_FILENAME="${HOME}/bootinfoscript_${UTC_TIME/ /_}"
  162.   fi
  163.  
  164.   # Check if wget or curl is available
  165.   if [ $(type wget > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
  166.      printf '\nDownloading last development version of Boot Info Script from git:\n\n';
  167.      wget -O "${GIT_BIS_FILENAME}" "${git_bis_url}";
  168.      LAST_GIT_COMMIT=$(wget -O - "${git_commit_url}" 2> /dev/null);
  169.   elif [ $(type curl > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
  170.      printf 'Downloading last development version of Boot Info Script from git:\n\n';
  171.      curl -o "${GIT_BIS_FILENAME}" "${git_bis_url}";
  172.      LAST_GIT_COMMIT=$(curl "${git_commit_url}");
  173.   else
  174.      printf '"wget" or "curl" could not be found.\nInstall at least one of them and try again.\n' >&2;
  175.      exit 1;
  176.   fi
  177.  
  178.   # Set the retrieval date in just downloaded script.
  179.   sed -i -e "4,0 s@LAST_GIT_COMMIT='';@LAST_GIT_COMMIT='${LAST_GIT_COMMIT}';@" \
  180.      -e "5,0 s/RETRIEVAL_DATE='';/RETRIEVAL_DATE='${UTC_TIME}';/" \
  181.      "${GIT_BIS_FILENAME}";
  182.  
  183.   printf '\nThe development version of Boot Info Script is saved as:\n"%s"\n\n' "${GIT_BIS_FILENAME}";
  184.   exit 0;
  185. }
  186.  
  187.  
  188.  
  189. ## Display version, release, last git commit and git retrieval date of the script when asked: ##
  190. #
  191. #   ./bootinfoscript -v
  192. #   ./bootinfoscript -V
  193. #   ./bootinfoscript --version
  194.  
  195. version () {
  196.   printf '\nBoot Info Script version: %s\nRelease date:             %s' "${VERSION}" "${RELEASE_DATE}";
  197.  
  198.   if [ ! -z "${LAST_GIT_COMMIT}" ] ; then
  199.      printf '\nLast git commit:          %s\nRetrieved from git on:    %s' "${LAST_GIT_COMMIT}" "${RETRIEVAL_DATE}";
  200.   fi
  201.  
  202.   printf '\n\n';
  203.  
  204.   exit 0;
  205. }
  206.  
  207.  
  208.  
  209. ## Run this version of BIS even when multiple versions are detected in the same directory?
  210. this_BIS=0;  # no=0
  211.  
  212. ## Gzip a copy of the output file? ##
  213. gzip_output=0;   # off=0
  214.  
  215. ## Write the output to the standard output instead of to a file? ##
  216. stdout_output=0; # off=0
  217.  
  218.  
  219.  
  220. ## Get arguments passed to the script. ##
  221.  
  222. process_args () {
  223.   if [ ${#@} -ge 1 ] ; then
  224.      if [ $1 = '--this' ] ; then
  225.     this_BIS=1; # run this version of BIS even if multiple versions are detected.
  226.  
  227.     if [ ${#@} -ge 2 ] ; then
  228.        shift;   # shift the command line parameters ($2 -> $1), so they can be processed.
  229.     else
  230.        return 0;    # exit this function when only '--this' was passed.
  231.     fi
  232.      fi
  233.  
  234.      # Process other arguments.
  235.      case "$1" insudo
  236.     -g    ) gzip_output=1; if [ ! -z "$2" ] ; then LogFile_cmd="$2"; fi;;
  237.     --gzip    ) gzip_output=1; if [ ! -z "$2" ] ; then LogFile_cmd="$2"; fi;;
  238.     -h    ) help;;
  239.     -help     ) help;;
  240.     --help    ) help;;
  241.     --stdout  ) stdout_output=1;;
  242.     --update  ) update "$2";;
  243.     -v    ) version;;
  244.     -V    ) version;;
  245.     --version ) version;;
  246.     -*    ) help;;
  247.     *     ) LogFile_cmd="$1";;
  248.      esac
  249.   fi
  250. }
  251.  
  252.  
  253.  
  254.  
  255. ## Get arguments passed to the script. ##
  256.  
  257. process_args ${@};
  258.  
  259.  
  260.  
  261. ## Display version number, release and git retrieval date. ##
  262.  
  263. printf '\nBoot Info Script %s      [%s]' "${VERSION}" "${RELEASE_DATE}";
  264.  
  265. if [ ! -z "${LAST_GIT_COMMIT}" ] ; then
  266.    printf '\n  Last git commit:         %s\n  Retrieved from git on:   %s' "${LAST_GIT_COMMIT}" "${RETRIEVAL_DATE}";
  267. fi
  268.  
  269. printf '\n\n';
  270.  
  271.  
  272.  
  273. ## Check whether Boot Info Script is run with root rights or not. ##
  274.  
  275. if [ $(type whoami > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
  276.    echo 'Please install "whoami" and run Boot Info Script again.' >&2;
  277.    exit 1;
  278. elif [ $(whoami) != 'root' ] ; then
  279.    cat <<- EOF >&2
  280.     Please use "sudo" or become "root" to run this script.
  281.    
  282.       Run the script as sudoer:
  283.    
  284.         sudo ${0} <outputfile>
  285.    
  286.       or if your operating system does not use sudo:
  287.    
  288.         su -
  289.         ${0} <outputfile>
  290.  
  291.     For more info, see the help:
  292.  
  293.         ${0} --help
  294.    
  295.     EOF
  296.    exit 1;
  297. fi
  298.  
  299.  
  300.  
  301. ## Check if all necessary programs are available. ##
  302.  
  303. # Programs that are in /bin or /usr/bin.
  304. Programs='
  305.     basename
  306.     cat
  307.     chown
  308.     dd
  309.     dirname
  310.     expr
  311.     fold
  312.     grep
  313.     gzip
  314.     hexdump
  315.     ls
  316.     mkdir
  317.     mktemp
  318.     mount
  319.     printf
  320.     pwd
  321.     rm
  322.     sed
  323.     sort
  324.     umount
  325.     wc'
  326.  
  327. # Programs that are in /usr/sbin or /sbin.
  328. Programs_SBIN='
  329.     blkid
  330.     fdisk
  331.     filefrag
  332.     losetup'
  333.  
  334.  
  335. Check_Prog=1;
  336.  
  337. for Program in ${Programs} ${Programs_SBIN}; do
  338.   if [ $(type ${Program} > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
  339.      echo "\"${Program}\" could not be found." >&2;
  340.      Check_Prog=0;
  341.   fi
  342. done
  343.  
  344.  
  345.  
  346. ## Can we decompress a LZMA stream? ##
  347. #
  348. #   The Grub2 (v1.99) core_dir string is contained in a LZMA stream.
  349. #   See if we have xz or lzma installed to decompress the stream.
  350. #
  351.  
  352. if [ $(type xz > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
  353.    UNLZMA='xz --format=lzma --decompress';
  354. elif [ $(type lzma > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
  355.    UNLZMA='lzma -cd';
  356. else
  357.    UNLZMA='none';
  358. fi
  359.  
  360.  
  361.  
  362. ## Do we have gawk? ##
  363. #
  364. #   If we don't have gawk, look for "busybox awk".
  365. #
  366.  
  367. # Make a variable named ${TAB}, needed for setting the separator for awk to a tab.
  368. TAB=$(printf "\t");
  369.  
  370. # Set awk binary to gawk.
  371. AWK='gawk';
  372.  
  373.  
  374. if [ $(type gawk > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
  375.    # Do we have a busybox version?
  376.    for BUSYBOX in 'busybox' '/usr/lib/initramfs-tools/bin/busybox' ; do
  377.      # And if we have one, does is support "awk"?
  378.      if [ $(type ${BUSYBOX} > /dev/null 2>&1 ; echo $?) -eq 0 ] && [ $(echo 'test' | ${BUSYBOX} awk '{ print $0 }' > /dev/null 2>&1; echo $?) -eq 0 ] ; then
  379.     printf '\n"gawk" could not be found, using "%s awk" instead.\nThis may lead to unreliable results.\n\n' "${BUSYBOX}" >&2;
  380.  
  381.     # Set awk binary to busybox's awk.
  382.     AWK="${BUSYBOX} awk";
  383.     break;
  384.      fi
  385.    done
  386.  
  387.    # If no busybox (or one without awk support) is found, "${AWK}" is still set to "gawk".
  388.    if [ "${AWK}" == 'gawk' ] ; then
  389.       echo '"gawk" could not be found.' >&2;
  390.       Check_Prog=0;
  391.    fi
  392. fi
  393.  
  394.  
  395.  
  396. if [ ${Check_Prog} -eq 0 ] ; then
  397.    printf '\nPlease install the missing program(s) and run Boot Info Script again.\n' >&2;
  398.    exit 1;
  399. fi
  400.  
  401.  
  402.  
  403. ## Check if there are other bootinfoscript files in the same directory. ##
  404. #
  405. #   This can be useful when BIS was downloaded multiple times with Firefox, Chromium, ...
  406. #   Those browsers will add a suffix to the filename, when there was already
  407. #   a file with the same name:
  408. #
  409. #     bootinfoscript(<number>)
  410. #
  411. #   To force BIS to run a certain version, add "--this" as first argument:
  412. #
  413. #     ./bootinfoscript --this <outputfile>
  414. #
  415.  
  416. if [ ${this_BIS} -eq 0 ] ; then
  417.    declare -a BIS_files;
  418.  
  419.    BIS_files=( $(ls "$(dirname "$0")/bootinfoscript" "$(dirname \"$0\")"/bootinfoscript\(*\) 2> /dev/null) );
  420.  
  421.    if [ "${#BIS_files[*]}" -ge 2 ] ; then
  422.       printf 'Multiple bootinfoscript files where found:\n\n';
  423.  
  424.       for i in ${!BIS_files[@]} ; do
  425.     eval $(echo 'BIS_'$(grep -m1 '^VERSION' "${BIS_files[$i]}") );
  426.     printf "  - ${BIS_files[$i]}:\tversion ${BIS_VERSION}\n";
  427.       done
  428.  
  429.       printf '\nAre you sure you want to run this version? If so, run:\n\n  %s --this %s\n\n' "$0" "$*";
  430.       exit 1;
  431.    fi
  432. fi
  433.  
  434.  
  435.  
  436. ## List of folders which might contain files used for chainloading. ##
  437.  
  438. Boot_Codes_Dir='
  439.     /
  440.     /NST/
  441.     '
  442.  
  443.  
  444.  
  445. ## List of files whose names will be displayed, if found. ##
  446.  
  447. Boot_Prog_Normal='
  448.     /bootmgr    /BOOTMGR
  449.     /boot/bcd   /BOOT/bcd   /Boot/bcd   /boot/BCD   /BOOT/BCD   /Boot/BCD
  450.     /Windows/System32/winload.exe   /WINDOWS/system32/winload.exe   /WINDOWS/SYSTEM32/winload.exe   /windows/system32/winload.exe
  451.     /Windows/System32/Winload.exe   /WINDOWS/system32/Winload.exe   /WINDOWS/SYSTEM32/Winload.exe   /windows/system32/Winload.exe
  452.     /grldr      /GRLDR      /grldr.mbr  /GRLDR.MBR
  453.     /ntldr      /NTLDR
  454.     /NTDETECT.COM   /ntdetect.com
  455.     /NTBOOTDD.SYS   /ntbootdd.sys
  456.     /wubildr    /ubuntu/winboot/wubildr
  457.     /wubildr.mbr    /ubuntu/winboot/wubildr.mbr
  458.     /ubuntu/disks/root.disk
  459.     /ubuntu/disks/home.disk
  460.     /ubuntu/disks/swap.disk
  461.     /core.img   /grub/core.img      /boot/grub/core.img /grub2/core.img /boot/grub2/core.img
  462.     /burg/core.img  /boot/burg/core.img
  463.     /ldlinux.sys    /syslinux/ldlinux.sys   /boot/syslinux/ldlinux.sys
  464.     /extlinux.sys   /extlinux/extlinux.sys  /boot/extlinux/extlinux.sys
  465.     /boot/map   /map
  466.     /DEFAULT.MNU    /default.mnu
  467.     /IO.SYS     /io.sys
  468.     /MSDOS.SYS  /msdos.sys
  469.     /KERNEL.SYS /kernel.sys
  470.     /DELLBIO.BIN    /dellbio.bin        /DELLRMK.BIN    /dellrmk.bin
  471.     /COMMAND.COM    /command.com
  472.     '
  473.  
  474. Boot_Prog_Fat='
  475.     /bootmgr
  476.     /boot/bcd
  477.     /Windows/System32/winload.exe
  478.     /grldr
  479.     /grldr.mbr
  480.     /ntldr
  481.     /freeldr.sys
  482.     /NTDETECT.COM
  483.     /NTBOOTDD.SYS
  484.     /wubildr
  485.     /wubildr.mbr
  486.     /ubuntu/winboot/wubildr
  487.     /ubuntu/winboot/wubildr.mbr
  488.     /ubuntu/disks/root.disk
  489.     /ubuntu/disks/home.disk
  490.     /ubuntu/disks/swap.disk
  491.     /core.img   /grub/core.img      /boot/grub/core.img /grub2/core.img /boot/grub2/core.img
  492.     /burg/core.img  /boot/burg/core.img
  493.     /ldlinux.sys    /syslinux/ldlinux.sys   /boot/syslinux/ldlinux.sys
  494.     /extlinux.sys   /extlinux/extlinux.sys  /boot/extlinux/extlinux.sys
  495.     /boot/map   /map
  496.     /DEFAULT.MNU
  497.     /IO.SYS
  498.     /MSDOS.SYS
  499.     /KERNEL.SYS
  500.     /DELLBIO.BIN    /DELLRMK.BIN
  501.     /COMMAND.COM
  502.     '
  503.  
  504.  
  505.  
  506. ## List of files whose contents will be displayed. ##
  507.  
  508. Boot_Files_Normal='
  509.     /menu.lst   /grub/menu.lst  /boot/grub/menu.lst /NST/menu.lst  
  510.     /grub.cfg   /grub/grub.cfg  /boot/grub/grub.cfg /grub2/grub.cfg /boot/grub2/grub.cfg
  511.     /burg.cfg   /burg/burg.cfg  /boot/burg/burg.cfg
  512.     /grub.conf  /grub/grub.conf /boot/grub/grub.conf    /grub2/grub.conf    /boot/grub2/grub.conf
  513.     /ubuntu/disks/boot/grub/menu.lst    /ubuntu/disks/install/boot/grub/menu.lst    /ubuntu/winboot/menu.lst
  514.     /boot.ini   /BOOT.INI
  515.     /etc/fstab
  516.     /etc/lilo.conf  /lilo.conf
  517.     /syslinux.cfg   /syslinux/syslinux.cfg  /boot/syslinux/syslinux.cfg
  518.     /extlinux.conf  /extlinux/extlinux.conf /boot/extlinux/extlinux.conf
  519.     /grldr      /grub.exe
  520.     '
  521.  
  522. Boot_Files_Fat='
  523.     /menu.lst   /grub/menu.lst  /boot/grub/menu.lst /NST/menu.lst
  524.     /grub.cfg   /grub/grub.cfg  /boot/grub/grub.cfg /grub2/grub.cfg /boot/grub2/grub.cfg
  525.     /burg.cfg   /burg/burg.cfg  /boot/burg/burg.cfg
  526.     /grub.conf  /grub/grub.conf /boot/grub/grub.conf    /grub2/grub.conf    /boot/grub2/grub.conf
  527.     /ubuntu/disks/boot/grub/menu.lst    /ubuntu/disks/install/boot/grub/menu.lst    /ubuntu/winboot/menu.lst
  528.     /boot.ini
  529.     /freeldr.ini
  530.     /etc/fstab
  531.     /etc/lilo.conf  /lilo.conf
  532.     /syslinux.cfg   /syslinux/syslinux.cfg  /boot/syslinux/syslinux.cfg
  533.     /extlinux.conf  /extlinux/extlinux.conf /boot/extlinux/extlinux.conf
  534.     /grldr      /grub.exe
  535.     '
  536.  
  537.  
  538. ## List of files whose end point (in GiB / GB) will be displayed. ##
  539.  
  540. GrubError18_Files='
  541.     menu.lst    grub/menu.lst   boot/grub/menu.lst  NST/menu.lst
  542.     ubuntu/disks/boot/grub/menu.lst
  543.     grub.conf   grub/grub.conf  boot/grub/grub.conf grub2/grub.conf boot/grub2/grub.conf
  544.     grub.cfg    grub/grub.cfg   boot/grub/grub.cfg  grub2/grub.cfg  boot/grub2/grub.cfg
  545.     burg.cfg    burg/burg.cfg   boot/burg/burg.cfg
  546.     core.img    grub/core.img   boot/grub/core.img  grub2/core.img  boot/grub2/core.img
  547.     burg/core.img   boot/burg/core.img
  548.     stage2      grub/stage2 boot/grub/stage2
  549.     boot/vmlinuz*   vmlinuz*    ubuntu/disks/boot/vmlinuz*
  550.     boot/initrd*    initrd*     ubuntu/disks/boot/initrd*
  551.     boot/kernel*.img
  552.     initramfs*  boot/initramfs*
  553.     '
  554.  
  555. SyslinuxError_Files='
  556.     syslinux.cfg    syslinux/syslinux.cfg   boot/syslinux/syslinux.cfg
  557.     extlinux.conf   extlinux/extlinux.conf  boot/extlinux/extlinux.conf
  558.     ldlinux.sys syslinux/ldlinux.sys    boot/syslinux/ldlinux.sys
  559.     extlinux.sys    extlinux/extlinux.sys   boot/extlinux/extlinux.sys
  560.     *.c32       syslinux/*.c32          boot/syslinux/*.c32
  561.     extlinux/*.c32  boot/extlinux/*.c32
  562.     '
  563.  
  564.  
  565.  
  566. ## Set output filename ##
  567.  
  568. if [ ${stdout_output} -eq 1 ] ; then
  569.   # The LogFile name is not used when --stdout is specified.
  570.   LogFile="";
  571. elif ( [ ! -z "${LogFile_cmd}" ]) ; then
  572.   # The RESULTS filename is specified on the commandline.
  573.   LogFile=$(basename "${LogFile_cmd}");
  574.  
  575.   # Directory where the RESULTS file will be stored.
  576.   Dir=$(dirname "${LogFile_cmd}");
  577.  
  578.   # Check if directory exists.
  579.   if [ ! -d "${Dir}" ] ; then
  580.      echo "The directory \"${Dir}\" does not exist.";
  581.      echo 'Create the directory or specify another path for the output file.';
  582.      exit 1;
  583.   fi
  584.  
  585.   Dir=$(cd "${Dir}"; pwd);
  586.   LogFile="${Dir}/${LogFile}";
  587. else
  588.   # Directory containing this script.
  589.   Dir=$(cd "$(dirname "$0")"; pwd);
  590.  
  591.   # Set ${Dir} to the home folder of the current user if the script is
  592.   # in one of the system folders.
  593.   # This allows placement of the script in /bin, /sbin, /usr/bin, ...
  594.   # while still having a normal location to write the output file to.
  595.  
  596.   for systemdir in /bin /boot /cdrom /dev /etc /lib /lost+found /opt /proc /sbin /selinux /srv /sys /usr /var; do
  597.     if [ $(expr "${Dir}" : ${systemdir}) -ne 0 ] ; then
  598.        Dir="${HOME}";
  599.        break;
  600.     fi
  601.   done
  602.  
  603.   # To avoid overwriting existing files, look for a non-existing file:
  604.   # RESULT.txt, RESULTS1.txt, RESULTS2.txt, ...
  605.  
  606.   LogFile="${Dir}/RESULTS";
  607.  
  608.   while ( [ -e "${LogFile}${j}.txt" ] ) ; do
  609.     if [ x"${j}" = x'' ]; then
  610.        j=0;
  611.     fi
  612.     j=$((${j}+1));
  613.     wait;
  614.   done
  615.  
  616.   LogFile="${LogFile}${j}.txt";  ## The RESULTS file. ##
  617. fi
  618.  
  619.  
  620.  
  621. ## Redirect stdout to RESULT File ##
  622. #
  623. #   exec 6>&1  
  624. #   exec > "${LogFile}"
  625.  
  626.  
  627.  
  628. ## Create temporary directory ##
  629.  
  630. Folder=$(mktemp -t -d BootInfo-XXXXXXXX);
  631.  
  632.  
  633.  
  634. ## Create temporary filenames. ##
  635.  
  636. cd ${Folder}
  637. Log=${Folder}/Log               # File to record the summary.
  638. Log1=${Folder}/Log1             # Most of the information which is not part of
  639.                         # the summary is recorded in this file.
  640. Error_Log=${Folder}/Error_Log           # File to catch all unusal Standar Errors.
  641. Trash=${Folder}/Trash               # File to catch all usual Standard Errors these
  642.                         # messagges will not be included in the RESULTS.
  643. Mount_Error=${Folder}/Mount_Error       # File to catch Mounting Errors.
  644. Unknown_MBR=${Folder}/Unknown_MBR       # File to record all unknown MBR and Boot sectors.
  645. Tmp_Log=${Folder}/Tmp_Log           # File to temporarily hold some information.
  646. core_img_file=${Folder}/core_img        # File to temporarily store an embedded core.img of grub2.
  647. core_img_file_unlzma=${Folder}/core_img_unlzma  # File to temporarily store the uncompressed part of core.img of grub2.
  648. PartitionTable=${Folder}/PT         # File to store the Partition Table.
  649. FakeHardDrives=${Folder}/FakeHD         # File to list devices which seem to have  no corresponding drive.
  650. BLKID=${Folder}/BLKID               # File to store the output of blkid.
  651.  
  652.  
  653.  
  654. ## Redirect all standard error to the file Error_Log. ##
  655.  
  656. exec 2> ${Error_Log};
  657.  
  658.  
  659.  
  660. ## List of all hard drives ##
  661. #
  662. #   Support more than 26 drives.
  663.  
  664. All_Hard_Drives=$(ls /dev/hd[a-z] /dev/hd[a-z][a-z] /dev/sd[a-z] /dev/sd[a-z][a-z] 2>> ${Trash});
  665.  
  666.  
  667. ## Add found RAID disks to list of hard drives. ##
  668.  
  669. if [ $(type dmraid >> ${Trash} 2>> ${Trash} ; echo $?) -eq 0 ] ; then
  670.   InActiveDMRaid=$(dmraid -si -c);
  671.  
  672.   if [ x"${InActiveDMRaid}" = x"no raid disks" ] ; then
  673.      InActiveDMRaid='';
  674.   fi
  675.  
  676.   if [ x"${InActiveDMRaid}" != x'' ] ; then
  677.      dmraid -ay ${InActiveDMRaid} >> ${Trash};
  678.   fi
  679.  
  680.   if [ x"$(dmraid -sa -c)" != x"no raid disks" ] ; then
  681.      All_DMRaid=$(dmraid -sa -c | ${AWK} '{ print "/dev/mapper/"$0 }');
  682.      All_Hard_Drives="${All_Hard_Drives} ${All_DMRaid}";
  683.   fi  
  684. fi
  685.  
  686.  
  687.  
  688. ## Arrays to hold information about Partitions: ##
  689. #
  690. #   name, starting sector, ending sector, size in sector, partition type,
  691. #   filesystem type, UUID, kind(Logical, Primary, Extended), harddrive,
  692. #   boot flag,  parent (for logical partitions), label,
  693. #   system(the partition id according the partition table),
  694. #   the device associated with the partition.
  695.  
  696. declare -a NamesArray StartArray EndArray SizeArray TypeArray  FileArray UUIDArray KindArray DriveArray BootArray ParentArray LabelArray SystemArray DeviceArray;
  697.  
  698.  
  699. ## Arrays to hold information about the harddrives. ##
  700.  
  701. declare -a HDName FirstPartion LastPartition HDSize HDMBR HDHead HDTrack HDCylinder HDPT HDStart HDEnd HDUUID;
  702.  
  703.  
  704. ## Array for hard drives formatted as filesystem. ##
  705.  
  706. declare -a FilesystemDrives;
  707.  
  708.  
  709.  
  710. PI=-1;  ## Counter for the identification number of a partition.   (each partition gets unique number)   ##
  711. HI=0;   ## Counter for the identification number of a hard drive.  (each hard drive gets unique number)  ##
  712. PTFormat='%-10s %4s%14s%14s%14s %3s %s\n';  ## standard format (hexdump) to use for partition table. ##
  713.  
  714.  
  715.  
  716. ## Get total number of blocks on a device. ##
  717. #
  718. #   Sometimes "fdisk -s" seems to malfunction or isn't supported (busybox fdisk),
  719. #   so use "sfdisk -s" if available.
  720. #   If sfdisk isn't available, calculate the number of blocks from the number of
  721. #   sectors (divide by 2).
  722.  
  723. fdisks () {
  724.   if [ $(type sfdisk >> ${Trash} 2>> ${Trash} ; echo $?) -eq 0 ] ; then
  725.      sfdisk -s "$1" 2>> ${Trash};
  726.   else
  727.      # Calculate the number of blocks from the number of sectors (divide by 2).
  728.      fdisk -lu "$1" 2>> ${Trash} | awk '$0 ~ /, .*, .*, .*/ { print $(NF - 1) / 2 }';
  729.   fi
  730. }
RAW Paste Data
Top