install.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. SCRIPT_DIR=$(dirname "$0")
  34. source ${SCRIPT_DIR}/installConfig
  35. # Generate the script to preload Intel(R) SGX ptrace library for gdb
  36. SDK_DST_PATH=${SGX_PACKAGES_PATH}/${SDK_PKG_NAME}
  37. SDK_LIB_PATH=${SDK_DST_PATH}/${LIB_DIR}
  38. if [ "$1" == "BIN" ]; then
  39. GDB_SCRIPT=${SDK_DST_PATH}/bin/sgx-gdb
  40. else
  41. GDB_SCRIPT=/usr/bin/sgx-gdb
  42. fi
  43. generate_gdb_script()
  44. {
  45. cat > $GDB_SCRIPT <<EOF
  46. #!/usr/bin/env bash
  47. #
  48. # Copyright (c) 2011-2017, Intel Corporation.
  49. #
  50. # Licensed under the Apache License, Version 2.0 (the "License");
  51. # you may not use this file except in compliance with the License.
  52. # You may obtain a copy of the License at
  53. #
  54. # http://www.apache.org/licenses/LICENSE-2.0
  55. #
  56. # Unless required by applicable law or agreed to in writing, software
  57. # distributed under the License is distributed on an "AS IS" BASIS,
  58. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  59. # See the License for the specific language governing permissions and
  60. # limitations under the License
  61. shopt -s expand_aliases
  62. GDB_SGX_PLUGIN_PATH=$SDK_LIB_PATH/gdb-sgx-plugin
  63. SGX_LIBRARY_PATH=$SDK_LIB_PATH
  64. if [ -f /usr/local/bin/gdb ]
  65. then
  66. GDB=/usr/local/bin/gdb
  67. elif [ -f /usr/bin/gdb ]
  68. then
  69. GDB=/usr/bin/gdb
  70. else
  71. GDB=gdb
  72. fi
  73. export PYTHONPATH=\$GDB_SGX_PLUGIN_PATH
  74. LD_PRELOAD=\$SGX_LIBRARY_PATH/libsgx_ptrace.so \$GDB -iex "directory \$GDB_SGX_PLUGIN_PATH" -iex "source \$GDB_SGX_PLUGIN_PATH/gdb_sgx_plugin.py" -iex "set environment LD_PRELOAD" -iex "add-auto-load-safe-path /usr/lib" "\$@"
  75. EOF
  76. chmod +x $GDB_SCRIPT
  77. }
  78. generate_gdb_script
  79. generate_uninstall_script()
  80. {
  81. cat > $SDK_DST_PATH/uninstall.sh <<EOF
  82. #!/usr/bin/env bash
  83. if test \$(id -u) -ne 0; then
  84. echo "Root privilege is required."
  85. exit 1
  86. fi
  87. # Removing the simulation runtime libraries
  88. rm -f /usr/lib/libsgx_uae_service_sim.so
  89. rm -f /usr/lib/libsgx_urts_sim.so
  90. # Removing pkg-config files
  91. rm -f /usr/lib/pkgconfig/libsgx_uae_service.pc
  92. rm -f /usr/lib/pkgconfig/libsgx_urts.pc
  93. rm -f /usr/lib/pkgconfig/libsgx_uae_service_sim.pc
  94. rm -f /usr/lib/pkgconfig/libsgx_urts_sim.pc
  95. # Removing sgx-gdb script
  96. rm -f $GDB_SCRIPT
  97. # Removing the SDK folder
  98. rm -fr $SDK_DST_PATH
  99. EOF
  100. }
  101. generate_uninstall_script_for_bin()
  102. {
  103. cat > $SDK_DST_PATH/uninstall.sh <<EOF
  104. #!/usr/bin/env bash
  105. # Removing the SDK folder
  106. rm -fr $SDK_DST_PATH 2> /dev/null
  107. if [ \$? -ne 0 ]; then
  108. echo "Superuser privilege is required."
  109. exit 1
  110. fi
  111. echo "Intel(R) SGX SDK uninstalled."
  112. EOF
  113. }
  114. if [ "$1" == "BIN" ]; then
  115. generate_uninstall_script_for_bin
  116. else
  117. generate_uninstall_script
  118. fi
  119. chmod +x $SDK_DST_PATH/uninstall.sh
  120. echo -e "uninstall.sh script generated in $SDK_DST_PATH\n"
  121. echo -e "Installation is successful! The SDK package can be found in $SDK_DST_PATH"
  122. rm -fr $SDK_DST_PATH/scripts
  123. exit 0