install_ch.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------------------------------------
  3. # Copyright (C) Microsoft. All rights reserved.
  4. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. #-------------------------------------------------------------------------------------------------------
  6. DEFAULT_COLOR='\033[0m'
  7. ERROR_COLOR='\033[0;31m'
  8. SUCCESS_COLOR='\033[0;32m'
  9. CURRENT_OS=
  10. CHAKRA_VERSION=0
  11. BINARY_NAME=
  12. PRINT()
  13. {
  14. TEXT_COLORED="$1$2"
  15. echo -e "${TEXT_COLORED} ${DEFAULT_COLOR}"
  16. }
  17. GET_ARCH()
  18. {
  19. UNAME_OUTPUT=$(uname -mrsn)
  20. if [[ "$UNAME_OUTPUT" =~ 'arm' ]]; then
  21. echo "arm"
  22. elif [[ "$UNAME_OUTPUT" =~ '64' ]]; then
  23. echo "x64"
  24. else
  25. echo "x86"
  26. fi
  27. }
  28. GET_OS()
  29. {
  30. UNAME_OUTPUT=$(uname -mrsn)
  31. ARCH=$(GET_ARCH)
  32. if [[ "${ARCH}" =~ "x64" ]]; then
  33. if [[ "${UNAME_OUTPUT}" =~ 'Darwin' ]]; then
  34. CURRENT_OS="macOS"
  35. BINARY_NAME="cc_osx_${ARCH}"
  36. return
  37. fi
  38. if [[ "${UNAME_OUTPUT}" =~ 'Linux' ]]; then
  39. CURRENT_OS="Linux"
  40. BINARY_NAME="cc_linux_${ARCH}"
  41. return
  42. fi
  43. fi
  44. PRINT $ERROR_COLOR "] This OS / ARCH is not yet supported - ${UNAME_OUTPUT}"
  45. exit
  46. }
  47. GET_LATEST()
  48. {
  49. GET_OS
  50. PRINT $DEFAULT_COLOR "] Fetching the latest ChakraCore version"
  51. CHAKRA_VERSION=$(curl -k -s -SL "https://aka.ms/chakracore/version")
  52. if [[ "$CHAKRA_VERSION" == *"Error"* ]]; then
  53. PRINT $ERROR_COLOR "] Please ensure you are connected to the internet and try again."
  54. exit 1
  55. fi
  56. PRINT $SUCCESS_COLOR "] Found ChakraCore ${CHAKRA_VERSION//_/.} for ${CURRENT_OS}"
  57. BINARY_NAME="https://aka.ms/chakracore/${BINARY_NAME}_${CHAKRA_VERSION}"
  58. SHASUM_NAME="${BINARY_NAME}_s"
  59. }
  60. PRINT $DEFAULT_COLOR "ChakraCore Installation Script 0.1b\n"
  61. PRINT $DEFAULT_COLOR "Visit https://aka.ms/WhatIs/ChakraCore for more information"
  62. GET_LATEST
  63. PRINT $DEFAULT_COLOR "----------------------------------------------------------------"
  64. PRINT $SUCCESS_COLOR "\nThis script will download & execute ChakraCore binary"
  65. PRINT $DEFAULT_COLOR "located at ${BINARY_NAME}\n"
  66. PRINT $DEFAULT_COLOR "----------------------------------------------------------------"
  67. PRINT $DEFAULT_COLOR "If you don't agree, press Ctrl+C to terminate"
  68. read -t 20 -p "Hit ENTER to continue (or wait 20 seconds)"
  69. if [ -d "./ChakraCoreFiles" ]; then
  70. PRINT $ERROR_COLOR "] Found 'ChakraCoreFiles' folder on the current path."
  71. PRINT $DEFAULT_COLOR "] You should delete that folder or try this script on another path"
  72. exit 1
  73. fi
  74. CHECK_DOWNLOAD_FAIL()
  75. {
  76. if [[ $? != 0 ]]; then
  77. PRINT $ERROR_COLOR "] Download failed."
  78. PRINT $DEFAULT_COLOR "] ${___}"
  79. exit 1
  80. fi
  81. }
  82. PRINT $DEFAULT_COLOR "\n] Downloading ChakraCore"
  83. PRINT $SUCCESS_COLOR "] ${BINARY_NAME}"
  84. ___=$(curl -kSL -o "chakracore.tar.gz" "${BINARY_NAME}" 2>&1)
  85. CHECK_DOWNLOAD_FAIL
  86. PRINT $DEFAULT_COLOR "\n] Downloading ChakraCore shasum"
  87. PRINT $SUCCESS_COLOR "] ${SHASUM_NAME}"
  88. ___=$(curl -kSL -o "chakracore_s.tar.gz" "${SHASUM_NAME}" 2>&1)
  89. CHECK_DOWNLOAD_FAIL
  90. PRINT $SUCCESS_COLOR "] Download completed"
  91. CHECK_EXT_FAIL()
  92. {
  93. if [[ $? != 0 ]]; then
  94. PRINT $ERROR_COLOR "] Extracting the compressed file failed."
  95. PRINT $DEFAULT_COLOR "] ${___}"
  96. rm -rf ChakraCoreFiles/
  97. rm -rf chakracore.tar.gz
  98. rm -rf chakracore_s.tar.gz
  99. exit 1
  100. fi
  101. }
  102. ___=$(tar -xzf chakracore_s.tar.gz 2>&1)
  103. CHECK_EXT_FAIL
  104. SUM1=`shasum -a 512256 chakracore.tar.gz`
  105. SUM2=`cat ChakraCoreFiles/shasum`
  106. SUM1="${SUM1}@"
  107. SUM2="${SUM2}@"
  108. if [[ ! $SUM1 =~ $SUM2 ]]; then
  109. PRINT $ERROR_COLOR "] Corrupted binary package."
  110. PRINT $DEFAULT_COLOR "] Check your network connection."
  111. PRINT $ERROR_COLOR "] If you suspect there is some other problem,\
  112. https://github.com/Microsoft/ChakraCore#contact-us"
  113. rm -rf chakracore.tar.gz
  114. rm -rf chakracore_s.tar.gz
  115. rm -rf ChakraCoreFiles/
  116. exit 1
  117. fi
  118. rm -rf chakracore_s.tar.gz
  119. PRINT $SUCCESS_COLOR "] ChakraCore package SHASUM matches"
  120. ___=$(tar -xzf chakracore.tar.gz 2>&1)
  121. CHECK_EXT_FAIL
  122. rm -rf chakracore.tar.gz
  123. # test ch
  124. ___=$(./ChakraCoreFiles/bin/ch -v 2>&1)
  125. if [[ $? != 0 ]]; then
  126. if [[ $___ =~ "GLIBC_2.17" ]]; then
  127. PRINT $ERROR_COLOR "] This ChakraCore binary is compiled for newer systems."
  128. PRINT $DEFAULT_COLOR "] You may compile ChakraCore on your current system."
  129. PRINT $DEFAULT_COLOR " Once you do that, it should work on your system.\n"
  130. PRINT $DEFAULT_COLOR "] You may also try running the pre-compiled binary on a newer system"
  131. else
  132. PRINT $ERROR_COLOR "] Something went wrong. 'ch' installation is failed."
  133. PRINT $DEFAULT_COLOR "] ${___}"
  134. PRINT $DEFAULT_COLOR "] Please send us this error from https://github.com/Microsoft/ChakraCore"
  135. fi
  136. rm -rf ChakraCoreFiles/
  137. exit 1
  138. fi
  139. PRINT $SUCCESS_COLOR "] Success\n"
  140. if [[ $___ =~ "-beta" ]]; then
  141. echo -e "Downloaded a ${ERROR_COLOR}release candidate${DEFAULT_COLOR} binary, $____"
  142. PRINT $DEFAULT_COLOR "] If you observe issue(s), please send us from https://github.com/Microsoft/ChakraCore"
  143. fi
  144. PRINT $DEFAULT_COLOR "] Try './ChakraCoreFiles/bin/ch -?'"