install.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. 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. # By default the AESM's communication socket will be created in
  50. # /var/run/aesmd. Putting the socket in the aesmd sub-directory
  51. # as opposed to directly in /var/run allows the user to create a
  52. # mount a volume at /var/run/aesmd and thus expose the socket to
  53. # a different filesystem or namespace, e.g. a Docker container.
  54. mkdir -p /var/run/aesmd
  55. chown -R aesmd /var/run/aesmd
  56. chmod 0755 /var/run/aesmd
  57. if [ -d /run/systemd/system ]; then
  58. AESMD_NAME=aesmd.service
  59. AESMD_TEMP=$AESM_PATH/$AESMD_NAME
  60. if [ -d /lib/systemd/system ]; then
  61. AESMD_DEST=/lib/systemd/system/$AESMD_NAME
  62. else
  63. AESMD_DEST=/usr/lib/systemd/system/$AESMD_NAME
  64. fi
  65. echo -n "Installing $AESMD_NAME service ..."
  66. sed -e "s:@aesm_folder@:$AESM_PATH:" \
  67. $AESMD_TEMP > $AESMD_DEST
  68. chmod 0644 $AESMD_DEST
  69. rm -f $AESMD_TEMP
  70. rm -f $AESM_PATH/aesmd.conf
  71. DISABLE_AESMD="systemctl disable aesmd"
  72. systemctl enable aesmd
  73. retval=$?
  74. elif [ -d /etc/init/ ]; then
  75. AESMD_NAME=aesmd.conf
  76. AESMD_TEMP=$AESM_PATH/$AESMD_NAME
  77. AESMD_DEST=/etc/init/$AESMD_NAME
  78. echo -n "Installing $AESMD_NAME service ..."
  79. sed -e "s:@aesm_folder@:$AESM_PATH:" \
  80. $AESMD_TEMP > $AESMD_DEST
  81. chmod 0644 $AESMD_DEST
  82. rm -f $AESMD_TEMP
  83. rm -f $AESM_PATH/aesmd.service
  84. /sbin/initctl reload-configuration
  85. retval=$?
  86. else
  87. echo " failed."
  88. echo "Unsupported platform - neither systemctl nor initctl is found."
  89. exit 5
  90. fi
  91. if test $retval -ne 0; then
  92. echo "$rcmngr failed to install $AESMD_NAME."
  93. exit 6
  94. fi
  95. echo " done."
  96. cat > $PSW_DST_PATH/uninstall.sh <<EOF
  97. #!/usr/bin/env bash
  98. if test \$(id -u) -ne 0; then
  99. echo "Root privilege is required."
  100. exit 1
  101. fi
  102. # Killing AESM service
  103. /usr/sbin/service aesmd stop
  104. $DISABLE_AESMD
  105. # Removing AESM configuration files
  106. rm -f $AESMD_DEST
  107. rm -f /etc/aesmd.conf
  108. # Removing AESM internal folders
  109. rm -fr /var/opt/aesmd
  110. rm -fr /var/run/aesmd
  111. # Removing runtime libraries
  112. rm -f /usr/lib/libsgx_uae_service.so
  113. rm -f /usr/lib/libsgx_urts.so
  114. rm -f /usr/lib/i386-linux-gnu/libsgx_uae_service.so
  115. rm -f /usr/lib/i386-linux-gnu/libsgx_urts.so
  116. # Removing AESM folder
  117. rm -fr $PSW_DST_PATH
  118. # Removing AESM user and group
  119. /usr/sbin/userdel aesmd
  120. echo "SGX PSW uninstalled."
  121. EOF
  122. chmod +x $PSW_DST_PATH/uninstall.sh
  123. $AESM_PATH/cse_provision_tool || true
  124. rm $AESM_PATH/cse_provision_tool
  125. # Start the aesmd service
  126. if [ -d /run/systemd/system ]; then
  127. systemctl start aesmd
  128. elif [ -d /etc/init/ ]; then
  129. /sbin/initctl start aesmd
  130. fi
  131. echo -e "\nuninstall.sh script generated in $PSW_DST_PATH\n"
  132. echo -e "Installation is successful!"
  133. rm -fr $PSW_DST_PATH/scripts
  134. exit 0