install-sgx-psw.bin.tmpl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2011-2018 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. grep intel_sgx /lib/modules/$(uname -r)/modules.builtin &> /dev/null
  33. if [[ $? != "0" ]]; then
  34. modinfo isgx &> /dev/null
  35. if [[ $? != "0" ]]; then
  36. modinfo intel_sgx &> /dev/null
  37. if [[ $? != "0" ]]; then
  38. lsmod | grep 'isgx\|intel_sgx' &> /dev/null
  39. if [[ $? = "0" ]]; then
  40. echo "Warning: You did not follow the document to install the driver package"
  41. echo
  42. else
  43. echo "Please install the driver package before the PSW package"
  44. exit 4
  45. fi
  46. fi
  47. fi
  48. fi
  49. set -e
  50. PKG_NAME="Intel SGX PSW Package"
  51. if test $(id -u) -ne 0; then
  52. echo "Root privilege is required to install $PKG_NAME."
  53. exit 4
  54. fi
  55. PKG_ARCH=@arch@
  56. ARCH=$(uname -m)
  57. if [ $ARCH == "i386" ] || [ $ARCH == "i586" ] || [ $ARCH == "i686" ]; then
  58. ARCH=x86
  59. fi
  60. if [[ $ARCH != $PKG_ARCH ]]; then
  61. echo "$PKG_ARCH $PKG_NAME can not be installed on $ARCH platform."
  62. exit 4
  63. fi
  64. INSTALL_PATH=/opt/intel/sgxpsw
  65. if [ -d "$INSTALL_PATH" ]; then
  66. echo "$PKG_NAME already exists in $INSTALL_PATH, please uninstall it first!"
  67. exit 4
  68. fi
  69. PATH=/usr/bin:/bin
  70. umask 022
  71. PSWPKG=`mktemp -t sgx-psw-pkg.XXXXXX`
  72. PSW_TEMP_FOLDER=`mktemp -d sgx-psw-XXXXXX -p /tmp`
  73. trap "rm -fr $PSWPKG $PSW_TEMP_FOLDER= 2>/dev/null; exit 3" HUP INT QUIT TERM
  74. # The number of lines in this script (plus 1). Using this number to
  75. # calculate the start address of the payload.
  76. NR_SCRIPT_LINES=@linenum@
  77. # Run /usr/bin/md5sum on the binary payload to get the MD5 check sum.
  78. CHKSUM=@md5sum@
  79. # Get the install payload from this shell script.
  80. echo -n "Unpacking $PKG_NAME ..."
  81. tail -n +$NR_SCRIPT_LINES "$0" > $PSWPKG
  82. echo " done."
  83. echo -n "Verifying the integrity of the install package ..."
  84. if test $(md5sum $PSWPKG | awk '{print $1}') != $CHKSUM; then
  85. echo " The install package appears to be corrupted."
  86. exit 1
  87. fi
  88. echo " done."
  89. echo -n "Installing $PKG_NAME ..."
  90. tar zxf $PSWPKG -C $PSW_TEMP_FOLDER >/dev/null 2>&1
  91. retcode=$? # Save the return code
  92. # Clean-up the temporary tarball.
  93. rm -f $PSWPKG 2>/dev/null
  94. if test $retcode -ne 0; then
  95. echo " failed."
  96. exit 2
  97. fi
  98. echo " done."
  99. pushd $PSW_TEMP_FOLDER
  100. source scripts/installConfig
  101. make install
  102. popd
  103. ${SGX_PACKAGES_PATH}/${PSW_PKG_NAME}/scripts/install.sh
  104. rm -fr ${PSW_TEMP_FOLDER}
  105. exit 0