SHARE
TWEET

Untitled

a guest Feb 2nd, 2018 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #syntax : sh create_util_usb.sh <device> <scu iso> <huu iso> <driver.iso>
  3. #example: sh create_util_usb.sh /dev/sdb scu.iso huu.iso ucs-cxxx-1.4.3-driver.iso
  4.  
  5. if [ $# -lt 2 ];then
  6.     echo "Missing argurments"
  7.     echo "syntax: sh create_util_usb.sh <device> <huu-iso-image>"
  8.     echo "example:"
  9.     echo "  sh create_util_usb.sh /dev/sdb ucs-c220m4-huu-2.0.12.31.iso"
  10.     exit 1;
  11. fi
  12.  
  13. USB_DEV=$1
  14. SCU_ISO=$2
  15.  
  16. if [ "$3" == "debug" ]; then
  17.     set -x
  18. fi
  19.  
  20. #Script input validation
  21.  
  22. if [ -z $USB_DEV ]; then
  23.     echo "Error: USB Device not provided"
  24.     exit 1;
  25. fi
  26. if [ -z $SCU_ISO ]; then
  27.     echo "Error: SCU ISO not provided"
  28.     exit 1;
  29. fi
  30.  
  31. losetup -f
  32. if [ $? -ne 0 ]; then
  33.     echo "Error: No free loop device found. "
  34.     exit 1
  35. fi
  36.  
  37. #HUU ISO name validation
  38. basename $SCU_ISO | grep -i "huu"
  39. if [ $? -ne 0 ]; then
  40.     echo "The second parameter does not look HUU iso. Do you want to proceed (y/n)?"
  41.     read ans
  42.     ans=`echo $ans | tr [:upper:] [:lower:]`
  43.     if [ $ans = "y" ]; then
  44.         echo "Proceeding..."
  45.     else
  46.         exit 1;
  47.     fi
  48. fi
  49.  
  50. TMP_TEST_DIR=/tmp/scu_test.$$
  51. mkdir -p $TMP_TEST_DIR
  52. #SCU ISO validation
  53. losetup -f
  54. if [ $? -ne 0 ]; then
  55.     echo "Error: No free loop device found. "
  56.     exit 1
  57. fi
  58.  
  59. mount -o loop $SCU_ISO $TMP_TEST_DIR
  60. if [ $? -ne 0 ]; then
  61.     echo "Error: Unable to mount SCU iso for validation"
  62.     rm -rf $TMP_TEST_DIR
  63.     exit 1;
  64. fi
  65. umount $TMP_TEST_DIR
  66.  
  67.  
  68. echo " "
  69.  
  70. rm -rf $TMP_TEST_DIR
  71.  
  72.  
  73. TMP_PART_SC=/tmp/partscr.sh
  74.  
  75. PART1_SIZE=8192
  76. PART1_DEV=$USB_DEV"1"
  77. USB_DIR=/tmp/usb2.$$
  78. MBR=/usr/lib/syslinux/mbr/mbr.bin
  79.  
  80. SYSLINUX_FILE=syslinux.cfg
  81. MENU_FILE=menu.txt
  82. TMP_SCU=/tmp/SCU
  83.  
  84. SCU_LCD_SUM=0
  85.  
  86.  
  87. create_part ()
  88. {
  89.     echo "## Creating partitions... Please wait (Will take a few minutes)"
  90.    
  91.     umount $PART1_DEV
  92.     dd if=/dev/zero of=$USB_DEV bs=4096 count=10
  93.     echo "Zeroing of USB done....."
  94. echo "d
  95. n
  96. p
  97. 1
  98.  
  99. +1024M
  100. w" | fdisk $USB_DEV
  101.    
  102.     if [ $? -ne 0 ]; then
  103.         echo "Error: Partition creation failed."
  104.         exit 1;
  105.     fi
  106.    
  107.     #Mark Partition as active
  108. echo "a
  109. 1
  110. w
  111. " | fdisk $USB_DEV
  112.    
  113.     echo "####### creating partition Done ######"
  114. }
  115.  
  116. format_part ()
  117. {
  118.     echo "###### Formating the partitions ######"
  119.     mkdosfs -F 32 $PART1_DEV
  120.     if [ $? -ne 0 ]; then
  121.         echo "Error: Formatting of first USB partition failed"
  122.         exit 1;
  123.     fi
  124.     echo "##### Formating partition Done ######"
  125. }
  126.  
  127.  
  128. add_syslinux ()
  129. {
  130.     echo "##### add_syslinux #####"
  131.     dd if=$MBR of=$USB_DEV
  132.     if [ $? -ne 0 ]; then
  133.         echo "Error: dd of mbr.bin failed ";
  134.         #rm -rf $USB_DIR
  135.         exit 1;
  136.     fi
  137.     syslinux $PART1_DEV
  138.     if [ $? -ne 0 ]; then
  139.         echo "Error: syslinux failed [ $PART1_DEV ] Failed";
  140.         #rm -rf $USB_DIR
  141.         exit 1;
  142.     fi
  143.    
  144.     echo "##### add_syslinux DONE  ######"
  145. }
  146.  
  147.  
  148. copy_files ()
  149. {
  150.     echo "##### copy_files  ######"
  151.     mkdir -p $USB_DIR
  152.     mount $PART1_DEV $USB_DIR
  153.     if [ $? -ne 0 ]; then
  154.         echo "Error: Mounting of partition [ $PART1_DEV ] on Dir [ $USB_DIR ] Failed";
  155.         rm -rf $USB_DIR
  156.         exit 1;
  157.     fi
  158.  
  159.    
  160.     mkdir -p $TMP_SCU
  161.  
  162.     losetup -f
  163.     if [ $? -ne 0 ]; then
  164.         echo "Error: No Free loop device found. Exiting";
  165.         umount $USB_DIR
  166.         rm -rf $USB_DIR
  167.         rm -rf $TMP_SCU
  168.         exit 1;
  169.        
  170.     fi
  171.    
  172.     mount -o loop $SCU_ISO $TMP_SCU
  173.     if [ $? -ne 0 ]; then
  174.         echo "Error: Mounting of SCU ISO [ $SCU_ISO ] on Dir [ $TMP_SCU ] Failed";
  175.         umount $USB_DIR
  176.         rm -rf $USB_DIR
  177.         rm -rf $TMP_SCU
  178.         exit 1;
  179.     fi
  180.  
  181.     cp -rvpf $TMP_SCU/* $USB_DIR/.
  182.     if [ $? -ne 0 ]; then
  183.         echo "Error: Copying of SCU Files to USB failedFailed";
  184.         umount $USB_DIR
  185.         rm -rf $USB_DIR
  186.         rm -rf $TMP_SCU
  187.         exit 1;
  188.     fi
  189.    
  190.     mv $USB_DIR/isolinux/ $USB_DIR/syslinux
  191.         mv $USB_DIR/syslinux/isolinux.cfg $USB_DIR/syslinux/syslinux.cfg
  192.  
  193.         # Set the UUID of SCU SD device as part of syslinuf.cfg
  194.         SCU_UUID=`blkid $PART1_DEV | cut -d" " -f2 | sed 's/\"//g'`
  195.         sed -ir "s/root=live:CDLABEL=.*-huu-[0-9]*/root=live:${SCU_UUID}/g" $USB_DIR/syslinux/syslinux.cfg 
  196.     sed -ir "s/root=live:CDLABEL=.*-huu-[0-9]*/root=live:${SCU_UUID}/g" $USB_DIR/EFI/BOOT/grub.cfg
  197.    
  198.     umount $TMP_SCU
  199.     umount $USB_DIR
  200.    
  201.     rm -rf $TMP_SCU $USB_DIR   
  202.     echo "##### copy_files Done  ######"
  203. }
  204.  
  205. #delete_part
  206. create_part
  207. format_part
  208. add_syslinux
  209. copy_files
  210.  
  211. fdisk -l $USB_DEV
  212.  
  213.  
  214. exit 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top