system 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/functions/detect/system_version/codename"
  3. __rvm_detect_system()
  4. {
  5. unset _system_type _system_name _system_version _system_arch
  6. export _system_type _system_name _system_version _system_arch
  7. _system_info="$(command uname -a)"
  8. _system_type="unknown"
  9. _system_name="unknown"
  10. _system_name_lowercase="unknown"
  11. _system_version="unknown"
  12. _system_arch="$(command uname -m)"
  13. case "$(command uname)" in
  14. (Linux|GNU*)
  15. source "$rvm_scripts_path/functions/detect/system_name/lsb_release"
  16. source "$rvm_scripts_path/functions/detect/system_name/os_release"
  17. _system_type="Linux"
  18. if [[ -f /etc/lsb-release ]] && __rvm_detect_system_from_lsb_release
  19. then
  20. :
  21. elif
  22. [[ -f /etc/os-release ]] && __rvm_detect_system_from_os_release
  23. then
  24. :
  25. elif
  26. [[ -f /etc/altlinux-release ]]
  27. then
  28. _system_name="Arch"
  29. _system_version="libc-$(ldd --version | \command \awk 'NR==1 {print $NF}' | \command \awk -F. '{print $1"."$2}' | head -n 1)"
  30. elif
  31. [[ -f /etc/SuSE-release ]]
  32. then
  33. _system_name="SuSE"
  34. _system_version="$( \command \awk -F'=' '{gsub(/ /,"")} $1~/VERSION/ {version=$2} $1~/PATCHLEVEL/ {patch=$2} END {print version"."patch}' < /etc/SuSE-release )"
  35. elif
  36. [[ -f /etc/devuan_version ]]
  37. then
  38. _system_name="Devuan"
  39. _system_version="$(\command \cat /etc/devuan_version | \command \awk -F. '{print $1}' | head -n 1)"
  40. _system_arch="$( dpkg --print-architecture )"
  41. elif
  42. [[ -f /etc/sabayon-release ]]
  43. then
  44. # needs to be before gentoo
  45. _system_name="Sabayon"
  46. _system_version="$(\command \cat /etc/sabayon-release | \command \awk 'NR==1 {print $NF}' | \command \awk -F. '{print $1"."$2}' | head -n 1)"
  47. elif
  48. [[ -f /etc/gentoo-release ]]
  49. then
  50. _system_name="Gentoo"
  51. _system_version="base-$(\command \cat /etc/gentoo-release | \command \awk 'NR==1 {print $NF}' | \command \awk -F. '{print $1"."$2}' | head -n 1)"
  52. elif
  53. [[ -f /etc/arch-release ]]
  54. then
  55. _system_name="Arch"
  56. _system_version="libc-$(ldd --version | \command \awk 'NR==1 {print $NF}' | \command \awk -F. '{print $1"."$2}' | head -n 1)"
  57. elif
  58. [[ -f /etc/fedora-release ]]
  59. then
  60. _system_name="Fedora"
  61. _system_version="$(GREP_OPTIONS="" \command \grep -Eo '[0-9]+' /etc/fedora-release | head -n 1)"
  62. elif
  63. [[ -f /etc/oracle-release ]]
  64. then
  65. _system_name="Oracle"
  66. _system_version="$(GREP_OPTIONS="" \command \grep -Eo '[0-9\.]+' /etc/oracle-release | \command \awk -F. '{print $1}' | head -n 1)"
  67. elif
  68. [[ -f /etc/redhat-release ]]
  69. then
  70. _system_name="$( GREP_OPTIONS="" \command \grep -Eo 'CentOS|PCLinuxOS|ClearOS|Mageia|Scientific|ROSA Desktop|OpenMandriva' /etc/redhat-release 2>/dev/null | \command \head -n 1 | \command \sed "s/ //" )"
  71. _system_name="${_system_name:-CentOS}"
  72. _system_version="$(GREP_OPTIONS="" \command \grep -Eo '[0-9\.]+' /etc/redhat-release | \command \awk -F. 'NR==1{print $1}' | head -n 1)"
  73. _system_arch="$( uname -m )"
  74. elif
  75. [[ -f /etc/centos-release ]]
  76. then
  77. _system_name="CentOS"
  78. _system_version="$(GREP_OPTIONS="" \command \grep -Eo '[0-9\.]+' /etc/centos-release | \command \awk -F. '{print $1}' | head -n 1)"
  79. elif
  80. [[ -f /etc/debian_version ]]
  81. then
  82. _system_name="Debian"
  83. _system_version="$(\command \cat /etc/debian_version | \command \awk -F. '{print $1}' | head -n 1)"
  84. _system_arch="$( dpkg --print-architecture )"
  85. __rvm_detect_debian_major_version_from_codename
  86. elif
  87. [[ -f /proc/devices ]] &&
  88. GREP_OPTIONS="" \command \grep -Eo "synobios" /proc/devices >/dev/null
  89. then
  90. _system_type="BSD"
  91. _system_name="Synology"
  92. _system_version="libc-$(ldd --version | \command \awk 'NR==1 {print $NF}' | \command \awk -F. '{print $1"."$2}' | head -n 1)"
  93. elif
  94. [[ "$(command uname -o)" == "Android" ]]
  95. then
  96. _system_name="Termux"
  97. _system_version="$(command uname -r)"
  98. else
  99. _system_version="libc-$(ldd --version | \command \awk 'NR==1 {print $NF}' | \command \awk -F. '{print $1"."$2}' | head -n 1)"
  100. fi
  101. ;;
  102. (SunOS)
  103. _system_type="SunOS"
  104. _system_name="Solaris"
  105. _system_version="$(command uname -v)"
  106. _system_arch="$(command isainfo -k)"
  107. if
  108. [[ "${_system_version}" == joyent* ]]
  109. then
  110. _system_name="SmartOS"
  111. _system_version="${_system_version#* }"
  112. elif
  113. [[ "${_system_version}" == omnios* ]]
  114. then
  115. _system_name="OmniOS"
  116. _system_version="${_system_version#* }"
  117. elif
  118. [[ "${_system_version}" == oi* || "${_system_version}" == illumos* ]]
  119. then
  120. _system_name="OpenIndiana"
  121. _system_version="${_system_version#* }"
  122. elif
  123. [[ "${_system_version}" == Generic* ]]
  124. then
  125. _system_version="10"
  126. elif
  127. [[ "${_system_version}" == *11* ]]
  128. then
  129. _system_version="11"
  130. # is else needed here?
  131. fi
  132. ;;
  133. (FreeBSD)
  134. _system_type="BSD"
  135. _system_name="FreeBSD"
  136. _system_version="$(command uname -r)"
  137. _system_version="${_system_version%%-*}"
  138. ;;
  139. (OpenBSD)
  140. _system_type="BSD"
  141. _system_name="OpenBSD"
  142. _system_version="$(command uname -r)"
  143. ;;
  144. (DragonFly)
  145. _system_type="BSD"
  146. _system_name="DragonFly"
  147. _system_version="$(command uname -r)"
  148. _system_version="${_system_version%%-*}"
  149. ;;
  150. (NetBSD)
  151. _system_type="BSD"
  152. _system_name="NetBSD"
  153. _system_version_full="$(command uname -r)"
  154. _system_version="$(echo ${_system_version_full} | \command \awk -F. '{print $1"."$2}')"
  155. ;;
  156. (Darwin)
  157. _system_type="Darwin"
  158. _system_name="OSX"
  159. _system_version="$(sw_vers -productVersion | \command \awk -F. '{print $1"."$2}')"
  160. ;;
  161. (CYGWIN*)
  162. _system_type="Windows"
  163. _system_name="Cygwin"
  164. ;;
  165. (MINGW*)
  166. _system_type="Windows"
  167. _system_name="Mingw"
  168. ;;
  169. (*)
  170. return 1
  171. ;;
  172. esac
  173. _system_type="${_system_type//[ \/]/_}"
  174. _system_name="${_system_name//[ \/]/_}"
  175. _system_name_lowercase="$(echo ${_system_name} | \command \tr '[A-Z]' '[a-z]')"
  176. _system_version="${_system_version//[ \/]/_}"
  177. _system_arch="${_system_arch//[ \/]/_}"
  178. _system_arch="${_system_arch/amd64/x86_64}"
  179. _system_arch="${_system_arch/i[123456789]86/i386}"
  180. }
  181. __rvm_detect_system_override()
  182. {
  183. \typeset _var
  184. for _var in system_type system_name system_name_lowercase system_version system_arch
  185. do __rvm_db ${_var} _${_var}
  186. done
  187. }
  188. __rvm_detect_system
  189. __rvm_detect_system_override