support 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. #!/usr/bin/env bash
  2. is_a_function()
  3. {
  4. \typeset -f $1 >/dev/null 2>&1 || return $?
  5. }
  6. # Functions RVM is built on
  7. # __rvm_string_match <value> <string|glob>
  8. if
  9. [[ -n "${ZSH_VERSION:-}" ]]
  10. then
  11. __rvm_string_match()
  12. {
  13. \typeset _string _search
  14. _string="$1"
  15. shift
  16. while (( $# ))
  17. do
  18. _search="$1"
  19. _search="${_search// /[[:space:]]}"
  20. _search="${_search//\#/\#}"
  21. eval "\
  22. case \"\${_string}\" in\
  23. ($_search) return 0 ;;\
  24. esac\
  25. "
  26. shift
  27. done
  28. return 1
  29. }
  30. else
  31. __rvm_string_match()
  32. {
  33. \typeset _string
  34. _string="$1"
  35. shift
  36. while (( $# ))
  37. do
  38. case "${_string}" in
  39. (${1// /[[:space:]]}) return 0 ;;
  40. esac
  41. shift
  42. done
  43. return 1
  44. }
  45. fi
  46. __rvm_array_contains()
  47. {
  48. \typeset _search _iterator
  49. _search="$1"
  50. shift
  51. for _iterator
  52. do
  53. case "${_iterator}" in
  54. (${_search}) return 0 ;;
  55. esac
  56. done
  57. return 1
  58. }
  59. __rvm_array_add_or_update()
  60. {
  61. \typeset _array_name _variable _separator _value _local_value
  62. \typeset -a _array_value_old _array_value_new
  63. _array_name="$1"
  64. _variable="$2"
  65. _separator="$3"
  66. _value="${4##${_separator}}"
  67. _array_value_new=()
  68. eval "_array_value_old=( \"\${${_array_name}[@]}\" )"
  69. case " ${_array_value_old[*]} " in
  70. (*[[:space:]]${_variable}*)
  71. for _local_value in "${_array_value_old[@]}"
  72. do
  73. case "${_local_value}" in
  74. (${_variable}*)
  75. _array_value_new+=( "${_local_value}${_separator}${_value}" )
  76. ;;
  77. (*)
  78. _array_value_new+=( "${_local_value}" )
  79. ;;
  80. esac
  81. done
  82. ;;
  83. (*)
  84. _array_value_new=( "${_array_value_old[@]}" "${_variable}${_value}" )
  85. ;;
  86. esac
  87. eval "${_array_name}=( \"\${_array_value_new[@]}\" )"
  88. }
  89. __rvm_array_prepend_or_ignore()
  90. {
  91. \typeset _array_name _variable _separator _value _prefix _local_value
  92. \typeset -a _array_value_old _array_value_new
  93. _array_name="$1"
  94. _variable="$2"
  95. _separator="$3"
  96. _value="$4"
  97. _prefix="$5"
  98. _array_value_new=()
  99. eval "_array_value_old=( \"\${${_array_name}[@]}\" )"
  100. case " ${_array_value_old[*]} " in
  101. (*[[:space:]]${_variable}*)
  102. for _local_value in "${_array_value_old[@]}"
  103. do
  104. case "${_local_value}" in
  105. (${_variable}*${_prefix}*)
  106. rvm_debug "__rvm_array_prepend_or_ignore ${_array_name} ${_local_value}"
  107. _array_value_new+=( "${_local_value}" )
  108. ;;
  109. (${_variable}*)
  110. rvm_debug "__rvm_array_prepend_or_ignore ${_array_name} ${_variable}\"${_value}${_separator}${_local_value#${_variable}}\""
  111. _array_value_new+=( "${_variable}${_value}${_separator}${_local_value#${_variable}}" )
  112. ;;
  113. (*)
  114. _array_value_new+=( "${_local_value}" )
  115. ;;
  116. esac
  117. done
  118. eval "${_array_name}=( \"\${_array_value_new[@]}\" )"
  119. ;;
  120. esac
  121. }
  122. # Drop in replacement for sed -i compatible with OpenBSD
  123. # Assumes that filename is the first argument, all others are passed onto sed
  124. __rvm_sed_i()
  125. {
  126. \typeset _filename _executable _user
  127. [[ -n "${1:-}" ]] || {
  128. rvm_debug "no file given for __rvm_sed_i"
  129. return 0
  130. }
  131. _filename="$1"
  132. shift
  133. if [[ -x "${_filename}" ]]
  134. then _executable=true
  135. fi
  136. _user="$( __rvm_statf "%u:%g" "%u:%g" "${_filename}" )"
  137. {
  138. __rvm_sed "$@" < "${_filename}" > "${_filename}.new" &&
  139. \command \mv -f "${_filename}.new" "${_filename}"
  140. } 2>&1 | rvm_debug_stream
  141. if [[ -n "${_executable:-}" && ! -x "${_filename}" ]]
  142. then chmod +x "${_filename}"
  143. fi
  144. if [[ "$_user" != "$( __rvm_statf "%u:%g" "%u:%g" "${_filename}" )" ]]
  145. then chown "$_user" "${_filename}"
  146. fi
  147. }
  148. # Drop in cd which _doesnt't_ respect cdpath
  149. __rvm_cd()
  150. {
  151. \typeset old_cdpath ret
  152. ret=0
  153. old_cdpath="${CDPATH}"
  154. CDPATH="."
  155. chpwd_functions="" builtin cd "$@" || ret=$?
  156. CDPATH="${old_cdpath}"
  157. return $ret
  158. }
  159. __rvm_setup_utils_functions()
  160. {
  161. \typeset gnu_tools_path gnu_prefix gnu_util
  162. \typeset -a gnu_utils gnu_missing
  163. gnu_utils=( awk cp date find sed tail tar xargs )
  164. gnu_missing=()
  165. if is_a_function __rvm_setup_utils_functions_${_system_name}
  166. then __rvm_setup_utils_functions_${_system_name} "$@" || return $?
  167. else __rvm_setup_utils_functions_Other "$@" || return $?
  168. fi
  169. }
  170. __rvm_setup_utils_functions_Solaris()
  171. {
  172. case "${_system_version}" in
  173. (10)
  174. gnu_tools_path=/opt/csw/bin
  175. gnu_prefix="g"
  176. ;;
  177. (11)
  178. gnu_tools_path=/usr/gnu/bin
  179. gnu_prefix=""
  180. ;;
  181. esac
  182. if [[ -x $gnu_tools_path/${gnu_prefix}grep ]]
  183. then eval "__rvm_grep() { GREP_OPTIONS=\"\" $gnu_tools_path/${gnu_prefix}grep \"\$@\" || return \$?; }"
  184. else gnu_missing+=( ${gnu_prefix}grep )
  185. fi
  186. if [[ "${_system_name}" == "OpenIndiana" || "${_system_version}" == "11" ]]
  187. then __rvm_stat() { \command \stat "$@" || return $?; }
  188. elif [[ -x $gnu_tools_path/${gnu_prefix}stat ]]
  189. then eval "__rvm_stat() { $gnu_tools_path/${gnu_prefix}stat \"\$@\" || return \$?; }"
  190. else gnu_missing+=( ${gnu_prefix}stat )
  191. fi
  192. if [[ "${_system_name}" == "SmartOS" ]]
  193. then __rvm_which() { \command \which "$@" || return $?; }
  194. elif [[ -x $gnu_tools_path/${gnu_prefix}which ]]
  195. then eval "__rvm_which() { $gnu_tools_path/${gnu_prefix}which \"\$@\" || return \$?; }"
  196. else gnu_missing+=( ${gnu_prefix}which )
  197. fi
  198. for gnu_util in "${gnu_utils[@]}"
  199. do
  200. if [[ -x $gnu_tools_path/$gnu_prefix$gnu_util ]]
  201. then eval "__rvm_$gnu_util() { $gnu_tools_path/$gnu_prefix$gnu_util \"\$@\" || return \$?; }"
  202. else gnu_missing+=( $gnu_prefix$gnu_util )
  203. fi
  204. done
  205. if
  206. (( ${#gnu_missing[@]} ))
  207. then
  208. rvm_error "ERROR: Missing GNU tools: ${gnu_missing[@]}. Make sure they are installed in '$gnu_tools_path/' before using RVM!"
  209. if [[ "${_system_name} ${_system_version}" == "Solaris 10" ]]
  210. then rvm_error "You might want to look at OpenCSW project to install the above mentioned tools (https://www.opencsw.org/about)"
  211. fi
  212. exit 200
  213. fi
  214. }
  215. __rvm_setup_utils_functions_OSX()
  216. {
  217. if
  218. [[ -x /usr/bin/stat ]]
  219. then
  220. __rvm_stat() { /usr/bin/stat "$@" || return $?; }
  221. else
  222. rvm_error "ERROR: Missing (executable) /usr/bin/stat. Falling back to '\\\\command \\\\stat' which might be something else."
  223. __rvm_stat() { \command \stat "$@" || return $?; }
  224. fi
  225. __rvm_setup_utils_functions_common
  226. }
  227. __rvm_setup_utils_functions_Other()
  228. {
  229. __rvm_stat() { \command \stat "$@" || return $?; }
  230. __rvm_setup_utils_functions_common
  231. }
  232. __rvm_setup_utils_functions_common()
  233. {
  234. __rvm_grep() { GREP_OPTIONS="" \command \grep "$@" || return $?; }
  235. if \command \which --skip-alias --skip-functions which >/dev/null 2>&1
  236. then __rvm_which() { \command \which --skip-alias --skip-functions "$@" || return $?; }
  237. elif \command \which whence >/dev/null 2>&1 && \command \whence whence >/dev/null 2>&1
  238. then __rvm_which() { \command \whence -p "$@" || return $?; }
  239. elif \command \which which >/dev/null 2>&1
  240. then __rvm_which() { \command \which "$@" || return $?; }
  241. elif \which which >/dev/null 2>&1
  242. then __rvm_which() { \which "$@" || return $?; }
  243. else
  244. \typeset __result=$?
  245. rvm_error "ERROR: Missing proper 'which' command. Make sure it is installed before using RVM!"
  246. return ${__result}
  247. fi
  248. for gnu_util in "${gnu_utils[@]}"
  249. do eval "__rvm_$gnu_util() { \\$gnu_util \"\$@\" || return \$?; }"
  250. done
  251. }
  252. __rvm_setup_utils_functions || return $?
  253. # detect system after setting up __rvm_sed and before setting up __rvm_statf
  254. source "${rvm_scripts_path}/functions/db"
  255. source "${rvm_scripts_path}/functions/detect/system"
  256. __rvm_setup_statf_function()
  257. {
  258. if
  259. [[ "${_system_type}" == Darwin || "${_system_type}" == BSD ]]
  260. then
  261. __rvm_statf()
  262. {
  263. __rvm_stat -f "$2" "$3"
  264. }
  265. else
  266. __rvm_statf()
  267. {
  268. __rvm_stat -c "$1" "$3"
  269. }
  270. fi
  271. }
  272. __rvm_setup_statf_function || return $?
  273. __rvm_setup_sudo_function()
  274. {
  275. if is_a_function __rvm_setup_sudo_function_${_system_name}
  276. then __rvm_setup_sudo_function_${_system_name} "$@" || return $?
  277. else __rvm_setup_sudo_function_Other "$@" || return $?
  278. fi
  279. }
  280. __rvm_setup_sudo_function_PCLinuxOS()
  281. {
  282. __rvm_sudo()
  283. {
  284. if
  285. [[ "$1" == "-p" ]]
  286. then
  287. rvm_printf_to_stderr "${2//%p/[root]/}"
  288. shift 2
  289. fi
  290. su -c "$*"
  291. }
  292. }
  293. __rvm_setup_sudo_function_Solaris()
  294. {
  295. if
  296. [[ -x /opt/csw/bin/sudo ]]
  297. then
  298. __rvm_sudo()
  299. {
  300. /opt/csw/bin/sudo "$@"
  301. }
  302. elif
  303. [[ -x /usr/bin/sudo ]]
  304. then
  305. __rvm_sudo()
  306. {
  307. /usr/bin/sudo "$@"
  308. }
  309. else
  310. rvm_debug "Warning: No '/opt/csw/bin/sudo' found."
  311. fi
  312. }
  313. __rvm_setup_sudo_function_Other()
  314. {
  315. if
  316. __rvm_which sudo >/dev/null 2>&1
  317. then
  318. __rvm_sudo()
  319. {
  320. \command \sudo "$@"
  321. }
  322. else
  323. rvm_debug "Warning: No 'sudo' found."
  324. fi
  325. }
  326. __rvm_setup_sudo_function || return $?
  327. # Utils that are not needed for RVM installation
  328. # but have non-standard paths in Solaris 10
  329. other_utils=( ant automake autoreconf libtoolize make mount patch readlink )
  330. if
  331. [[ "${_system_name} ${_system_version}" == "Solaris 10" ]]
  332. then
  333. __rvm_ant() { /usr/sfw/bin/ant "$@" || return $?; }
  334. __rvm_automake() { /opt/csw/bin/automake "$@" || return $?; }
  335. __rvm_autoreconf() { /opt/csw/bin/autoreconf "$@" || return $?; }
  336. __rvm_libtoolize() { /opt/csw/bin/libtoolize "$@" || return $?; }
  337. __rvm_make() { /opt/csw/bin/gmake "$@" || return $?; }
  338. __rvm_mount() { /sbin/mount "$@" || return $?; }
  339. __rvm_patch() { /opt/csw/bin/gpatch "$@" || return $?; }
  340. __rvm_readlink() { /opt/csw/bin/greadlink "$@" || return $?; }
  341. else
  342. for other_util in "${other_utils[@]}"
  343. do eval "__rvm_$other_util() { \\$other_util \"\$@\" || return \$?; }"
  344. done
  345. fi
  346. unset other_util other_utils
  347. __rvm_readlink_deep()
  348. {
  349. eval "
  350. while [[ -n \"\${$1}\" && -L \"\${$1}\" ]]
  351. do $1=\"\$(__rvm_readlink \"\${$1}\")\"
  352. done
  353. "
  354. }
  355. ## duplication marker 32fosjfjsznkjneuera48jae
  356. __rvm_curl_output_control()
  357. {
  358. if
  359. (( ${rvm_quiet_curl_flag:-0} == 1 ))
  360. then
  361. __flags+=( "--silent" "--show-error" )
  362. elif
  363. [[ " $*" == *" -s"* || " $*" == *" --silent"* ]]
  364. then
  365. # make sure --show-error is used with --silent
  366. [[ " $*" == *" -S"* || " $*" == *" -sS"* || " $*" == *" --show-error"* ]] ||
  367. {
  368. __flags+=( "--show-error" )
  369. }
  370. fi
  371. }
  372. ## duplication marker 32fosjfjsznkjneuera48jae
  373. # -S is automatically added to -s
  374. __rvm_curl()
  375. (
  376. \typeset curl_path
  377. if
  378. [[ "${_system_name} ${_system_version}" == "Solaris 10" ]] &&
  379. ! __rvm_which curl >/dev/null 2>&1
  380. then
  381. curl_path=/opt/csw/bin/
  382. else
  383. curl_path=""
  384. fi
  385. __rvm_which ${curl_path}curl >/dev/null 2>&1 ||
  386. {
  387. rvm_error "RVM requires 'curl'. Install 'curl' first and try again."
  388. return 200
  389. }
  390. \typeset -a __flags
  391. __flags=( --fail --location )
  392. # allow overriding default 30 minutes for download, but should be plenty of time
  393. if [[ -n "${rvm_curl_flags[*]}" ]]
  394. then __flags+=( "${rvm_curl_flags[@]}" )
  395. else __flags+=( --max-redirs 10 --max-time 1800 )
  396. fi
  397. [[ "$*" == *"--max-time"* ]] ||
  398. [[ "$*" == *"--connect-timeout"* ]] ||
  399. [[ "${__flags[*]}" == *"--connect-timeout"* ]] ||
  400. __flags+=( --connect-timeout 30 --retry-delay 2 --retry 3 )
  401. if [[ -n "${rvm_proxy:-}" ]]
  402. then __flags+=( --proxy "${rvm_proxy:-}" )
  403. fi
  404. __rvm_curl_output_control
  405. unset curl
  406. __rvm_debug_command ${curl_path}curl "${__flags[@]}" "$@" || return $?
  407. )
  408. is_parent_of()
  409. {
  410. \typeset name pid ppid pname
  411. name=$1
  412. pid=$2
  413. while [[ -n "$pid" && "$pid" != "0" ]]
  414. do
  415. case "`uname`" in
  416. (SunOS)
  417. read ppid pname <<<"$(\command \ps -p $pid -o ppid= -o comm=)"
  418. ;;
  419. (*)
  420. read ppid pname <<<"$(\command \ps -p $pid -o ppid= -o ucomm=)"
  421. ;;
  422. esac
  423. if [[ -n "$ppid" && -n "$pname" ]]
  424. then
  425. if [[ "$pname" == "$name" ]]
  426. then
  427. echo $pid
  428. return 0
  429. else
  430. pid=$ppid
  431. fi
  432. else
  433. break
  434. fi
  435. done
  436. return 1
  437. }
  438. __rvm_string_includes()
  439. {
  440. \typeset __search __text="$1"
  441. shift
  442. for __search in "$@"
  443. do
  444. if [[ " ${__text} " == *" ${__search} "* ]]
  445. then return 0
  446. fi
  447. done
  448. return 1
  449. }
  450. __function_on_stack()
  451. {
  452. __rvm_string_includes "${FUNCNAME[*]}" "$@" || return $?
  453. }
  454. # read lines from file / stdin(-)
  455. __rvm_read_lines()
  456. {
  457. \typeset IFS
  458. # NEW LINE, BE CAREFUL
  459. IFS="
  460. "
  461. if [[ "${2:--}" == "-" ]]
  462. then eval "$1=( \$( \command \cat - ) )"
  463. else eval "$1=( \$( \command \cat \"\${2:--}\" ) )"
  464. fi
  465. }
  466. __setup_lang_fallback()
  467. {
  468. if
  469. [[ -z "${LANG:-}" ]]
  470. then
  471. LANG="$(
  472. {
  473. locale -a | __rvm_grep "^en_US.utf8" ||
  474. locale -a | __rvm_grep "^en_US" ||
  475. locale -a | __rvm_grep "^en" ||
  476. locale -a
  477. } 2>/dev/null | \command \head -n 1
  478. )"
  479. : LANG=${LANG:=en_US.utf-8}
  480. export LANG
  481. rvm_warn "\$LANG was empty, setting up LANG=$LANG, if it fails again try setting LANG to something sane and try again."
  482. fi
  483. }
  484. __rvm_ruby_config_save()
  485. {
  486. \typeset ruby_path
  487. ruby_path="${1:-$rvm_ruby_home/bin/ruby}"
  488. case "$ruby_path" in
  489. (*/mruby*)
  490. __rvm_ruby_config_save_mruby "${2:-${ruby_path%%/bin/ruby}/config}"
  491. ;;
  492. (*)
  493. __rvm_ruby_config_save_generic "$2"
  494. ;;
  495. esac
  496. }
  497. __rvm_ruby_config_save_mruby()
  498. {
  499. echo "target_cpu=\"$_system_arch\"" > "$1"
  500. }
  501. __rvm_ruby_config_save_generic()
  502. {
  503. \typeset config_path default_config_path
  504. default_config_path="#{RbConfig::CONFIG[\"prefix\"]}/config"
  505. config_path="${1:-$default_config_path}"
  506. "$ruby_path" -rrbconfig -e '\
  507. File.open("'"$config_path"'","w") { |file|
  508. RbConfig::CONFIG.sort.each{|key,value|
  509. file.write("#{key.gsub(/\.|-/,"_")}=\"#{value.to_s.gsub("$","\\$")}\"\n")
  510. }
  511. }
  512. ' >/dev/null 2>&1
  513. }
  514. __rvm_record_ruby_configs()
  515. {
  516. \typeset __dir
  517. for __dir in "$rvm_path/rubies/"*
  518. do
  519. if
  520. [[ ! -L "${__dir}" && ! -s "${__dir}/config" && -x "${__dir}/bin/ruby" ]]
  521. then
  522. __rvm_ruby_config_save "${__dir}/bin/ruby" "${__dir}/config" ||
  523. {
  524. \typeset string="${__dir##*/}"
  525. rvm_error " Can not save config data for ruby: '${string}', most likely it is broken installation and you can:
  526. - try fix it: 'rvm reinstall ${string}', OR:
  527. - remove it: 'rvm uninstall ${string} --gems'"
  528. }
  529. fi
  530. done
  531. }
  532. __rvm_ls() { \command \ls "$@" || return $?; }