#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby

后端开发   发布日期:2025年06月15日   浏览次数:90
  1. #!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
  2. # This script installs to /usr/local only. To install elsewhere you can just
  3. # untar https://github.com/Homebrew/brew/tarball/master anywhere you like or
  4. # change the value of HOMEBREW_PREFIX.
  5. HOMEBREW_PREFIX = "/usr/local".freeze
  6. HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
  7. HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
  8. HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze
  9. BREW_REPO = "https://github.com/Homebrew/brew".freeze
  10. CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
  11. # no analytics during installation
  12. ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
  13. ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] = "1"
  14. module Tty
  15. module_function
  16. def blue
  17. bold 34
  18. end
  19. def red
  20. bold 31
  21. end
  22. def reset
  23. escape 0
  24. end
  25. def bold(n = 39)
  26. escape "1;#{n}"
  27. end
  28. def underline
  29. escape "4;39"
  30. end
  31. def escape(n)
  32. "\033[#{n}m" if STDOUT.tty?
  33. end
  34. end
  35. class Array
  36. def shell_s
  37. cp = dup
  38. first = cp.shift
  39. cp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ")
  40. end
  41. end
  42. def ohai(*args)
  43. puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
  44. end
  45. def warn(warning)
  46. puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
  47. end
  48. def system(*args)
  49. abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
  50. end
  51. def sudo(*args)
  52. args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil?
  53. ohai "/usr/bin/sudo", *args
  54. system "/usr/bin/sudo", *args
  55. end
  56. def getc # NOTE only tested on OS X
  57. system "/bin/stty raw -echo"
  58. if STDIN.respond_to?(:getbyte)
  59. STDIN.getbyte
  60. else
  61. STDIN.getc
  62. end
  63. ensure
  64. system "/bin/stty -raw echo"
  65. end
  66. def wait_for_user
  67. puts
  68. puts "Press RETURN to continue or any other key to abort"
  69. c = getc
  70. # we test for \r and \n because some stuff does \r instead
  71. abort unless (c == 13) || (c == 10)
  72. end
  73. class Version
  74. include Comparable
  75. attr_reader :parts
  76. def initialize(str)
  77. @parts = str.split(".").map(&:to_i)
  78. end
  79. def <=>(other)
  80. parts <=> self.class.new(other).parts
  81. end
  82. end
  83. def force_curl?
  84. ARGV.include?("--force-curl")
  85. end
  86. def macos_version
  87. @macos_version ||= Version.new(`/usr/bin/sw_vers -productVersion`.chomp[/10\.\d+/])
  88. end
  89. def should_install_command_line_tools?
  90. return false if force_curl?
  91. return false if macos_version < "10.9"
  92. developer_dir = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp
  93. developer_dir.empty? || !File.exist?("#{developer_dir}/usr/bin/git")
  94. end
  95. def git
  96. return false if force_curl?
  97. @git ||= if ENV["GIT"] && File.executable?(ENV["GIT"])
  98. ENV["GIT"]
  99. elsif Kernel.system "/usr/bin/which -s git"
  100. "git"
  101. else
  102. exe = `xcrun -find git 2>/dev/null`.chomp
  103. exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
  104. end
  105. return unless @git
  106. # Github only supports HTTPS fetches on 1.7.10 or later:
  107. # https://help.github.com/articles/https-cloning-errors
  108. `#{@git} --version` =~ /git version (\d\.\d+\.\d+)/
  109. return if $1.nil?
  110. return if Version.new($1) < "1.7.10"
  111. @git
  112. end
  113. def user_only_chmod?(d)
  114. return false unless File.directory?(d)
  115. mode = File.stat(d).mode & 0777
  116. # u = (mode >> 6) & 07
  117. # g = (mode >> 3) & 07
  118. # o = (mode >> 0) & 07
  119. mode != 0755
  120. end
  121. def chmod?(d)
  122. File.exist?(d) && !(File.readable?(d) && File.writable?(d) && File.executable?(d))
  123. end
  124. def chown?(d)
  125. !File.owned?(d)
  126. end
  127. def chgrp?(d)
  128. !File.grpowned?(d)
  129. end
  130. # Invalidate sudo timestamp before exiting (if it wasn't active before).
  131. Kernel.system "/usr/bin/sudo -n -v 2>/dev/null"
  132. at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $?.success?
  133. # The block form of Dir.chdir fails later if Dir.CWD doesn't exist which I
  134. # guess is fair enough. Also sudo prints a warning message for no good reason
  135. Dir.chdir "/usr"
  136. ####################################################################### script
  137. abort "See Linuxbrew: http://linuxbrew.sh/" if RUBY_PLATFORM.to_s.downcase.include?("linux")
  138. abort "MacOS too old, see: https://github.com/mistydemeo/tigerbrew" if macos_version < "10.6"
  139. abort "Don't run this as root!" if Process.uid.zero?
  140. abort <<-EOABORT unless `dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include? "user is a member"
  141. This script requires the user #{ENV["USER"]} to be an Administrator.
  142. EOABORT
  143. # Tests will fail if the prefix exists, but we don't have execution
  144. # permissions. Abort in this case.
  145. abort <<-EOABORT if File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX)
  146. The Homebrew prefix, #{HOMEBREW_PREFIX}, exists but is not searchable. If this is
  147. not intentional, please restore the default permissions and try running the
  148. installer again:
  149. sudo chmod 775 #{HOMEBREW_PREFIX}
  150. EOABORT
  151. ohai "This script will install:"
  152. puts "#{HOMEBREW_PREFIX}/bin/brew"
  153. puts "#{HOMEBREW_PREFIX}/share/doc/homebrew"
  154. puts "#{HOMEBREW_PREFIX}/share/man/man1/brew.1"
  155. puts "#{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
  156. puts "#{HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
  157. puts HOMEBREW_REPOSITORY.to_s
  158. group_chmods = %w[ bin bin/brew etc Frameworks include lib sbin share var
  159. etc/bash_completion.d lib/pkgconfig var/log
  160. share/aclocal share/doc share/info share/locale share/man
  161. share/man/man1 share/man/man2 share/man/man3 share/man/man4
  162. share/man/man5 share/man/man6 share/man/man7 share/man/man8].
  163. map { |d| File.join(HOMEBREW_PREFIX, d) }.
  164. select { |d| chmod?(d) }
  165. # zsh refuses to read from these directories if group writable
  166. zsh_dirs = %w[share/zsh share/zsh/site-functions].
  167. map { |d| File.join(HOMEBREW_PREFIX, d) }
  168. user_chmods = zsh_dirs.select { |d| user_only_chmod?(d) }
  169. chmods = group_chmods + user_chmods
  170. chowns = chmods.select { |d| chown?(d) }
  171. chgrps = chmods.select { |d| chgrp?(d) }
  172. mkdirs = %w[Cellar Homebrew Frameworks bin etc include lib opt sbin share share/zsh share/zsh/site-functions var].
  173. map { |d| File.join(HOMEBREW_PREFIX, d) }.
  174. reject { |d| File.directory?(d) }
  175. unless group_chmods.empty?
  176. ohai "The following existing directories will be made group writable:"
  177. puts(*group_chmods)
  178. end
  179. unless user_chmods.empty?
  180. ohai "The following existing directories will be made writable by user only:"
  181. puts(*user_chmods)
  182. end
  183. unless chowns.empty?
  184. ohai "The following existing directories will have their owner set to #{Tty.underline}#{ENV["USER"]}#{Tty.reset}:"
  185. puts(*chowns)
  186. end
  187. unless chgrps.empty?
  188. ohai "The following existing directories will have their group set to #{Tty.underline}admin#{Tty.reset}:"
  189. puts(*chgrps)
  190. end
  191. unless mkdirs.empty?
  192. ohai "The following new directories will be created:"
  193. puts(*mkdirs)
  194. end
  195. wait_for_user if STDIN.tty? && !ENV["TRAVIS"]
  196. if File.directory? HOMEBREW_PREFIX
  197. sudo "/bin/chmod", "u+rwx", *chmods unless chmods.empty?
  198. sudo "/bin/chmod", "g+rwx", *group_chmods unless group_chmods.empty?
  199. sudo "/bin/chmod", "755", *user_chmods unless user_chmods.empty?
  200. sudo "/usr/sbin/chown", ENV["USER"], *chowns unless chowns.empty?
  201. sudo "/usr/bin/chgrp", "admin", *chgrps unless chgrps.empty?
  202. else
  203. sudo "/bin/mkdir", "-p", HOMEBREW_PREFIX
  204. sudo "/usr/sbin/chown", "root:wheel", HOMEBREW_PREFIX
  205. end
  206. unless mkdirs.empty?
  207. sudo "/bin/mkdir", "-p", *mkdirs
  208. sudo "/bin/chmod", "g+rwx", *mkdirs
  209. sudo "/bin/chmod", "755", *zsh_dirs
  210. sudo "/usr/sbin/chown", ENV["USER"], *mkdirs
  211. sudo "/usr/bin/chgrp", "admin", *mkdirs
  212. end
  213. [HOMEBREW_CACHE, HOMEBREW_OLD_CACHE].each do |cache|
  214. sudo "/bin/mkdir", "-p", cache unless File.directory? cache
  215. sudo "/bin/chmod", "g+rwx", cache if chmod? cache
  216. sudo "/usr/sbin/chown", ENV["USER"], cache if chown? cache
  217. sudo "/usr/bin/chgrp", "admin", cache if chgrp? cache
  218. end
  219. if should_install_command_line_tools?
  220. ohai "Searching online for the Command Line Tools"
  221. # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
  222. clt_placeholder = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
  223. sudo "/usr/bin/touch", clt_placeholder
  224. clt_label = `softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\\*/ {print $2}' | sed 's/^ *//' | tail -n1`.chomp
  225. ohai "Installing #{clt_label}"
  226. sudo "/usr/sbin/softwareupdate", "-i", clt_label
  227. sudo "/bin/rm", "-f", clt_placeholder
  228. sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
  229. end
  230. # Headless install may have failed, so fallback to original 'xcode-select' method
  231. if should_install_command_line_tools? && STDIN.tty?
  232. ohai "Installing the Command Line Tools (expect a GUI popup):"
  233. sudo "/usr/bin/xcode-select", "--install"
  234. puts "Press any key when the installation has completed."
  235. getc
  236. sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
  237. end
  238. abort <<-EOABORT if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success?
  239. You have not agreed to the Xcode license.
  240. Before running the installer again please agree to the license by opening
  241. Xcode.app or running:
  242. sudo xcodebuild -license
  243. EOABORT
  244. ohai "Downloading and installing Homebrew..."
  245. Dir.chdir HOMEBREW_REPOSITORY do
  246. if git
  247. # we do it in four steps to avoid merge errors when reinstalling
  248. system git, "init", "-q"
  249. # "git remote add" will fail if the remote is defined in the global config
  250. system git, "config", "remote.origin.url", BREW_REPO
  251. system git, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
  252. # ensure we don't munge line endings on checkout
  253. system git, "config", "core.autocrlf", "false"
  254. args = git, "fetch", "origin", "master:refs/remotes/origin/master",
  255. "--tags", "--force"
  256. args << "--depth=1" unless ARGV.include?("--full") || !ENV["HOMEBREW_DEVELOPER"].nil?
  257. system(*args)
  258. system git, "reset", "--hard", "origin/master"
  259. system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"
  260. system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"
  261. else
  262. # -m to stop tar erroring out if it can't modify the mtime for root owned directories
  263. # pipefail to cause the exit status from curl to propagate if it fails
  264. curl_flags = "fsSL"
  265. core_tap = "#{HOMEBREW_PREFIX}/Homebrew/Library/Taps/homebrew/homebrew-core"
  266. system "/bin/bash -o pipefail -c '/usr/bin/curl -#{curl_flags} #{BREW_REPO}/tarball/master | /usr/bin/tar xz -m --strip 1'"
  267. system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"
  268. system "/bin/mkdir", "-p", core_tap
  269. Dir.chdir core_tap do
  270. system "/bin/bash -o pipefail -c '/usr/bin/curl -#{curl_flags} #{CORE_TAP_REPO}/tarball/master | /usr/bin/tar xz -m --strip 1'"
  271. end
  272. end
  273. end
  274. warn "#{HOMEBREW_PREFIX}/bin is not in your PATH." unless ENV["PATH"].split(":").include? "#{HOMEBREW_PREFIX}/bin"
  275. ohai "Installation successful!"
  276. puts
  277. # Use the shell's audible bell.
  278. print "\a"
  279. # Use an extra newline and bold to avoid this being missed.
  280. ohai "Homebrew has enabled anonymous aggregate user behaviour analytics."
  281. puts <<-EOS
  282. #{Tty.bold}Read the analytics documentation (and how to opt-out) here:
  283. #{Tty.underline}https://docs.brew.sh/Analytics.html#{Tty.reset}
  284. EOS
  285. if git
  286. Dir.chdir HOMEBREW_REPOSITORY do
  287. system git, "config", "--local", "--replace-all", "homebrew.analyticsmessage", "true"
  288. end
  289. end
  290. ohai "Next steps:"
  291. if macos_version < "10.9" && macos_version > "10.6"
  292. `/usr/bin/cc --version 2> /dev/null` =~ /clang-(\d{2,})/
  293. version = $1.to_i
  294. if version < 425
  295. puts "- Install the #{Tty.bold}Command Line Tools for Xcode:"
  296. puts " #{Tty.underline}https://developer.apple.com/downloads#{Tty.reset}"
  297. end
  298. elsif !File.exist? "/usr/bin/cc"
  299. puts "- Install #{Tty.bold}Xcode:"
  300. puts " #{Tty.underline}https://developer.apple.com/xcode#{Tty.reset}"
  301. end
  302. unless git
  303. puts "- Run `brew update --force` to complete installation by installing:"
  304. puts " #{HOMEBREW_PREFIX}/share/doc/homebrew"
  305. puts " #{HOMEBREW_PREFIX}/share/man/man1/brew.1"
  306. puts " #{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
  307. puts " #{HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
  308. puts " #{HOMEBREW_REPOSITORY}/.git"
  309. end
  310. puts "- Run `brew help` to get started"
  311. puts "- Further documentation: "
  312. puts " #{Tty.underline}https://docs.brew.sh#{Tty.reset}"

以上就是#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby的详细内容,更多关于#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby的资料请关注九品源码其它相关文章!