install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. SCRIPT_DIR=$(dirname "$0")
  34. source ${SCRIPT_DIR}/installConfig
  35. # Generate the script to preload 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-2015, 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. export PYTHONPATH=\$GDB_SGX_PLUGIN_PATH
  65. LD_PRELOAD=\$SGX_LIBRARY_PATH/libsgx_ptrace.so /usr/bin/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" "\$@"
  66. EOF
  67. chmod +x $GDB_SCRIPT
  68. }
  69. generate_gdb_script
  70. generate_uninstall_script()
  71. {
  72. cat > $SDK_DST_PATH/uninstall.sh <<EOF
  73. #!/usr/bin/env bash
  74. if test \$(id -u) -ne 0; then
  75. echo "Root privilege is required."
  76. exit 1
  77. fi
  78. # Removing the simulation runtime libraries
  79. rm -f /usr/lib/libsgx_uae_service_sim.so
  80. rm -f /usr/lib/libsgx_urts_sim.so
  81. # Removing pkg-config files
  82. rm -f /usr/lib/pkgconfig/libsgx_uae_service.pc
  83. rm -f /usr/lib/pkgconfig/libsgx_urts.pc
  84. rm -f /usr/lib/pkgconfig/libsgx_uae_service_sim.pc
  85. rm -f /usr/lib/pkgconfig/libsgx_urts_sim.pc
  86. # Removing sgx-gdb script
  87. rm -f $GDB_SCRIPT
  88. # Removing the SDK folder
  89. rm -fr $SDK_DST_PATH
  90. EOF
  91. }
  92. generate_uninstall_script_for_bin()
  93. {
  94. cat > $SDK_DST_PATH/uninstall.sh <<EOF
  95. #!/usr/bin/env bash
  96. # Removing the SDK folder
  97. rm -fr $SDK_DST_PATH 2> /dev/null
  98. if [ \$? -ne 0 ]; then
  99. echo "Superuser privilege is required."
  100. exit 1
  101. fi
  102. EOF
  103. }
  104. if [ "$1" == "BIN" ]; then
  105. generate_uninstall_script_for_bin
  106. else
  107. generate_uninstall_script
  108. fi
  109. chmod +x $SDK_DST_PATH/uninstall.sh
  110. echo -e "uninstall.sh script generated in $SDK_DST_PATH\n"
  111. echo -e "Installation is successful! The SDK package can be found in $SDK_DST_PATH"
  112. rm -fr $SDK_DST_PATH/scripts
  113. exit 0