install.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2011-2018 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 -U -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: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: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. #
  99. # Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
  100. #
  101. # Redistribution and use in source and binary forms, with or without
  102. # modification, are permitted provided that the following conditions
  103. # are met:
  104. #
  105. # * Redistributions of source code must retain the above copyright
  106. # notice, this list of conditions and the following disclaimer.
  107. # * Redistributions in binary form must reproduce the above copyright
  108. # notice, this list of conditions and the following disclaimer in
  109. # the documentation and/or other materials provided with the
  110. # distribution.
  111. # * Neither the name of Intel Corporation nor the names of its
  112. # contributors may be used to endorse or promote products derived
  113. # from this software without specific prior written permission.
  114. #
  115. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  116. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  117. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  118. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  119. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  120. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  121. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  122. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  123. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  124. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  125. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  126. #
  127. #
  128. if test \$(id -u) -ne 0; then
  129. echo "Root privilege is required."
  130. exit 1
  131. fi
  132. get_lib()
  133. {
  134. echo "\$(basename \$(gcc -print-multi-os-directory))"
  135. }
  136. # Killing AESM service
  137. /usr/sbin/service aesmd stop
  138. $DISABLE_AESMD
  139. # Removing AESM configuration files
  140. rm -f $AESMD_DEST
  141. rm -f /etc/aesmd.conf
  142. # Removing AESM internal folders
  143. #rm -fr /var/opt/aesmd
  144. rm -fr /var/run/aesmd
  145. # Removing runtime libraries
  146. rm -f /usr/\$(get_lib)/libsgx_uae_service.so
  147. rm -f /usr/\$(get_lib)/libsgx_urts.so
  148. rm -f /usr/lib/i386-linux-gnu/libsgx_uae_service.so
  149. rm -f /usr/lib/i386-linux-gnu/libsgx_urts.so
  150. # Removing AESM user and group
  151. /usr/sbin/userdel aesmd 2> /dev/null
  152. /usr/sbin/groupdel aesmd 2> /dev/null
  153. # Removing AESM folder
  154. rm -fr $PSW_DST_PATH
  155. echo "Intel(R) SGX PSW uninstalled."
  156. EOF
  157. chmod +x $PSW_DST_PATH/uninstall.sh
  158. $AESM_PATH/cse_provision_tool || true
  159. rm $AESM_PATH/cse_provision_tool
  160. cat > $AESM_PATH/linksgx.sh <<EOF
  161. #!/usr/bin/env bash
  162. #
  163. # Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
  164. #
  165. # Redistribution and use in source and binary forms, with or without
  166. # modification, are permitted provided that the following conditions
  167. # are met:
  168. #
  169. # * Redistributions of source code must retain the above copyright
  170. # notice, this list of conditions and the following disclaimer.
  171. # * Redistributions in binary form must reproduce the above copyright
  172. # notice, this list of conditions and the following disclaimer in
  173. # the documentation and/or other materials provided with the
  174. # distribution.
  175. # * Neither the name of Intel Corporation nor the names of its
  176. # contributors may be used to endorse or promote products derived
  177. # from this software without specific prior written permission.
  178. #
  179. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  180. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  181. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  182. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  183. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  184. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  185. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  186. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  187. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  188. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  189. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  190. #
  191. #
  192. if test \$(id -u) -ne 0; then
  193. echo "Root privilege is required."
  194. exit 1
  195. fi
  196. if [ -e /dev/sgx ]; then
  197. chmod 666 /dev/sgx &> /dev/null
  198. /sbin/modprobe -r isgx &> /dev/null
  199. else
  200. /sbin/modprobe isgx &> /dev/null || /sbin/modprobe --allow-unsupported isgx &> /dev/null
  201. fi
  202. echo ""
  203. EOF
  204. chmod +x $AESM_PATH/linksgx.sh
  205. # Start the aesmd service
  206. if [ -d /run/systemd/system ]; then
  207. systemctl start aesmd
  208. elif [ -d /etc/init/ ]; then
  209. /sbin/initctl start aesmd
  210. fi
  211. echo -e "\nuninstall.sh script generated in $PSW_DST_PATH\n"
  212. echo -e "Installation is successful!"
  213. rm -fr $PSW_DST_PATH/scripts
  214. exit 0