Advertisement
robertgraham1906

ESXi VIB Tool

Nov 13th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.11 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ###############################################################################
  4. ## This program is free software; you can redistribute it and/or modify it
  5. ## under the terms and conditions of the GNU General Public License,
  6. ## version 2, as published by the Free Software Foundation.
  7. ##
  8. ## This program is distributed in the hope it will be useful, but WITHOUT
  9. ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  11. ## more details.
  12. ##
  13. ## You should have received a copy of the GNU General Public License along with
  14. ## this program; if not, write to the Free Software Foundation, Inc.,
  15. ## 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. ##
  17. ## The full GNU General Public License is included in this distribution in
  18. ## the file called "COPYING".
  19. ##
  20. ## Contact Information:
  21. ## Robert Graham <robertgraham1906@gmail.com>
  22. ###############################################################################
  23. ###
  24. ### @brief
  25. ### VMware ESXi 5.0+ VIB Creation Tool (for Drivers)
  26. ###############################################################################
  27. LOG_FILE=$(dirname $(readlink -f $0))/log.txt
  28. PAYLOAD_FOLDER=$(dirname $(readlink -f $0))/payload
  29. OUTPUT_DRIVER_LOCATION=$(dirname $(readlink -f $0))/stage/usr/lib/vmware/vmkmod/
  30. DRIVER_NAME="sel3390e4"
  31.  
  32. # Verify Root
  33. if [ "$(id -u)" -ne "0" ]
  34. then
  35.     echo "ERROR: This should be run as root"
  36.     exit 1
  37. fi
  38.  
  39. # Verify input params
  40. if [ -z "$2" ] || [ -n "$3" ] || [ ! -n "$(echo $2 | grep "[0-9]\.[0-9]")" ]
  41. then
  42.     echo "ERROR: incorrect input params\n"
  43.     echo "$(basename $0) <path_to_driver_file_1> <version_number>"
  44.     exit 1
  45. else
  46.     DRIVER_FILE_1=$1
  47.     VERSION=$2
  48.     VIB_NAME="$DRIVER_NAME-5.0.0-$VERSION.vib"
  49.     OUTPUT_FOLDER=$(dirname $(readlink -f $0))/bin/release/$VERSION
  50. fi
  51.  
  52. # Verify descriptor.xml file exists
  53. if [ ! -f descriptor.xml ]
  54. then
  55.     echo "ERROR: missing descriptor.xml"
  56.     exit 1
  57. fi
  58.  
  59. if [ ! -d payload ]
  60. then
  61.     echo "ERROR: missing payload directory"
  62.     exit 1
  63. fi
  64.  
  65. # Remove output folder
  66. rm -rf $OUTPUT_FOLDER
  67.  
  68. # Create output folder
  69. mkdir -p $OUTPUT_FOLDER
  70.  
  71. # Create stage folder
  72. mkdir stage
  73.  
  74. # Copy Everything in payload folder to stage
  75. cp -rf $PAYLOAD_FOLDER/* stage
  76.  
  77. # Copy Driver Files
  78. cp -f $DRIVER_FILE_1 $OUTPUT_DRIVER_LOCATION >> $LOG_FILE ||
  79.     { echo "ERROR: unable to copy $DRIVER_FILE_1" ; exit 1 ; }
  80.  
  81. # Create gzipped file
  82.  
  83. cd stage || { exit 1 ; }
  84. tar czvf ../$DRIVER_NAME.tgz * >> $LOG_FILE ||
  85.     { echo "ERROR: unable to create .gz from stage/*" ; exit 1 ; }
  86.  
  87. cd ../
  88.    
  89. # Create empty signature file
  90. touch sig.pkcs7
  91.  
  92. mkdir temp
  93. cp -f descriptor.xml temp/
  94. sed -i "s/\(<version>[0-9]\.[0-9]\.[0-9]-\)\([0-9]\.[0-9]\)\(<\/version>\)/\1$VERSION\3/g" temp/descriptor.xml
  95.  
  96. # Create vib file (ORDER IS IMPORTANT!)
  97. # descriptor.xml sig.pkcs7 tar_file
  98. ar -r $VIB_NAME temp/descriptor.xml sig.pkcs7 $DRIVER_NAME.tgz
  99.  
  100. # Move to output folder
  101. mv $VIB_NAME $OUTPUT_FOLDER
  102.  
  103. # Remove stage files
  104. rm -f sig.pkcs7
  105. rm -f $DRIVER_NAME.tgz
  106. rm -rf temp/
  107. rm -rf stage/
  108.  
  109. echo "Successfully created $OUTPUT_FOLDER/$VIB_NAME"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement