tuist/scripts/install

96 lines
2.0 KiB
Ruby
Executable File

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
# Inspired by: https://raw.githubusercontent.com/Homebrew/install/master/install
require 'tmpdir'
module Tty
module_function
def blue
bold 34
end
def red
bold 31
end
def reset
escape 0
end
def bold(n = 39)
escape "1;#{n}"
end
def underline
escape "4;39"
end
def escape(n)
"\033[#{n}m" if STDOUT.tty?
end
end
class Array
def shell_s
cp = dup
first = cp.shift
cp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ")
end
end
def ohai(*args)
puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
end
def warn(warning)
puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
end
def system(*args)
abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
end
def getc
system "/bin/stty raw -echo"
if STDIN.respond_to?(:getbyte)
STDIN.getbyte
else
STDIN.getc
end
ensure
system "/bin/stty -raw echo"
end
def wait_for_user
puts
puts "Press RETURN to continue or any other key to abort"
c = getc
# we test for \r and \n because some stuff does \r instead
abort unless (c == 13) || (c == 10)
end
class Version
include Comparable
attr_reader :parts
def initialize(str)
@parts = str.split(".").map { |p| p.to_i }
end
def <=>(other)
parts <=> self.class.new(other).parts
end
end
ohai "This script will install:"
puts "/Applications/xcbuddy.app"
puts "/usr/local/bin/xcbuddy"
wait_for_user
ohai "Installing"
download_url = `curl -s https://api.github.com/repos/xcbuddy/xcbuddy/releases/latest | grep browser_download_url | cut -d '"' -f 4`.chomp
tmp_dir = Dir.mktmpdir
download_path = File.join(tmp_dir, File.basename(download_url))
system("curl -L #{download_url} --output #{download_path}")
system("tar -xz -f #{download_path} -C /Applications")
system("ln -f -s /Applications/xcbuddy.app/Contents/SharedSupport/xcbuddy /usr/local/bin/xcbuddy")
ohai "Installed: Try running 'xcbuddy'"