check-requirements.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env sh
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. set -e
  6. # The script checks necessary server requirements for the classic server
  7. # scenarios. Currently, the script can exit with any of the following
  8. # 3 exit codes and should be handled accordingly on the extension side.
  9. #
  10. # 0: All requirements are met, use the default server.
  11. # 99: Unsupported OS, abort server startup with appropriate error message.
  12. # 100: Use legacy server.
  13. #
  14. # Do not remove this check.
  15. # Provides a way to skip the server requirements check from
  16. # outside the install flow. A system process can create this
  17. # file before the server is downloaded and installed.
  18. if [ -f "/tmp/vscode-skip-server-requirements-check" ]; then
  19. echo "!!! WARNING: Skipping server pre-requisite check !!!"
  20. echo "!!! Server stability is not guaranteed. Proceed at your own risk. !!!"
  21. exit 0
  22. fi
  23. ARCH=$(uname -m)
  24. found_required_glibc=0
  25. found_required_glibcxx=0
  26. MIN_GLIBCXX_VERSION="3.4.25"
  27. # Extract the ID value from /etc/os-release
  28. if [ -f /etc/os-release ]; then
  29. OS_ID="$(cat /etc/os-release | grep -Eo 'ID=([^"]+)' | sed -n '1s/ID=//p')"
  30. if [ "$OS_ID" = "nixos" ]; then
  31. echo "Warning: NixOS detected, skipping GLIBC check"
  32. exit 0
  33. fi
  34. fi
  35. # Based on https://github.com/bminor/glibc/blob/520b1df08de68a3de328b65a25b86300a7ddf512/elf/cache.c#L162-L245
  36. case $ARCH in
  37. x86_64) LDCONFIG_ARCH="x86-64";;
  38. armv7l | armv8l)
  39. MIN_GLIBCXX_VERSION="3.4.26"
  40. LDCONFIG_ARCH="hard-float"
  41. ;;
  42. arm64 | aarch64)
  43. BITNESS=$(getconf LONG_BIT)
  44. if [ "$BITNESS" = "32" ]; then
  45. # Can have 32-bit userland on 64-bit kernel
  46. LDCONFIG_ARCH="hard-float"
  47. else
  48. LDCONFIG_ARCH="AArch64"
  49. fi
  50. ;;
  51. esac
  52. if [ "$OS_ID" != "alpine" ]; then
  53. if [ -f /sbin/ldconfig ]; then
  54. # Look up path
  55. libstdcpp_paths=$(/sbin/ldconfig -p | grep 'libstdc++.so.6')
  56. if [ "$(echo "$libstdcpp_paths" | wc -l)" -gt 1 ]; then
  57. libstdcpp_path=$(echo "$libstdcpp_paths" | grep "$LDCONFIG_ARCH" | awk '{print $NF}')
  58. else
  59. libstdcpp_path=$(echo "$libstdcpp_paths" | awk '{print $NF}')
  60. fi
  61. elif [ -f /usr/lib/libstdc++.so.6 ]; then
  62. # Typical path
  63. libstdcpp_path='/usr/lib/libstdc++.so.6'
  64. elif [ -f /usr/lib64/libstdc++.so.6 ]; then
  65. # Typical path
  66. libstdcpp_path='/usr/lib64/libstdc++.so.6'
  67. else
  68. echo "Warning: Can't find libstdc++.so or ldconfig, can't verify libstdc++ version"
  69. fi
  70. while [ -n "$libstdcpp_path" ]; do
  71. # Extracts the version number from the path, e.g. libstdc++.so.6.0.22 -> 6.0.22
  72. # which is then compared based on the fact that release versioning and symbol versioning
  73. # are aligned for libstdc++. Refs https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html
  74. # (i-e) GLIBCXX_3.4.<release> is provided by libstdc++.so.6.y.<release>
  75. libstdcpp_path_line=$(echo "$libstdcpp_path" | head -n1)
  76. libstdcpp_real_path=$(readlink -f "$libstdcpp_path_line")
  77. libstdcpp_version=$(grep -ao 'GLIBCXX_[0-9]*\.[0-9]*\.[0-9]*' "$libstdcpp_real_path" | sort -V | tail -1)
  78. libstdcpp_version_number=$(echo "$libstdcpp_version" | sed 's/GLIBCXX_//')
  79. if [ "$(printf '%s\n' "$MIN_GLIBCXX_VERSION" "$libstdcpp_version_number" | sort -V | head -n1)" = "$MIN_GLIBCXX_VERSION" ]; then
  80. found_required_glibcxx=1
  81. break
  82. fi
  83. libstdcpp_path=$(echo "$libstdcpp_path" | tail -n +2) # remove first line
  84. done
  85. else
  86. echo "Warning: alpine distro detected, skipping GLIBCXX check"
  87. found_required_glibcxx=1
  88. fi
  89. if [ "$found_required_glibcxx" = "0" ]; then
  90. echo "Warning: Missing GLIBCXX >= $MIN_GLIBCXX_VERSION! from $libstdcpp_real_path"
  91. fi
  92. if [ "$OS_ID" = "alpine" ]; then
  93. MUSL_RTLDLIST="/lib/ld-musl-aarch64.so.1 /lib/ld-musl-x86_64.so.1"
  94. for rtld in ${MUSL_RTLDLIST}; do
  95. if [ -x $rtld ]; then
  96. musl_version=$("$rtld" --version 2>&1 | grep "Version" | awk '{print $NF}')
  97. break
  98. fi
  99. done
  100. if [ "$(printf '%s\n' "1.2.3" "$musl_version" | sort -V | head -n1)" != "1.2.3" ]; then
  101. echo "Error: Unsupported alpine distribution. Please refer to our supported distro section https://aka.ms/vscode-remote/linux for additional information."
  102. exit 99
  103. fi
  104. found_required_glibc=1
  105. elif [ -z "$(ldd --version 2>&1 | grep 'musl libc')" ]; then
  106. if [ -f /sbin/ldconfig ]; then
  107. # Look up path
  108. libc_paths=$(/sbin/ldconfig -p | grep 'libc.so.6')
  109. if [ "$(echo "$libc_paths" | wc -l)" -gt 1 ]; then
  110. libc_path=$(echo "$libc_paths" | grep "$LDCONFIG_ARCH" | awk '{print $NF}')
  111. else
  112. libc_path=$(echo "$libc_paths" | awk '{print $NF}')
  113. fi
  114. elif [ -f /usr/lib/libc.so.6 ]; then
  115. # Typical path
  116. libc_path='/usr/lib/libc.so.6'
  117. elif [ -f /lib64/libc.so.6 ]; then
  118. # Typical path (OpenSUSE)
  119. libc_path='/lib64/libc.so.6'
  120. elif [ -f /usr/lib64/libc.so.6 ]; then
  121. # Typical path
  122. libc_path='/usr/lib64/libc.so.6'
  123. else
  124. echo "Warning: Can't find libc.so or ldconfig, can't verify libc version"
  125. fi
  126. while [ -n "$libc_path" ]; do
  127. # Rather than trusting the output of ldd --version (which is not always accurate)
  128. # we instead use the version of the cached libc.so.6 file itself.
  129. libc_path_line=$(echo "$libc_path" | head -n1)
  130. libc_real_path=$(readlink -f "$libc_path_line")
  131. libc_version=$(cat "$libc_real_path" | sed -n 's/.*release version \([0-9]\+\.[0-9]\+\).*/\1/p')
  132. if [ "$(printf '%s\n' "2.28" "$libc_version" | sort -V | head -n1)" = "2.28" ]; then
  133. found_required_glibc=1
  134. break
  135. fi
  136. libc_path=$(echo "$libc_path" | tail -n +2) # remove first line
  137. done
  138. if [ "$found_required_glibc" = "0" ]; then
  139. echo "Warning: Missing GLIBC >= 2.28! from $libc_real_path"
  140. fi
  141. else
  142. echo "Warning: musl detected, skipping GLIBC check"
  143. found_required_glibc=1
  144. fi
  145. if [ "$found_required_glibc" = "0" ] || [ "$found_required_glibcxx" = "0" ]; then
  146. echo "Warning: Missing required dependencies. Please refer to our FAQ https://aka.ms/vscode-remote/faq/old-linux for additional information."
  147. # Custom exit code based on https://tldp.org/LDP/abs/html/exitcodes.html
  148. exit 100
  149. fi