install-sgx-sdk.bin.tmpl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2011-2017 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. PKG_NAME="Intel SGX SDK"
  34. select_install_path()
  35. {
  36. USER_INPUT_PATH=$(pwd)
  37. echo
  38. echo -n "Do you want to install in current directory? [yes/no] : "
  39. read ANSWER
  40. if [ "$ANSWER" == "yes" ]; then
  41. if [ ! -d "$USER_INPUT_PATH" ] || [ ! -w "$USER_INPUT_PATH" ]; then
  42. echo "Can not install in $USER_INPUT_PATH, please check the permission!"
  43. exit 4
  44. fi
  45. else
  46. echo
  47. echo -n "Please input the directory which you want to install in : "
  48. read USER_INPUT_PATH
  49. eval USER_INPUT_PATH="$USER_INPUT_PATH"
  50. if [ -d "$USER_INPUT_PATH" ]; then
  51. if [ ! -w "$USER_INPUT_PATH" ]; then
  52. echo "Can not install in $USER_INPUT_PATH, please check the permission!"
  53. exit 4
  54. fi
  55. else
  56. mkdir -p "$USER_INPUT_PATH"
  57. if [ "$?" != "0" ]; then
  58. echo "Can not install in $USER_INPUT_PATH, please check the permission!"
  59. exit 4
  60. fi
  61. fi
  62. fi
  63. }
  64. prev=
  65. for option
  66. do
  67. if test -n "$prev"; then
  68. eval $prev=\$option
  69. prev=
  70. continue
  71. fi
  72. case $option in
  73. *=?*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
  74. *=) optarg= ;;
  75. *) optarg=yes ;;
  76. esac
  77. case $option in
  78. -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
  79. prev=prefix ;;
  80. -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
  81. prefix=$optarg ;;
  82. esac
  83. done
  84. if [ -n "$prefix" ]; then
  85. eval USER_INPUT_PATH="$prefix"
  86. if [ -d "$USER_INPUT_PATH" ]; then
  87. if [ ! -w "$USER_INPUT_PATH" ]; then
  88. echo "Can not install in $USER_INPUT_PATH, please check the permission!"
  89. exit 4
  90. fi
  91. else
  92. mkdir -p "$USER_INPUT_PATH"
  93. if [ "$?" != "0" ]; then
  94. echo "Can not install in $USER_INPUT_PATH, please check the permission!"
  95. exit 4
  96. fi
  97. fi
  98. else
  99. select_install_path
  100. fi
  101. USER_INPUT_PATH=$(cd "$USER_INPUT_PATH"; pwd -P)
  102. PATH=/usr/bin:/bin
  103. umask 022
  104. SDKPKG=`mktemp -t sgx-sdk-pkg.XXXXXX`
  105. SDK_TEMP_FOLDER=`mktemp -d sgx-sdk-XXXXXX -p /tmp`
  106. trap "rm -rf $SDKPKG $SDK_TEMP_FOLDER 2>/dev/null; exit 3" HUP INT QUIT TERM
  107. # The number of lines in this script (plus 1). Using this number to
  108. # calculate the start address of the payload.
  109. NR_SCRIPT_LINES=@linenum@
  110. # Run /usr/bin/md5sum on the binary payload to get the MD5 check sum.
  111. CHKSUM=@md5sum@
  112. # Get the install payload from this shell script.
  113. echo -n "Unpacking $PKG_NAME ..."
  114. tail -n +$NR_SCRIPT_LINES "$0" > $SDKPKG
  115. echo " done."
  116. echo -n "Verifying the integrity of the install package ..."
  117. if test $(md5sum $SDKPKG | awk '{print $1}') != $CHKSUM; then
  118. echo " The install package appears to be corrupted."
  119. exit 1
  120. fi
  121. echo " done."
  122. echo -n "Installing $PKG_NAME ..."
  123. tar zxf $SDKPKG -C $SDK_TEMP_FOLDER >/dev/null 2>&1
  124. retcode=$? # Save the return code
  125. # Clean-up the temporary tarball.
  126. rm -f $SDKPKG 2>/dev/null
  127. if test $retcode -ne 0; then
  128. echo " failed."
  129. exit 2
  130. fi
  131. echo " done."
  132. pushd ${SDK_TEMP_FOLDER}
  133. sed -i "s#\(SGX_PACKAGES_PATH=\).*#\1$USER_INPUT_PATH#" scripts/installConfig
  134. source scripts/installConfig
  135. make install INSTALLER_FORM=BIN
  136. popd
  137. ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/scripts/install.sh BIN
  138. rm -fr ${SDK_TEMP_FOLDER}
  139. export_the_simulation()
  140. {
  141. if [ ! -d ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/sdk_libs ]; then
  142. mkdir ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/sdk_libs
  143. else
  144. rm -f ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/sdk_libs/libsgx_urts_sim.so
  145. rm -f ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/sdk_libs/libsgx_uae_service_sim.so
  146. fi
  147. ln -s ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/${LIB_DIR}/libsgx_urts_sim.so ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/sdk_libs/
  148. ln -s ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/${LIB_DIR}/libsgx_uae_service_sim.so ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/sdk_libs/
  149. }
  150. generate_environment_script()
  151. {
  152. cat > ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/environment <<EOF
  153. export SGX_SDK=${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}
  154. export PATH=\$PATH:\$SGX_SDK/$(dirname ${BIN_DIR}):\$SGX_SDK/${BIN_DIR}
  155. export PKG_CONFIG_PATH=\$PKG_CONFIG_PATH:\$SGX_SDK/pkgconfig
  156. if [ -z "\$LD_LIBRARY_PATH" ]; then
  157. export LD_LIBRARY_PATH=\$SGX_SDK/sdk_libs
  158. else
  159. export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:\$SGX_SDK/sdk_libs
  160. fi
  161. EOF
  162. }
  163. export_the_simulation
  164. generate_environment_script
  165. echo """
  166. Please set the environment variables with below command:
  167. "
  168. echo -e "\033[32;49;1msource ${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}/environment\033[39;49;0m"
  169. exit 0