installer 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. #!/usr/bin/env bash
  2. case "`date +%s:%N`" in
  3. (*:%N)
  4. __install_time()
  5. {
  6. __time="$SECONDS:"
  7. }
  8. ;;
  9. (*)
  10. __install_time()
  11. {
  12. __time="$(date +%s:%N)"
  13. }
  14. ;;
  15. esac
  16. install_run_debug_time()
  17. {
  18. # 1st s = start, 1st e = end, 1st d = difference, 2nd s = seconds, 2nd n = nanoseconds
  19. \typeset __ss __sn __es __en __ds __dn __time __status=0
  20. rvm_debug "step> '$1' started"
  21. __install_time
  22. __ss="${__time}"
  23. "$@" || __status=$?
  24. __install_time
  25. __es="${__time}"
  26. # split seconds and nano
  27. __sn="${__ss#*:}"
  28. __sn="${__sn##*(0)}"
  29. __ss="${__ss%:*}"
  30. __ss="${__ss##*(0)}"
  31. __en="${__es#*:}"
  32. __en="${__en##*(0)}"
  33. __es="${__es%:*}"
  34. __es="${__es##*(0)}"
  35. __ds="$(( __es - __ss ))"
  36. __dn=""
  37. if
  38. [[ -n "${__sn}" && -n "${__en}" ]]
  39. then
  40. __dn="$(( __en - __sn ))"
  41. if
  42. (( __dn < 0 ))
  43. then
  44. __dn="$(( __dn + 1000000000 ))"
  45. __ds="$(( __ds - 1 ))"
  46. fi
  47. if [[ "${__dn}" == "0" ]]
  48. then __dn=""
  49. fi
  50. fi
  51. __time="${__ds}${__dn:+"$(printf ".%09d" "$__dn")"} seconds"
  52. rvm_debug "step< '$1' finished with status 0 in ${__time}"
  53. }
  54. install_rvm_step()
  55. {
  56. install_run_debug_time $1 ||
  57. {
  58. \typeset __status=$?
  59. rvm_error "Installer failed at step '$1' with status ${__status}, please run it with --debug and report a bug."
  60. return ${__status}
  61. }
  62. }
  63. install_rvm()
  64. {
  65. \typeset __step
  66. \typeset -a __steps
  67. __steps=()
  68. load_configuration
  69. parse_args "$@"
  70. setup_installer
  71. load_rvm
  72. if (( rvm_user_install_flag == 0 ))
  73. then __steps+=( system_installation_check setup_rvm_group_and_users )
  74. fi
  75. __steps+=(
  76. print_install_header
  77. cleanse_old_entities
  78. create_install_paths
  79. load_custom_flags
  80. save_custom_flags
  81. install_rvm_directories
  82. install_rvm_files
  83. install_rvm_scripts
  84. cleanup_old_help_and_docs_files
  85. install_rvm_hooks
  86. remove_old_hooks
  87. install_binaries
  88. install_gemsets
  89. install_patchsets
  90. install_man_pages
  91. setup_configuration_files
  92. setup_login_shell
  93. )
  94. # not using elif for clarity
  95. if (( rvm_user_install_flag == 1 ))
  96. then __steps+=( setup_user_profile )
  97. else
  98. if (( UID == 0 ))
  99. then __steps+=( setup_etc_profile setup_etc_bashrc setup_etc_rvmrc )
  100. else
  101. if (( upgrade_flag == 0 ))
  102. then __steps+=( warning_no_loading_of_rvm )
  103. fi
  104. fi
  105. fi
  106. __steps+=(
  107. cleanse_old_environments
  108. migrate_old_gemsets
  109. migrate_defaults
  110. migrate_environments_and_wrappers
  111. create_gems_aliases
  112. restore_missing_environments
  113. record_ruby_configs
  114. update_gemsets_install_rvm
  115. configure_autolibs
  116. update_yaml_if_needed
  117. cleanup_tmp_files
  118. record_installation_time
  119. )
  120. if
  121. (( rvm_user_install_flag == 0 ))
  122. then
  123. __steps+=(
  124. setup_rvm_path_permissions_root
  125. setup_rvm_path_permissions_check_group
  126. setup_rvm_path_permissions_check_dirs
  127. setup_rvm_path_permissions_check_files
  128. )
  129. fi
  130. __steps+=(
  131. print_install_footer
  132. display_notes
  133. )
  134. for __step in "${__steps[@]}"
  135. do install_rvm_step ${__step} || return $?
  136. done
  137. }
  138. load_configuration()
  139. {
  140. set -o errtrace
  141. export PS4 PATH HOME
  142. HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
  143. case "$MACHTYPE" in
  144. *aix*) name_opt=-name ;;
  145. *) name_opt=-iname ;;
  146. esac
  147. if
  148. (( ${rvm_ignore_rvmrc:=0} == 0 ))
  149. then
  150. [[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
  151. rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  152. if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
  153. then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  154. fi
  155. for file in "${rvm_rvmrc_files[@]}"
  156. do
  157. if [[ -s "$file" ]]
  158. then . "$file"
  159. fi
  160. done
  161. unset rvm_rvmrc_files
  162. fi
  163. PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
  164. [[ -z "${rvm_user_path_prefix:-}" ]] || PATH="${rvm_user_path_prefix}:$PATH"
  165. export ORIGINAL_PATH="$PATH"
  166. true ${rvm_group_name:=rvm}
  167. unset rvm_auto_dotfiles_flag
  168. }
  169. parse_args()
  170. {
  171. true ${DESTDIR:=}
  172. # Parse RVM Installer CLI arguments.
  173. while (( $# > 0 ))
  174. do
  175. token="$1"
  176. shift
  177. case "$token" in
  178. (--auto-dotfiles|--ignore-dotfiles|--debug|--quiet-curl)
  179. token=${token#--}
  180. token=${token//-/_}
  181. export "rvm_${token}_flag"=1
  182. ;;
  183. (--autolibs=*)
  184. export rvm_autolibs_flag="${token#--autolibs=}"
  185. ;;
  186. (--without-gems=*|--with-gems=*|--with-default-gems=*)
  187. value="${token#*=}"
  188. token="${token%%=*}"
  189. token="${token#--}"
  190. token="${token//-/_}"
  191. export "rvm_${token}"="${value}"
  192. ;;
  193. (--path)
  194. export rvm_path="$1"
  195. export rvm_bin_path="$1/bin"
  196. export rvm_ignore_rvmrc=1
  197. shift
  198. ;;
  199. (--add-to-rvm-group)
  200. export rvm_add_users_to_rvm_group="$1"
  201. shift
  202. ;;
  203. (--version)
  204. (
  205. export rvm_path="${PWD%%+(\/)}"
  206. echo "$rvm_version"
  207. )
  208. exit
  209. ;;
  210. (--trace)
  211. export rvm_trace_flag=1
  212. set -o xtrace
  213. echo "$@"
  214. env | GREP_OPTIONS="" \grep '^rvm_'
  215. export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
  216. ;;
  217. (--help)
  218. install_usage
  219. exit 0
  220. ;;
  221. (*)
  222. echo "Unrecognized option: $token"
  223. install_usage
  224. exit 1
  225. ;;
  226. esac
  227. done
  228. if [[ -n "${DESTDIR}" ]]
  229. then
  230. rvm_prefix="${DESTDIR}"
  231. fi
  232. }
  233. install_usage()
  234. {
  235. printf "%b" "
  236. Usage:
  237. ${0} [options]
  238. options:
  239. --auto-dotfiles : Automatically update shell profile files.
  240. --ignore-dotfiles : Do not update shell profile files.
  241. --path : Installation directory (rvm_path).
  242. --help : Display usage information
  243. --version : display rvm package version
  244. "
  245. }
  246. setup_installer()
  247. {
  248. export rvm_prefix rvm_path rvm_user_install_flag rvm_debug_flag rvm_trace_flag upgrade_flag HOME
  249. HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
  250. if
  251. [[ -z "${rvm_path:-}" ]]
  252. then
  253. if (( UID == 0 ))
  254. then rvm_path="/usr/local/rvm"
  255. else rvm_path="${HOME}/.rvm"
  256. fi
  257. rvm_prefix="${rvm_path%/*}"
  258. fi
  259. : \
  260. rvm_bin_path:${rvm_bin_path:=$rvm_path/bin} \
  261. rvm_man_path:${rvm_man_path:=$rvm_path/man} \
  262. rvm_user_path:${rvm_user_path:=$rvm_path/user} \
  263. rvm_scripts_path:${rvm_scripts_path:=$rvm_path/scripts}
  264. # duplication marker kkdfkgnjfndgjkndfjkgnkfjdgn
  265. [[ -n "${rvm_user_install_flag:-}" ]] ||
  266. case "$rvm_path" in
  267. (/usr/local/rvm) rvm_user_install_flag=0 ;;
  268. ($HOME/*|/${USER// /_}*) rvm_user_install_flag=1 ;;
  269. (*) rvm_user_install_flag=0 ;;
  270. esac
  271. if [[ -d "$rvm_path" && -s "${rvm_path}/scripts/rvm" ]]
  272. then upgrade_flag=1
  273. else upgrade_flag=0
  274. fi
  275. }
  276. load_rvm()
  277. {
  278. export install_source_path="$0"
  279. install_source_path="${install_source_path%/install}"
  280. install_source_path="${install_source_path%/scripts}" # install -> scripts/install
  281. \typeset save_rvm_scripts_path="$rvm_scripts_path"
  282. export rvm_scripts_path="${install_source_path}/scripts"
  283. source "$rvm_scripts_path/base"
  284. source "$rvm_scripts_path/functions/autolibs"
  285. source "$rvm_scripts_path/functions/group"
  286. source "$rvm_scripts_path/functions/pkg"
  287. rvm_scripts_path="$save_rvm_scripts_path"
  288. if [[ "$install_source_path/scripts" != "." && "$install_source_path/scripts" != "$PWD" ]]
  289. then __rvm_cd "$install_source_path"
  290. fi
  291. true "${source_path:=${PWD%%+(\/)}}"
  292. }
  293. system_installation_check()
  294. {
  295. case "${_system_type}" in
  296. Linux|Darwin|SunOS|BSD)
  297. return 0 # Accounted for, continue.
  298. ;;
  299. *)
  300. # it will report 'unknown' or even nothing here!
  301. rvm_error "Installing RVM as root is currently only supported on the following known OS's (uname):
  302. Linux, FreeBSD, OpenBSD, DragonFly, Darwin and SunOS
  303. Whereas your OS is reported as '${_system_type}'"
  304. return 1
  305. ;;
  306. esac
  307. }
  308. setup_rvm_group_and_users()
  309. {
  310. if
  311. __rvm_group_exists "$rvm_group_name"
  312. then
  313. rvm_debug "Group '$rvm_group_name' already exists"
  314. else
  315. rvm_log "Creating group '$rvm_group_name'"
  316. __rvm_create_group "${rvm_group_name}" "${rvm_group_id:-}"
  317. fi
  318. if
  319. [[ -n "${rvm_add_users_to_rvm_group:-}" ]]
  320. then
  321. \typeset __user
  322. \typeset -a __users
  323. if
  324. [[ "$rvm_add_users_to_rvm_group" == "all" ]]
  325. then
  326. __users=( $( __rvm_list_all_users ) )
  327. else
  328. if [[ -n "${ZSH_VERSION:-}" ]]
  329. then __users=( ${=rvm_add_users_to_rvm_group//,/ } )
  330. else __users=( ${rvm_add_users_to_rvm_group//,/ } )
  331. fi
  332. fi
  333. for __user in "${__users[@]}"
  334. do
  335. if
  336. __rvm_is_user_in_group "$rvm_group_name" "$__user"
  337. then
  338. rvm_debug "User '$__user' already in the RVM group '${rvm_group_name}'"
  339. else
  340. rvm_log "Adding user '$__user' to the RVM group '${rvm_group_name}'"
  341. __rvm_add_user_to_group "$rvm_group_name" "$__user"
  342. fi
  343. done
  344. fi
  345. }
  346. print_install_header()
  347. {
  348. if [[ ${upgrade_flag:-0} -eq 1 ]]
  349. then rvm_notify "Upgrading the RVM installation in $rvm_path/"
  350. else rvm_notify "Installing RVM to $rvm_path/"
  351. fi
  352. }
  353. cleanse_old_entities()
  354. {
  355. #
  356. # Remove old files that no longer exist.
  357. #
  358. for script in utility array
  359. do
  360. if test -f "$rvm_path/scripts/${script}"
  361. then \command \rm -f "$rvm_path/scripts/${script}"
  362. fi
  363. done
  364. return 0
  365. }
  366. create_install_paths()
  367. {
  368. \typeset -a install_paths
  369. install_paths=(
  370. archives src log bin gems man rubies config user tmp gems environments wrappers
  371. )
  372. for install_path in "${install_paths[@]}"
  373. do [[ -d "$rvm_path/$install_path" ]] || mkdir -p "$rvm_path/$install_path"
  374. done
  375. [[ -z "$rvm_bin_path" || -d "$rvm_bin_path" ]] || mkdir -p "$rvm_bin_path"
  376. return 0
  377. }
  378. # duplication marker kdfkjkjfdkfjdjkdfkjfdkj
  379. load_custom_flags()
  380. {
  381. if
  382. [[ -s "${rvm_path:-}/user/custom_flags" ]]
  383. then
  384. \typeset __key __value
  385. while IFS== read __key __value
  386. do
  387. eval "export ${__key}=\"\${__value}\""
  388. done < "${rvm_path:-}/user/custom_flags"
  389. fi
  390. }
  391. save_custom_flags()
  392. {
  393. \typeset -a __variables
  394. __variables=(
  395. ^rvm_ignore_dotfiles_flag=
  396. )
  397. \typeset IFS="|"
  398. set | __rvm_grep -E "${__variables[*]}" > "${rvm_path:-}/user/custom_flags"
  399. true # no failing from __rvm_grep filtering
  400. }
  401. install_rvm_directories()
  402. {
  403. for entry in $(__rvm_find -L config patches patchsets gem-cache contrib examples lib hooks help docs scripts -type d 2>/dev/null)
  404. do
  405. # Target is supposed to be a directory, remove if it is a file.
  406. if [[ -f "$rvm_path/$entry" ]]
  407. then \command \rm -f "$rvm_path/$entry"
  408. fi
  409. [[ -d "$rvm_path/$entry" ]] || mkdir -p "$rvm_path/$entry"
  410. done
  411. }
  412. install_rvm_files()
  413. {
  414. for file in README.md LICENSE VERSION
  415. do
  416. __rvm_cp -f "$source_path/${file}" "$rvm_path/${file}"
  417. done
  418. for entry in $(__rvm_find -L config patches gem-cache contrib examples lib help docs -type f 2>/dev/null)
  419. do
  420. # Target is supposed to be a file, remove if it is a directory.
  421. if [[ -d "$rvm_path/$entry" ]]
  422. then __rvm_rm_rf "$rvm_path/$entry"
  423. fi
  424. \command \cat < "$source_path/$entry" > "$rvm_path/$entry"
  425. if [[ -x "$source_path/$entry" && ! -x "$rvm_path/$entry" ]]
  426. then chmod +x "$rvm_path/$entry"
  427. fi
  428. done
  429. }
  430. install_rvm_scripts()
  431. {
  432. case "${_system_type}" in
  433. (SunOS)
  434. # SmartOS bash and /opt/local/bin/test have a bug checking for executable bit when
  435. # run as root user. Reported here: https://github.com/joyent/smartos-live/issues/318
  436. chmod_if_needed()
  437. {
  438. if /usr/bin/test -x "$1" && ! /usr/bin/test -x "$2"
  439. then chmod +x "$2"
  440. fi
  441. }
  442. ;;
  443. *)
  444. chmod_if_needed()
  445. {
  446. if [[ -x "$1" && ! -x "$2" ]]
  447. then chmod +x "$2"
  448. fi
  449. }
  450. ;;
  451. esac
  452. for entry in $(__rvm_find -L scripts -type f 2>/dev/null)
  453. do
  454. # Target is supposed to be a file, remove if it is a directory.
  455. if [[ -d "$rvm_path/$entry" ]]
  456. then __rvm_rm_rf "$rvm_path/$entry"
  457. fi
  458. if
  459. [[ "$entry" == "scripts/extras/completion.zsh/_rvm" || "$entry" == "scripts/zsh/Completion/_rvm" ]]
  460. then
  461. if [[ ! -f "$rvm_path/$entry" ]] || __rvm_rm_rf "$rvm_path/$entry" 2>/dev/null
  462. then __rvm_cp -f "$source_path/$entry" "$rvm_path/$entry"
  463. else rvm_log " Can not update '$entry', it's a conflict between Zsh and multiuser installation, prefix the command with 'rvmsudo' to update this file."
  464. fi
  465. else
  466. \command \cat < "$source_path/$entry" > "$rvm_path/$entry"
  467. chmod_if_needed "$source_path/$entry" "$rvm_path/$entry"
  468. fi
  469. done
  470. true # for osx
  471. }
  472. cleanup_old_help_and_docs_files()
  473. {
  474. find "$rvm_path/help" -type f \! \( -name '*.md' -o -name '*.txt' \) -exec rm '{}' \;
  475. find "$rvm_path/docs" -type f \! \( -name '*.md' -o -name '*.txt' \) -exec rm '{}' \;
  476. true # for osx
  477. }
  478. install_rvm_hooks()
  479. {
  480. \typeset hook_x_flag entry name
  481. for entry in $(__rvm_find -L hooks -type f 2>/dev/null)
  482. do
  483. # Target is supposed to be a file, remove if it is a directory.
  484. if [[ -d "$rvm_path/$entry" ]]
  485. then __rvm_rm_rf "$rvm_path/$entry"
  486. fi
  487. # Source is first level hook (after_use) and target is custom user hook, preserve it
  488. if
  489. [[ -f "$rvm_path/$entry" ]] &&
  490. __rvm_grep -E '^hooks/[[:alpha:]]+_[[:alpha:]]+$' >/dev/null <<<"$entry" &&
  491. ! __rvm_grep "$(basename ${entry})_\*" "$rvm_path/$entry" >/dev/null
  492. then
  493. \command \mv -f "$rvm_path/$entry" "$rvm_path/${entry}_custom"
  494. fi
  495. hook_x_flag=0
  496. [[ -x "$rvm_path/$entry" ]] || hook_x_flag=$?
  497. __rvm_cp -f "$source_path/$entry" "$rvm_path/$entry"
  498. if (( hook_x_flag == 0 ))
  499. then [[ -x "$rvm_path/$entry" ]] || chmod a+rx "$rvm_path/$entry"
  500. fi
  501. done
  502. }
  503. remove_old_hooks()
  504. {
  505. for entry in after_use_custom after_use after_cd
  506. do
  507. name=${entry#after_}
  508. name=${name%_*}
  509. if
  510. [[ -f "$rvm_path/hooks/$entry" ]] &&
  511. __rvm_grep "after_${name}_\*" "$rvm_path/hooks/$entry" >/dev/null
  512. then
  513. \command \rm -f "$rvm_path/hooks/$entry"
  514. fi
  515. done
  516. }
  517. install_binaries()
  518. {
  519. \typeset -a files
  520. \typeset system_bin
  521. files=(
  522. rvm-prompt rvm rvmsudo rvm-shell rvm-smile rvm-exec rvm-auto-ruby
  523. ruby-rvm-env rvm-shebang-ruby
  524. )
  525. [[ -d "${rvm_bin_path}" ]] || mkdir -p "${rvm_bin_path}"
  526. for file in "${files[@]}"
  527. do
  528. if [[ -e "${rvm_bin_path}/${file}" ]] &&
  529. [[ ! -f "${rvm_bin_path}/${file}" || -L "${rvm_bin_path}/${file}" ]]
  530. then \command \rm -f "${rvm_bin_path}/${file}"
  531. fi
  532. if
  533. [[ -L "${source_path}/bin/${file}" ]]
  534. then
  535. ln -s "$( readlink "${source_path}/bin/${file}" )" "${rvm_bin_path}/${file}"
  536. else
  537. \command \cat < "${source_path}/bin/${file}" > "${rvm_bin_path}/${file}"
  538. fi
  539. [[ -x "${rvm_bin_path}/${file}" ]] || chmod a+rx "${rvm_bin_path}/${file}"
  540. # try to clean old installer files left in usual places added to PATH
  541. for system_bin in ~/bin /usr/bin /usr/local/bin
  542. do
  543. if
  544. [[ "${system_bin}" != "${rvm_bin_path}" && -x "${system_bin}/${file}" ]]
  545. then
  546. \command \rm -f "${system_bin}/${file}" 2>/dev/null ||
  547. rvm_out "!!! could not remove ${system_bin}/${file}, remove it manually with:
  548. !!! > sudo \command \rm -f ${system_bin}/${file}
  549. "
  550. fi
  551. done
  552. done
  553. return 0
  554. }
  555. update_gemsets_rvmrc()
  556. {
  557. if
  558. [[ -n "$2" ]]
  559. then
  560. if [[ -f ~/.rvmrc ]] && __rvm_grep "^$1=" ~/.rvmrc >/dev/null
  561. then __rvm_sed_i ~/.rvmrc -e "s/^$1=.*$/$1=\"$2\"/"
  562. else printf "%b" "\n$1=\"$2\"\n" >> ~/.rvmrc
  563. fi
  564. else
  565. if [[ -f ~/.rvmrc ]]
  566. then __rvm_sed_i ~/.rvmrc -e "/^$1=/ d"
  567. fi
  568. fi
  569. }
  570. install_gemsets()
  571. {
  572. \typeset gemset_files
  573. if [[ ${rvm_keep_gemset_defaults_flag:-0} == 0 && -d "$rvm_path/gemsets" ]]
  574. then __rvm_find "$rvm_path/gemsets" -type f -exec rm '{}' \;
  575. fi
  576. [[ -d "$rvm_path/gemsets" ]] || mkdir -p "$rvm_path/gemsets"
  577. __rvm_read_lines gemset_files <(
  578. __rvm_find "gemsets" "${name_opt}" '*.gems'
  579. )
  580. for gemset_file in "${gemset_files[@]}"
  581. do
  582. destination="$rvm_path/gemsets/${gemset_file#gemsets/}"
  583. if
  584. [[ ! -s "$destination" ]]
  585. then
  586. destination_path="${destination%/*}"
  587. [[ -d "$destination_path" ]] || mkdir -p "$destination_path"
  588. \command \cat < "$gemset_file" > "$destination"
  589. fi
  590. done
  591. update_gemsets_rvmrc rvm_without_gems "${rvm_without_gems}"
  592. update_gemsets_rvmrc rvm_with_gems "${rvm_with_gems}"
  593. update_gemsets_rvmrc rvm_with_default_gems "${rvm_with_default_gems}"
  594. }
  595. install_patchsets()
  596. {
  597. if
  598. [[ ${rvm_keep_patchsets_flag:-0} == 0 && -d "$rvm_path/patchsets" ]]
  599. then
  600. __rvm_find "$rvm_path/patchsets/" -type f -exec rm '{}' \;
  601. fi
  602. if
  603. [[ -d patchsets/ ]]
  604. then
  605. [[ -d "$rvm_path/patchsets" ]] || mkdir -p "$rvm_path/patchsets"
  606. patchsets=($(
  607. __rvm_find patchsets/ -type f
  608. ))
  609. for patchset_file in "${patchsets[@]}"
  610. do
  611. destination="$rvm_path/$patchset_file"
  612. if
  613. [[ ! -s "$destination" || "${patchset_file##*/}" == "default" ]]
  614. then
  615. if [[ -d "$destination" ]]
  616. then \command \rm -f "$destination"
  617. fi
  618. \command \cat < "$patchset_file" > "$destination"
  619. fi
  620. done
  621. fi
  622. }
  623. install_man_pages()
  624. {
  625. files=($(
  626. __rvm_cd "$install_source_path/man"
  627. __rvm_find . -maxdepth 2 -mindepth 1 -type f -print
  628. ))
  629. for file in "${files[@]//.\/}"
  630. do
  631. [[ -d $rvm_man_path/${file%\/*} ]] ||
  632. {
  633. mkdir -p $rvm_man_path/${file%\/*}
  634. install_fix_rights $rvm_man_path/${file%\/*}
  635. }
  636. __rvm_cp -Rf "$install_source_path/man/$file" "$rvm_man_path/$file" || \
  637. rvm_out "
  638. Please run the installer using rvmsudo to fix file permissions
  639. "
  640. install_fix_rights "$rvm_man_path/$file"
  641. done
  642. }
  643. setup_configuration_files()
  644. {
  645. \typeset _save_dir
  646. _save_dir="$PWD"
  647. __rvm_cd "$rvm_path"
  648. if [[ -f config/user ]]
  649. then \command \mv config/user user/db
  650. fi
  651. if [[ -f config/installs ]]
  652. then \command \mv config/installs user/installs
  653. fi
  654. if [[ -s config/rvmrcs ]]
  655. then \command \mv config/rvmrcs user/rvmrcs
  656. fi
  657. [[ -s user/db ]] ||
  658. echo '# User settings, overrides db settings and persists across installs.' >> user/db
  659. [[ -f user/rvmrcs ]] || > user/rvmrcs
  660. [[ -f user/md5 ]] || > user/md5
  661. [[ -f user/sha512 ]] || > user/sha512
  662. # Prune old (keyed-by-hash) trust entries
  663. __rvm_grep '^_' user/rvmrcs > user/rvmrcs.new || true
  664. \command \mv user/rvmrcs.new user/rvmrcs
  665. __rvm_cd "${_save_dir}"
  666. }
  667. setup_login_shell()
  668. {
  669. if [ "$COLORTERM" = "gnome-terminal" ]
  670. then
  671. if __rvm_grep "entry name=['\"]login_shell['\"]" ~/.gconf/apps/gnome-terminal/profiles/Default/%gconf.xml > /dev/null
  672. then
  673. :
  674. else
  675. __rvm_sed_i "/<gconf>/ a<entry name='login_shell' mtime='`date +%s`' type='bool' value='true'/>" ~/.gconf/apps/gnome-terminal/profiles/Default/%gconf.xml
  676. fi
  677. fi
  678. }
  679. check_file_group()
  680. {
  681. \typeset _group
  682. _group="$( __rvm_statf "%G" "%Sg" "$1" )"
  683. [[ "${_group}" == "$2" ]] || return $?
  684. true # for OSX
  685. }
  686. check_file_rights()
  687. {
  688. \typeset _all
  689. _all="$( __rvm_statf "%A" "%Sp" "$1" )"
  690. shift
  691. while
  692. (( $# ))
  693. do
  694. case "$1" in
  695. (g+w) [[ "${_all:5:1}" == "w" ]] || return $? ;;
  696. (a+r) [[ "${_all:7:1}" == "r" ]] || return $? ;;
  697. (a-r) [[ "${_all:7:1}" == "-" ]] || return $? ;;
  698. esac
  699. shift
  700. done
  701. true # for OSX
  702. }
  703. permissions_warning()
  704. {
  705. rvm_warn " $1, prefix the command with 'rvmsudo' to fix it, if the situation persist report a bug."
  706. if [[ -n "${2:-}" ]]
  707. then return $2
  708. fi
  709. }
  710. install_fix_rights()
  711. {
  712. (( ${rvm_user_install_flag:-0} == 0 )) || return 0
  713. check_file_group "$1" "$rvm_group_name" || chown :$rvm_group_name "$1" || permissions_warning "could not set group of '$1'"
  714. check_file_rights "$1" g+w || chmod g+rwX "$1" || permissions_warning "could not fix perissions of '$1'"
  715. }
  716. setup_etc_profile()
  717. {
  718. export etc_profile_file="/etc/profile.d/rvm.sh"
  719. if [[ -s "${etc_profile_file}" ]] || (( ${rvm_auto_dotfiles_flag:-1} == 0 ))
  720. then return 0
  721. fi
  722. \typeset executable add_to_profile_flag zshrc_file ps_ucomm_alias
  723. if
  724. [[ -d /etc/profile.d ]]
  725. then
  726. add_to_profile_flag=0
  727. executable=1
  728. else
  729. add_to_profile_flag=1
  730. executable=0
  731. mkdir -p /etc/profile.d
  732. fi
  733. if [[ "$(uname)" == "SunOS" ]]
  734. then
  735. # Solaris default ps doesn't provide ucomm
  736. ps_ucomm_alias=comm
  737. else
  738. ps_ucomm_alias=ucomm
  739. fi
  740. # partial duplication marker dkjnkjvnckbjncvbkjnvkj
  741. # prevent from loading in sh shells
  742. printf "%b" "#
  743. # RVM profile
  744. #
  745. # /etc/profile.d/rvm.sh # sh extension required for loading.
  746. #
  747. if
  748. [ -n \"\${BASH_VERSION:-}\" -o -n \"\${ZSH_VERSION:-}\" ] &&
  749. test \"\`\\\\command \\\\ps -p \$\$ -o ${ps_ucomm_alias}=\`\" != dash &&
  750. test \"\`\\\\command \\\\ps -p \$\$ -o ${ps_ucomm_alias}=\`\" != sh
  751. then
  752. [[ -n \"\${rvm_stored_umask:-}\" ]] || export rvm_stored_umask=\$(umask)
  753. # Load user rvmrc configurations, if exist
  754. for file in \"/etc/rvmrc\" \"\$HOME/.rvmrc\"
  755. do
  756. [[ -s \"\$file\" ]] && source \$file
  757. done
  758. if
  759. [[ -n \"\${rvm_prefix:-}\" ]] &&
  760. [[ -s \"\${rvm_prefix}/.rvmrc\" ]] &&
  761. [[ ! \"\$HOME/.rvmrc\" -ef \"\${rvm_prefix}/.rvmrc\" ]]
  762. then
  763. source \"\${rvm_prefix}/.rvmrc\"
  764. fi
  765. # Load RVM if it is installed, try user then root install
  766. if
  767. [[ -s \"\$rvm_path/scripts/rvm\" ]]
  768. then
  769. source \"\$rvm_path/scripts/rvm\"
  770. elif
  771. [[ -s \"\$HOME/.rvm/scripts/rvm\" ]]
  772. then
  773. true \${rvm_path:=\"\$HOME/.rvm\"}
  774. source \"\$HOME/.rvm/scripts/rvm\"
  775. elif
  776. [[ -s \"/usr/local/rvm/scripts/rvm\" ]]
  777. then
  778. true \${rvm_path:=\"/usr/local/rvm\"}
  779. source \"/usr/local/rvm/scripts/rvm\"
  780. fi
  781. # Add \$rvm_bin_path to \$PATH if necessary. Make sure this is the last PATH variable change
  782. if [[ -n \"\${rvm_bin_path}\" && ! \":\${PATH}:\" == *\":\${rvm_bin_path}:\"* ]]
  783. then PATH=\"\${PATH}:\${rvm_bin_path}\"
  784. fi
  785. fi
  786. " > "${etc_profile_file}"
  787. if
  788. (( executable )) && check_file_rights "${etc_profile_file}" a-x
  789. then
  790. chmod a+rx "${etc_profile_file}" || permissions_warning "could not fix '${etc_profile_file}' rights"
  791. fi
  792. if
  793. (( add_to_profile_flag )) &&
  794. ! __rvm_grep "source ${etc_profile_file}" /etc/profile >/dev/null 2>&1
  795. then
  796. printf "%b" "\ntest -f ${etc_profile_file} && source ${etc_profile_file}\n" >> /etc/profile
  797. fi
  798. for zshrc_file in $(
  799. __rvm_find /etc/ -name zprofile -type f 2>/dev/null ;
  800. __rvm_find /etc/ -name zlogin -type f 2>/dev/null ;
  801. true
  802. ) /etc/zprofile
  803. do
  804. if
  805. [[ ! -f "${zshrc_file}" ]]
  806. then
  807. printf "%b" "\ntest -f ${etc_profile_file} && source ${etc_profile_file}\n" > $zshrc_file
  808. elif
  809. ! __rvm_grep "source /etc/bash" "${zshrc_file}" &&
  810. ! __rvm_grep "source /etc/profile" "${zshrc_file}"
  811. then
  812. printf "%b" "\ntest -f ${etc_profile_file} && source ${etc_profile_file}\n" >> $zshrc_file
  813. fi
  814. break # process only first file found
  815. done
  816. }
  817. print_etc_bashrc_change()
  818. {
  819. printf "%b" "
  820. type rvm >/dev/null 2>/dev/null || echo \${PATH} | __rvm_grep \"${rvm_bin_path}\" > /dev/null || export PATH=\"\${PATH}:${rvm_bin_path}\"
  821. "
  822. }
  823. # Ubuntu does not source /etc/profile when we're running command such as "ssh my-ubuntu env"
  824. # So we add source ${etc_profile_file} in /etc/bash.bashrc
  825. setup_etc_bashrc()
  826. {
  827. \typeset system_bashrc_file new_content_path
  828. system_bashrc_file="/etc/bash.bashrc"
  829. if [[ -s "${system_bashrc_file}" ]] || (( ${rvm_auto_dotfiles_flag:-1} == 0 ))
  830. then return 0
  831. fi
  832. if
  833. [[ ! -f "${system_bashrc_file}" ]]
  834. then
  835. print_etc_bashrc_change > "${system_bashrc_file}" 2>/dev/null ||
  836. permissions_warning "could not create '${system_bashrc_file}'" $? ||
  837. return $?
  838. elif
  839. ! __rvm_grep "PATH=.*${rvm_bin_path}" "${system_bashrc_file}" >/dev/null
  840. then
  841. new_content_path="$( mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXXXXXXXXXX )"
  842. [[ ! -f "${new_content_path}" ]] || \command \rm -f "${new_content_path}"
  843. {
  844. print_etc_bashrc_change # prepend
  845. __rvm_grep -v "|| export PATH=\"\${PATH}:\"" < "${system_bashrc_file}"
  846. true
  847. } > "${new_content_path}" &&
  848. \command \mv "${new_content_path}" "${system_bashrc_file}" 2>/dev/null ||
  849. permissions_warning "could not update '${system_bashrc_file}'" $? ||
  850. return $?
  851. fi
  852. check_file_rights $system_bashrc_file a+r ||
  853. chmod a+r $system_bashrc_file ||
  854. permissions_warning "File '$system_bashrc_file' is not readable for all users, this might cause problems in loading RVM" $? ||
  855. return $?
  856. }
  857. setup_etc_rvmrc()
  858. {
  859. rvmrc_file="/etc/rvmrc"
  860. if
  861. [[ -f $rvmrc_file ]] &&
  862. __rvm_grep '#umask' $rvmrc_file >/dev/null
  863. then
  864. true # commented out, skip it!
  865. elif
  866. [[ -f $rvmrc_file ]] &&
  867. __rvm_grep 'umask g+w' $rvmrc_file >/dev/null
  868. then
  869. __rvm_sed_i $rvmrc_file -e 's/umask g+w/umask u=rwx,g=rwx,o=rx/'
  870. elif
  871. ! [[ -f $rvmrc_file ]] ||
  872. ! __rvm_grep 'umask' $rvmrc_file >/dev/null
  873. then
  874. echo 'umask u=rwx,g=rwx,o=rx' >> $rvmrc_file
  875. fi
  876. if
  877. [[ "${rvm_path}" != "/usr/local/rvm" ]] &&
  878. ! __rvm_grep 'rvm_path' $rvmrc_file >/dev/null
  879. then
  880. echo "rvm_path=\"${rvm_path}\"" >> $rvmrc_file
  881. fi
  882. if [[ -s $rvmrc_file ]]
  883. then install_fix_rights $rvmrc_file
  884. fi
  885. return 0
  886. }
  887. pick_a_file()
  888. {
  889. \typeset _file _result
  890. _result=$1
  891. shift
  892. for _file
  893. do
  894. if
  895. [[ -f "$_file" ]]
  896. then
  897. eval "${_result}+=( \"\$_file\" )"
  898. return 0
  899. fi
  900. done
  901. eval "${_result}+=( \"\$1\" )"
  902. }
  903. setup_user_profile_check()
  904. {
  905. case "${rvm_ignore_dotfiles_flag:-${rvm_ignore_dotfiles:-no}}" in
  906. (yes|1) return 1 ;;
  907. esac
  908. return 0
  909. }
  910. setup_user_profile_detect()
  911. {
  912. etc_profile_file="/etc/profile.d/rvm.sh"
  913. search_list_mksh=( "$HOME/.mkshrc" "$HOME/.profile" )
  914. search_list_bash=( "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.bash_login" )
  915. search_list_zsh=( "${ZDOTDIR:-${HOME}}/.zshenv" "${ZDOTDIR:-${HOME}}/.zprofile" "${ZDOTDIR:-${HOME}}/.zshrc" "${ZDOTDIR:-${HOME}}/.zlogin" )
  916. search_list=( "${search_list_mksh[@]}" "${search_list_bash[@]}" "${search_list_zsh[@]}" )
  917. target_rc=( "$HOME/.profile" "$HOME/.mkshrc" "$HOME/.bashrc" "${ZDOTDIR:-${HOME}}/.zshrc" )
  918. target_login=( "$HOME/.profile" )
  919. pick_a_file target_login "$HOME/.bash_profile" "$HOME/.bash_login"
  920. target_login+=( "${ZDOTDIR:-${HOME}}/.zlogin" )
  921. for profile_file in "${search_list[@]}"
  922. do
  923. if
  924. [[ -f "$profile_file" ]]
  925. then
  926. if
  927. __rvm_grep PATH=.*$local_rvm_path/bin "$profile_file" >/dev/null
  928. then
  929. found_rc+=( "$profile_file" )
  930. fi
  931. if
  932. __rvm_grep \..*scripts/rvm "$profile_file" >/dev/null
  933. then
  934. found_login+=( "$profile_file" )
  935. elif
  936. __rvm_grep source.*scripts/rvm "$profile_file" >/dev/null
  937. then
  938. found_login+=( "$profile_file" )
  939. fi
  940. fi
  941. done
  942. }
  943. setup_user_profile_summary()
  944. {
  945. eval "\typeset __list_found=\"\${${1}[*]}\""
  946. \typeset __target="$2"
  947. rvm_log " RVM ${__target} line found in ${__list_found}."
  948. \typeset __bash_included=0
  949. \typeset __zsh_included=0
  950. __rvm_string_includes "${__list_found}" "${search_list_bash[@]}" || __bash_included=$?
  951. __rvm_string_includes "${__list_found}" "${search_list_zsh[@]}" || __zsh_included=$?
  952. \typeset __missing=""
  953. if (( __bash_included>0 && __zsh_included>0 ))
  954. then __missing="Bash or Zsh"
  955. elif (( __bash_included>0 ))
  956. then __missing="Bash"
  957. elif (( __zsh_included>0 ))
  958. then __missing="Zsh"
  959. fi
  960. if [[ -n "${__missing}" ]]
  961. then rvm_warn " RVM ${__target} line not found for ${__missing}, rerun this command with '--auto-dotfiles' flag to fix it."
  962. fi
  963. }
  964. setup_user_profile_rc()
  965. {
  966. if
  967. (( rvm_auto_dotfiles_flag == 1 && ${#found_rc[@]} > 0 ))
  968. then
  969. rvm_out " Removing rvm PATH line from ${found_rc[*]}."
  970. for profile_file in "${found_rc[@]}"
  971. do
  972. __rvm_sed_i "${profile_file}" -e '/PATH=.*'"$local_rvm_path_sed"'\/bin/ d;'
  973. # also delete duplicate blank lines
  974. __rvm_sed_i "${profile_file}" -e '/^\s*$/{ N; /^\n$/ D; };'
  975. done
  976. found_rc=()
  977. fi
  978. if
  979. (( rvm_auto_dotfiles_flag == 1 || ${#found_rc[@]} == 0 ))
  980. then
  981. rvm_out " Adding rvm PATH line to ${target_rc[*]}."
  982. for profile_file in "${target_rc[@]}"
  983. do
  984. touch "$profile_file"
  985. printf "%b" "
  986. # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
  987. export PATH=\"\$PATH:$local_rvm_path/bin\"
  988. " >> "$profile_file"
  989. done
  990. else
  991. setup_user_profile_summary found_rc "PATH"
  992. fi
  993. }
  994. setup_user_profile_login()
  995. {
  996. if
  997. (( rvm_auto_dotfiles_flag == 1 && ${#found_login[@]} > 0 ))
  998. then
  999. rvm_out " Removing rvm loading line from ${found_login[*]}."
  1000. for profile_file in "${found_login[@]}"
  1001. do
  1002. __rvm_sed_i "${profile_file}" -e '/source.*scripts\/rvm/ d; /\. .*scripts\/rvm/ d;'
  1003. # also delete duplicate blank lines
  1004. __rvm_sed_i "${profile_file}" -e '/^\s*$/{ N; /^\n$/ D; };'
  1005. done
  1006. found_rc=()
  1007. fi
  1008. if
  1009. (( rvm_auto_dotfiles_flag == 1 || ${#found_login[@]} == 0 ))
  1010. then
  1011. rvm_out " Adding rvm loading line to ${target_login[*]}."
  1012. for profile_file in "${target_login[@]}"
  1013. do
  1014. [[ -f "$profile_file" ]] ||
  1015. {
  1016. touch "$profile_file"
  1017. if
  1018. [[ "$profile_file" == "$HOME/.bash_"* && -f "$HOME/.profile" ]]
  1019. then
  1020. printf "%b" "
  1021. [[ -s \"\$HOME/.profile\" ]] && source \"\$HOME/.profile\" # Load the default .profile
  1022. " >> "$profile_file"
  1023. fi
  1024. }
  1025. printf "%b" "
  1026. [[ -s \"$local_rvm_path/scripts/rvm\" ]] && source \"$local_rvm_path/scripts/rvm\" # Load RVM into a shell session *as a function*
  1027. " >> "$profile_file"
  1028. done
  1029. else
  1030. setup_user_profile_summary found_login "sourcing"
  1031. fi
  1032. }
  1033. setup_user_profile()
  1034. {
  1035. setup_user_profile_check || return 0
  1036. export user_profile_file
  1037. \typeset -a search_list search_list_mksh search_list_bash search_list_zsh
  1038. \typeset -a target_rc target_login found_rc found_login
  1039. \typeset etc_profile_file profile_file local_rvm_path local_rvm_path_sed
  1040. local_rvm_path="${rvm_path/#$HOME/\$HOME}"
  1041. local_rvm_path_sed="\\${local_rvm_path//\./\\.}"
  1042. local_rvm_path_sed="${local_rvm_path_sed//\//\/}"
  1043. setup_user_profile_detect
  1044. setup_user_profile_rc
  1045. setup_user_profile_login
  1046. true # for osx
  1047. }
  1048. warning_no_loading_of_rvm()
  1049. {
  1050. rvm_error " Warning! Installing RVM in system mode without root permissions, make sure to modify PATH / source rvm when it's needed."
  1051. }
  1052. cleanse_old_environments()
  1053. {
  1054. if
  1055. [[ -d "$rvm_path/environments" ]]
  1056. then
  1057. for file in "$rvm_path/environments"/*
  1058. do
  1059. # Remove broken links
  1060. if
  1061. [[ -L "$file" && ! -e "$file" ]]
  1062. then
  1063. rm -f "$file"
  1064. fi
  1065. if
  1066. [[ -f "$file" ]]
  1067. then
  1068. # Remove BUNDLE_PATH from environment files
  1069. if
  1070. __rvm_grep 'BUNDLE_PATH' "$file" >/dev/null 2>&1
  1071. then
  1072. __rvm_grep -v 'BUNDLE_PATH' "$file" > "$file.new" &&
  1073. \command \mv "$file.new" "$file"
  1074. fi
  1075. # regenerate when found broken path :/bin:/bin or missing $PATH
  1076. if
  1077. __rvm_grep ':/bin:/bin' "$file" >/dev/null 2>&1 ||
  1078. __rvm_grep "[^_]PATH=" "$file" | __rvm_grep -v "\$PATH" >/dev/null 2>&1
  1079. then
  1080. ruby_version="${file##*environments/}"
  1081. rvm_out " Fixing environment for ${ruby_version}."
  1082. __rvm_with "${ruby_version}" __rvm_ensure_has_environment_files
  1083. fi
  1084. fi
  1085. done
  1086. fi
  1087. }
  1088. migrate_old_gemsets()
  1089. {
  1090. for gemset in "$rvm_path"/gems/*\%*
  1091. do
  1092. new_path=${gemset/\%/${rvm_gemset_separator:-"@"}}
  1093. if
  1094. [[ -d "$gemset" ]] && [[ ! -d "$new_path" ]]
  1095. then
  1096. rvm_out " Renaming $(basename "$gemset") to $(basename "$new_path") for new gemset separator."
  1097. \command \mv "$gemset" "$new_path"
  1098. fi
  1099. done
  1100. for gemset in "$rvm_path"/gems/*\+*
  1101. do
  1102. new_path=${gemset/\+/${rvm_gemset_separator:-"@"}}
  1103. if
  1104. [[ -d "$gemset" && ! -d "$new_path" ]]
  1105. then
  1106. rvm_out " Renaming $(basename "$gemset") to $(basename "$new_path") for new gemset separator."
  1107. \command \mv $gemset $new_path
  1108. fi
  1109. done
  1110. for gemset in "$rvm_path"/gems/*\@
  1111. do
  1112. new_path="$( __rvm_sed -e 's#\@$##' <<<"$gemset" )"
  1113. if
  1114. [[ -d "$gemset" && ! -d "$new_path" ]]
  1115. then
  1116. rvm_out " Fixing: $(basename "$gemset") to $(basename "$new_path") for new gemset separator."
  1117. \command \mv "$gemset" "$new_path"
  1118. fi
  1119. done
  1120. }
  1121. # Move from legacy defaults to the new, alias based system.
  1122. migrate_defaults()
  1123. {
  1124. [[ -s "$rvm_path/config/default" ]] || return 0
  1125. \typeset original_version="$(
  1126. basename "$(
  1127. __rvm_grep GEM_HOME "$rvm_path/config/default" |
  1128. __rvm_awk -F"'" '{print $2}' | __rvm_sed "s#\%#${rvm_gemset_separator:-"@"}#"
  1129. )"
  1130. )"
  1131. if [[ -n "$original_version" ]]
  1132. then "$rvm_scripts_path/alias" create default "$original_version" &> /dev/null
  1133. fi
  1134. __rvm_rm_rf "$rvm_path/config/default"
  1135. }
  1136. migrate_environments_and_wrappers()
  1137. {
  1138. \typeset environment_file wrappers_path new_path ruby_version
  1139. for environment_file in "$rvm_path"/environments/*
  1140. do
  1141. ruby_version="${environment_file##*/}"
  1142. new_path="$rvm_path/gems/${ruby_version}/environment"
  1143. if
  1144. [[ -f "$environment_file" && ! -L "$environment_file" && -d "${new_path%/*}" && ! -e "$new_path" ]]
  1145. then
  1146. rvm_out " Migrating environment ${ruby_version} to use with 'gem-wrappers' gem."
  1147. \command \mv "$environment_file" "$new_path" && \command \ln -s "$new_path" "$environment_file"
  1148. fi
  1149. done
  1150. for wrappers_path in "$rvm_path"/wrappers/*
  1151. do
  1152. ruby_version="${wrappers_path##*/}"
  1153. new_path="$rvm_path/gems/${ruby_version}/wrappers"
  1154. if
  1155. [[ -d "$wrappers_path" && ! -L "$wrappers_path" && -d "${new_path%/*}" && ! -e "$new_path" ]]
  1156. then
  1157. rvm_out " Migrating wrappers ${ruby_version} to use with 'gem-wrappers' gem."
  1158. \command \mv "$wrappers_path" "$new_path" && \command \ln -snf "$new_path" "$wrappers_path"
  1159. fi
  1160. done
  1161. __rvm_grep -rl 'unset GEM_HOME' "$rvm_path/gems"/*/environment "$rvm_path/environments"/ 2>/dev/null |
  1162. while read environment_file
  1163. do
  1164. ruby_version="${environment_file%/environment}"
  1165. ruby_version="${ruby_version##*/}"
  1166. rvm_out " Fixing environment for ${ruby_version}."
  1167. __rvm_with "${ruby_version}" __rvm_ensure_has_environment_files
  1168. done
  1169. }
  1170. create_gems_aliases()
  1171. {
  1172. [[ -s "$rvm_path/config/alias" ]] || return 0
  1173. \typeset __alias __ruby
  1174. \typeset -a __aliases
  1175. __rvm_read_lines __aliases "$rvm_path/config/alias"
  1176. for __alias in "${__aliases[@]}"
  1177. do
  1178. __ruby="${__alias#*=}"
  1179. __alias="${__alias%%=*}"
  1180. [[ -e "$rvm_path/gems/${__alias}" ]] ||
  1181. \command \ln -snf "$rvm_path/gems/${__ruby}" "$rvm_path/gems/${__alias}"
  1182. done
  1183. }
  1184. restore_missing_environments()
  1185. {
  1186. if
  1187. [[ -d "$rvm_path/rubies" ]]
  1188. then
  1189. [[ -d "$rvm_path/environments" ]] || mkdir -p "$rvm_path/environments"
  1190. for ruby_path in "$rvm_path"/rubies/*
  1191. do
  1192. ruby_version="${ruby_path##*/}"
  1193. environment_path="$rvm_path/environments/${ruby_version}"
  1194. if
  1195. [[ "${ruby_version}" == "*" || -e "$environment_path" ]]
  1196. then
  1197. true
  1198. elif
  1199. [[ "${ruby_version}" == "gems" ]]
  1200. then
  1201. rvm_out " Removing unexpected ruby: ${ruby_version}."
  1202. \command \rm -rf "${ruby_path}"
  1203. elif
  1204. [[ -L "$ruby_path" ]]
  1205. then
  1206. ruby_target="$(readlink "$ruby_path")"
  1207. ruby_target="${ruby_target##*/}"
  1208. environment_tareget="$rvm_path/environments/${ruby_target}"
  1209. rvm_out " Fixing environment link for ${ruby_version}."
  1210. \command \ln -nsf "$environment_tareget" "$environment_path"
  1211. else
  1212. rvm_out " Fixing environment for ${ruby_version}."
  1213. __rvm_with "${ruby_version}" __rvm_ensure_has_environment_files
  1214. fi
  1215. done
  1216. fi
  1217. }
  1218. record_ruby_configs()
  1219. {
  1220. __rvm_record_ruby_configs
  1221. }
  1222. update_gemsets_install_rvm()
  1223. {
  1224. \typeset _iterator _gem installed found missing _current_path
  1225. \typeset -a paths missing
  1226. [[ ${rvm_keep_gemset_defaults_flag:-0} == 0 ]] || return 0
  1227. # rvm /gems
  1228. paths=($(
  1229. __rvm_find "$rvm_path/gems" -maxdepth 1 "${name_opt}" '*@global'
  1230. ))
  1231. for _gem in rvm gem-wrappers
  1232. do
  1233. [[ " ${rvm_without_gems:-} " == *" ${_gem} "* ]] ||
  1234. {
  1235. missing=()
  1236. for _iterator in "${paths[@]}"
  1237. do
  1238. # skip unless this ruby is installed
  1239. installed="${_iterator%@global}"
  1240. installed="${installed/\/gems\//\/rubies\//}/bin"
  1241. installed="${installed//\\/}"
  1242. [[ -x "${installed}/ruby" ]] || continue
  1243. [[ -x "${installed}/gem" ]] || continue
  1244. _current_path="${_iterator%%+(\/)}/gems"
  1245. # rvm /gems @global /gems
  1246. found=($(
  1247. [[ ! -d "${_current_path}" ]] ||
  1248. __rvm_find "${_current_path}" -maxdepth 1 "${name_opt}" ${_gem}-'*'
  1249. ))
  1250. (( ${#found[@]} > 0 )) || missing+=( "${installed}=${_iterator}" )
  1251. done
  1252. if
  1253. (( ${#missing[@]} > 0 ))
  1254. then
  1255. for _iterator in "${missing[@]}"
  1256. do
  1257. __gem_home="${_iterator#*=}"
  1258. __rvm_with "${__gem_home##*/}" gem_install ${_gem}
  1259. done | __rvm_dotted " Installing ${_gem} gem in ${#missing[@]} gemsets"
  1260. fi
  1261. if
  1262. [[ "${_gem}" == "gem-wrappers" ]] &&
  1263. (( ${#missing[@]} > 0 ))
  1264. then
  1265. for _iterator in "${missing[@]}"
  1266. do
  1267. installed="${_iterator#*=}"
  1268. installed="${installed%@global}"
  1269. for __gem_home in "${installed}"{,@*}
  1270. do
  1271. if [[ "${__gem_home}" == *"@*" ]]
  1272. then continue
  1273. fi
  1274. __rvm_with "${__gem_home##*/}" gem wrappers regenerate
  1275. done
  1276. done | __rvm_dotted " Regenerating gem wrappers in ${#missing[@]} rubies"
  1277. fi
  1278. }
  1279. done
  1280. }
  1281. configure_autolibs()
  1282. (
  1283. # remove old version from rvmrc
  1284. for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
  1285. do
  1286. if
  1287. [[ -s "$rvmrc" ]] &&
  1288. __rvm_grep 'rvm_autolibs_flag=' "$rvmrc" >/dev/null 2>&1
  1289. then
  1290. [[ -w "$rvmrc" ]] &&
  1291. __rvm_sed '/rvm_autolibs_flag=/ d' < "$rvmrc" > "$rvmrc.backup" &&
  1292. \command \mv -f "$rvmrc.backup" "$rvmrc" ||
  1293. rvm_error " Can not automatically remove lines with 'rvm_autolibs_flag=' from '$rvmrc', please clean it manually."
  1294. fi
  1295. done
  1296. if
  1297. [[ -s "$rvmrc" ]] &&
  1298. __rvm_grep 'rvm_autolibs_flag=' "$rvmrc" >/dev/null 2>&1
  1299. then
  1300. export rvm_autolibs_flag="$( __rvm_awk -F'=' '/rvm_autolibs_flag=/{print $2}' <"$rvmrc" )"
  1301. [[ -w "$rvmrc" ]] &&
  1302. __rvm_sed '/rvm_autolibs_flag/ d' < "$rvmrc" > "$rvmrc.backup" &&
  1303. \command \mv -f "$rvmrc.backup" "$rvmrc" || true
  1304. fi
  1305. # migrate SMF settings
  1306. rvmrc=/etc/rvmrc
  1307. if
  1308. [[ -s "$rvmrc" ]] &&
  1309. __rvm_grep 'rvm_configure_env=.*/opt/sm' "$rvmrc" >/dev/null 2>&1
  1310. then
  1311. export rvm_autolibs_flag=smf
  1312. [[ -w "$rvmrc" ]] &&
  1313. __rvm_sed '/rvm_configure_env/ d' < "$rvmrc" > "$rvmrc.backup" &&
  1314. \command \mv -f "$rvmrc.backup" "$rvmrc" || true
  1315. fi
  1316. [[ -n "${rvm_autolibs_flag:-}" ]] || return 0
  1317. # save if proper value
  1318. if
  1319. __rvm_autolibs_translate
  1320. then
  1321. __rvm_db_ "$rvm_user_path/db" "autolibs" "$rvm_autolibs_flag"
  1322. else
  1323. rvm_error " Unknown mode '$rvm_autolibs_flag' for autolibs, please read 'rvm autolibs'."
  1324. return 1
  1325. fi
  1326. if [[ -x "${rvm_bin_path}/brew" && -L "${rvm_bin_path}/brew" ]]
  1327. then \command \rm -rf "${rvm_bin_path}/brew"
  1328. fi
  1329. )
  1330. update_yaml_if_needed()
  1331. {
  1332. \typeset yaml_version
  1333. __rvm_db "yaml_version" "yaml_version"
  1334. if
  1335. libyaml_installed &&
  1336. ! __rvm_grep -r "${yaml_version//\./\\.}" "${rvm_usr_path:=$rvm_path/usr}" >/dev/null 2>&1
  1337. then
  1338. __rvm_log_command "update_yaml" \
  1339. " Updating libyaml in $rvm_usr_path to version $yaml_version, see https://github.com/rvm/rvm/issues/2594 " \
  1340. install_libyaml
  1341. fi
  1342. }
  1343. record_installation_time()
  1344. {
  1345. __rvm_date +%s > $rvm_path/installed.at
  1346. [[ -s "$rvm_path/RELEASE" ]] || echo "manual" > "$rvm_path/RELEASE"
  1347. touch "$rvm_path/config/displayed-notes.txt"
  1348. return 0
  1349. }
  1350. cleanup_tmp_files()
  1351. {
  1352. files=($(
  1353. __rvm_find "$rvm_path/" -mindepth 1 -maxdepth 2 "${name_opt}" '*.swp' -type f
  1354. ))
  1355. if
  1356. (( ${#files[@]} > 0 ))
  1357. then
  1358. rvm_out " Cleanup any .swp files."
  1359. \command \rm -f "${files[@]}"
  1360. fi
  1361. }
  1362. setup_rvm_path_permissions_root()
  1363. {
  1364. # ignore if not root
  1365. (( UID == 0 )) || return 0
  1366. chown -R root:"$rvm_group_name" "$rvm_path"
  1367. chmod -R u+rwX,g+rwX,o+rX "$rvm_path"
  1368. if [[ -d "$rvm_path" ]]
  1369. then __rvm_find "$rvm_path" -type d -print0 | __rvm_xargs -n1 -0 chmod g+s
  1370. fi
  1371. chmod -R g-ws "$rvm_path/scripts/zsh" "$rvm_path/scripts/extras/completion.zsh"
  1372. }
  1373. setup_rvm_path_permissions_check_single()
  1374. {
  1375. \typeset __ignore __message __file
  1376. __ignore="$1"
  1377. __message="$2"
  1378. shift 2
  1379. \typeset -a __found
  1380. __rvm_read_lines __found <( "$@" )
  1381. if
  1382. (( ${#__found[@]} > __ignore ))
  1383. then
  1384. permissions_warning "Found ${#__found[@]} ${__message},
  1385. use \`--debug\` to see the list, run \`rvmsudo rvm get stable\` to fix it."
  1386. if
  1387. (( ${rvm_debug_flag:-0} ))
  1388. then
  1389. for __file in "${__found[@]}"
  1390. do printf "%b" " ${__file}\n"
  1391. done
  1392. fi
  1393. fi
  1394. }
  1395. setup_rvm_path_permissions_check_group()
  1396. {
  1397. setup_rvm_path_permissions_check_single 0 "files not belonging to '$rvm_group_name'" \
  1398. __rvm_find "$rvm_path" \! -group "$rvm_group_name"
  1399. }
  1400. setup_rvm_path_permissions_check_dirs()
  1401. {
  1402. setup_rvm_path_permissions_check_single 3 "directories with mode different than '775'" \
  1403. __rvm_find "$rvm_path" -type d \! -perm -2775
  1404. }
  1405. setup_rvm_path_permissions_check_files()
  1406. {
  1407. setup_rvm_path_permissions_check_single 2 "files with mode different than '664' or '775'" \
  1408. __rvm_find "$rvm_path" \! -type d \! -type l \! -perm -775 \! -perm -664
  1409. }
  1410. print_install_footer()
  1411. {
  1412. true ${upgrade_flag:=0}
  1413. \typeset itype profile_file
  1414. if (( upgrade_flag == 0 ))
  1415. then itype=Installation
  1416. else itype=Upgrade
  1417. fi
  1418. if
  1419. (( upgrade_flag == 0 ))
  1420. then
  1421. profile_file="${user_profile_file:-${etc_profile_file:-$rvm_path/scripts/rvm}}"
  1422. rvm_log "$itype of RVM in $rvm_path/ is almost complete:"
  1423. if
  1424. (( ${rvm_user_install_flag:=0} == 0 )) &&
  1425. [[ -z "${rvm_add_users_to_rvm_group:-}" ]]
  1426. then
  1427. rvm_out "
  1428. * First you need to add all users that will be using rvm to '${rvm_group_name}' group,
  1429. and logout - login again, anyone using rvm will be operating with \`umask u=rwx,g=rwx,o=rx\`."
  1430. fi
  1431. rvm_out "
  1432. * To start using RVM you need to run \`source ${profile_file}\`
  1433. in all your open shell windows, in rare cases you need to reopen all shell windows."
  1434. else
  1435. rvm_notify "$itype of RVM in $rvm_path/ is complete."
  1436. fi
  1437. }
  1438. display_notes()
  1439. {
  1440. if (( upgrade_flag == 0 ))
  1441. then bash ./scripts/notes initial
  1442. else bash ./scripts/notes upgrade
  1443. fi
  1444. }