build-installpkg.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in
  13. # the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Intel Corporation nor the names of its
  16. # contributors may be used to endorse or promote products derived
  17. # from this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. #
  32. set -e
  33. [[ $# -eq 1 ]] || {
  34. echo "Usage : ./build-installpkg.sh sdk | psw "
  35. exit 1
  36. }
  37. [[ "$1" == "sdk" ]] || [[ "$1" == "psw" ]] || {
  38. echo "Usage : ./build-installpkg.sh sdk | psw "
  39. exit 1
  40. }
  41. INSTALLER_TYPE="$1"
  42. SCRIPT_DIR=$(dirname "$0")
  43. ROOT_DIR="${SCRIPT_DIR}/../../.."
  44. LINUX_INSTALLER_COMMON_DIR="${ROOT_DIR}/linux/installer/common"
  45. LINUX_INSTALLER_COMMON_SDK_DIR="${LINUX_INSTALLER_COMMON_DIR}/sdk"
  46. LINUX_INSTALLER_COMMON_PSW_DIR="${LINUX_INSTALLER_COMMON_DIR}/psw"
  47. # The result dir of the build
  48. BUILD_DIR=${ROOT_DIR}/build/linux
  49. # Get the architecture of the build from generated binary
  50. get_arch()
  51. {
  52. local a=$(readelf -h $BUILD_DIR/sgx_sign | sed -n '2p' | awk '/:/{print $6}')
  53. test $a = 02 && echo 'x86_64' || echo 'x86'
  54. }
  55. ARCH=$(get_arch)
  56. case $ARCH in
  57. x86_64)PACKAGE_SUFFIX="x64"
  58. ;;
  59. x86)PACKAGE_SUFFIX="x86"
  60. ;;
  61. esac
  62. case "$INSTALLER_TYPE" in
  63. psw)
  64. source ${LINUX_INSTALLER_COMMON_PSW_DIR}/installConfig.${PACKAGE_SUFFIX}
  65. ${LINUX_INSTALLER_COMMON_PSW_DIR}/createTarball.sh
  66. cp ${LINUX_INSTALLER_COMMON_PSW_DIR}/output/${TARBALL_NAME} ${SCRIPT_DIR}
  67. ;;
  68. sdk)
  69. source ${LINUX_INSTALLER_COMMON_SDK_DIR}/installConfig.${PACKAGE_SUFFIX}
  70. ${LINUX_INSTALLER_COMMON_SDK_DIR}/createTarball.sh
  71. cp ${LINUX_INSTALLER_COMMON_SDK_DIR}/output/${TARBALL_NAME} ${SCRIPT_DIR}
  72. ;;
  73. esac
  74. trap "rm -f ${SCRIPT_DIR}/$TARBALL_NAME 2>/dev/null" 0
  75. # Create the tarball and compute its MD5 check sum.
  76. m=$(md5sum ${SCRIPT_DIR}/$TARBALL_NAME | awk '{print $1}')
  77. v=$(awk '/STRFILEVER/ {print $3}' ${ROOT_DIR}/common/inc/internal/se_version.h|sed 's/^\"\(.*\)\"$/\1/')
  78. TEMPLATE_FILE=$SCRIPT_DIR/install-sgx-"$INSTALLER_TYPE".bin.tmpl
  79. INSTALLER_NAME=$SCRIPT_DIR/sgx_linux_"${PACKAGE_SUFFIX}"_"$INSTALLER_TYPE"_"$v".bin
  80. l=$(wc -l $TEMPLATE_FILE | awk '{print $1}')
  81. l=$(($l+1))
  82. sed -e "s:@linenum@:$l:" \
  83. -e "s:@md5sum@:$m:" \
  84. -e "s:@arch@:$ARCH:" \
  85. $TEMPLATE_FILE > $INSTALLER_NAME
  86. cat ${SCRIPT_DIR}/${TARBALL_NAME} >> $INSTALLER_NAME
  87. chmod +x $INSTALLER_NAME
  88. echo "Generated ${INSTALLER_TYPE} installer: $INSTALLER_NAME"
  89. exit 0