install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. PSW_DST_PATH=${SGX_PACKAGES_PATH}/${PSW_PKG_NAME}
  36. AESM_PATH=$PSW_DST_PATH/aesm
  37. # Install the AESM service
  38. cut -d: -f1 /etc/passwd | grep -q -w aesmd || \
  39. /usr/sbin/useradd -r -c "User for aesmd" \
  40. -d /var/opt/aesmd -s /sbin/nologin aesmd
  41. mkdir -p /var/opt/aesmd
  42. cp -rf $AESM_PATH/data /var/opt/aesmd/
  43. rm -rf $AESM_PATH/data
  44. cp -rf $AESM_PATH/conf/aesmd.conf /etc/aesmd.conf
  45. rm -rf $AESM_PATH/conf
  46. chmod 0644 /etc/aesmd.conf
  47. chown -R aesmd /var/opt/aesmd
  48. chmod 0750 /var/opt/aesmd
  49. if [ -d /run/systemd/system ]; then
  50. AESMD_NAME=aesmd.service
  51. AESMD_TEMP=$AESM_PATH/$AESMD_NAME
  52. if [ -d /lib/systemd/system ]; then
  53. AESMD_DEST=/lib/systemd/system/$AESMD_NAME
  54. else
  55. AESMD_DEST=/usr/lib/systemd/system/$AESMD_NAME
  56. fi
  57. echo -n "Installing $AESMD_NAME service ..."
  58. sed -e "s:@aesm_folder@:$AESM_PATH:" \
  59. $AESMD_TEMP > $AESMD_DEST
  60. chmod 0644 $AESMD_DEST
  61. rm -f $AESMD_TEMP
  62. rm -f $AESM_PATH/aesmd.conf
  63. DISABLE_AESMD="systemctl disable aesmd"
  64. systemctl enable aesmd
  65. retval=$?
  66. elif [ -d /etc/init/ ]; then
  67. AESMD_NAME=aesmd.conf
  68. AESMD_TEMP=$AESM_PATH/$AESMD_NAME
  69. AESMD_DEST=/etc/init/$AESMD_NAME
  70. echo -n "Installing $AESMD_NAME service ..."
  71. sed -e "s:@aesm_folder@:$AESM_PATH:" \
  72. $AESMD_TEMP > $AESMD_DEST
  73. chmod 0644 $AESMD_DEST
  74. rm -f $AESMD_TEMP
  75. rm -f $AESM_PATH/aesmd.service
  76. sudo /sbin/initctl reload-configuration
  77. retval=$?
  78. else
  79. echo " failed."
  80. echo "Unsupported platform - neither systemctl nor initctl is found."
  81. exit 5
  82. fi
  83. if test $retval -ne 0; then
  84. echo "$rcmngr failed to install $AESMD_NAME."
  85. exit 6
  86. fi
  87. echo " done."
  88. cat > $PSW_DST_PATH/uninstall.sh <<EOF
  89. #!/usr/bin/env bash
  90. if test \$(id -u) -ne 0; then
  91. echo "Root privilege is required."
  92. exit 1
  93. fi
  94. # Killing AESM service
  95. sudo /usr/sbin/service aesmd stop
  96. $DISABLE_AESMD
  97. # Removing AESM configuration files
  98. rm -f $AESMD_DEST
  99. rm -f /etc/aesmd.conf
  100. # Removing AESM internal folder
  101. rm -fr /var/opt/aesmd
  102. # Removing runtime libraries
  103. rm -f /usr/lib/libsgx_uae_service.so
  104. rm -f /usr/lib/libsgx_urts.so
  105. # Removing AESM folder
  106. rm -fr $PSW_DST_PATH
  107. # Removing AESM user and group
  108. /usr/sbin/userdel aesmd
  109. EOF
  110. chmod +x $PSW_DST_PATH/uninstall.sh
  111. # Start the aesmd service
  112. if [ -d /run/systemd/system ]; then
  113. systemctl start aesmd
  114. elif [ -d /etc/init/ ]; then
  115. sudo /sbin/initctl start aesmd
  116. fi
  117. echo -e "\nuninstall.sh script generated in $PSW_DST_PATH\n"
  118. echo -e "Installation is successful!"
  119. rm -fr $PSW_DST_PATH/scripts
  120. exit 0