From 2025720964709c3d0802231416818734d655a52d Mon Sep 17 00:00:00 2001 From: Marc O'Morain Date: Mon, 23 Sep 2019 17:05:20 +0100 Subject: [PATCH] Add CLI installer --- README.md | 2 +- lib/xcode/install.rb | 3 +- lib/xcode/install/command.rb | 3 +- lib/xcode/install/tools.rb | 62 ++++++++++++++++++++++++++++++++++++ xcode-install.gemspec | 2 +- 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 lib/xcode/install/tools.rb diff --git a/README.md b/README.md index bb51d4cb..3456cd96 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ to a dialog popping up. Feel free to dupe [the radar][5]. 📡 XcodeInstall normally relies on the Spotlight index to locate installed versions of Xcode. If you use it while indexing is happening, it might show inaccurate results and it will not be able to see installed -versions on unindexed volumes. +versions on unindexed volumes. To workaround the Spotlight limitation, XcodeInstall searches `/Applications` folder to locate Xcodes when Spotlight is disabled on the machine, or when Spotlight query for Xcode does not return any results. But it still won't work if your Xcodes are not located under `/Applications` folder. diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index fdba464c..b7210d52 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -31,7 +31,6 @@ def fetch(url: nil, progress: nil, progress_block: nil) options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH] - uri = URI.parse(url) output ||= File.basename(uri.path) output = (Pathname.new(directory) + Pathname.new(output)) if directory @@ -329,7 +328,7 @@ def mount(dmg_path) node.text end - private + #private def spaceship @spaceship ||= begin diff --git a/lib/xcode/install/command.rb b/lib/xcode/install/command.rb index 0a2431f8..4d3e9935 100644 --- a/lib/xcode/install/command.rb +++ b/lib/xcode/install/command.rb @@ -20,9 +20,10 @@ class Command < CLAide::Command require 'xcode/install/list' require 'xcode/install/select' require 'xcode/install/selected' + require 'xcode/install/simulators' + require 'xcode/install/tools.rb' require 'xcode/install/uninstall' require 'xcode/install/update' - require 'xcode/install/simulators' self.abstract_command = true self.command = 'xcversion' diff --git a/lib/xcode/install/tools.rb b/lib/xcode/install/tools.rb new file mode 100644 index 00000000..1932a26f --- /dev/null +++ b/lib/xcode/install/tools.rb @@ -0,0 +1,62 @@ +require 'claide' +require 'spaceship' + +module XcodeInstall + class Command + class Tools < Command + self.command = 'tools' + self.summary = 'List or install Xcode CLI tools.' + + def self.options + [['--install=name', 'Install simulator beginning with name, e.g. \'iOS 8.4\', \'tvOS 9.0\'.'], + ['--force', 'Install even if the same version is already installed.'], + ['--no-install', 'Only download DMG, but do not install it.'], + ['--no-progress', 'Don’t show download progress.']].concat(super) + end + + def initialize(argv) + @install = argv.option('install') + @force = argv.flag?('force', false) + @should_install = argv.flag?('install', true) + @progress = argv.flag?('progress', true) + @installer = XcodeInstall::Installer.new + super + end + + def run + @install ? install : list + end + + :private + + def download(package) + puts("Downloading #{package}") + url = 'https://developer.apple.com/devcenter/download.action?path=' + package + dmg_file = File.basename(url) + Curl.new.fetch( + url: url, + directory: XcodeInstall::CACHE_DIR, + cookies: @installer.spaceship.cookie, + output: dmg_file, + progress: false + ) + XcodeInstall::CACHE_DIR + dmg_file + end + + def install + dmg_path = download(@install) + puts("Downloaded to from #{dmg_path}") + mount_dir = @installer.mount(dmg_path) + puts("Mounted to #{mount_dir}") + pkg_path = Dir.glob(File.join(mount_dir, '*.pkg')).first + puts("Installing from #{pkg_path}") + prompt = "Please authenticate to install Command Line Tools.\nPassword: " + `sudo -p "#{prompt}" installer -verbose -pkg "#{pkg_path}" -target /` + end + + def list + raise NotImplementedError, 'Listing is not implemented' + end + end + end +end diff --git a/xcode-install.gemspec b/xcode-install.gemspec index fc5ad71e..bc713a2a 100644 --- a/xcode-install.gemspec +++ b/xcode-install.gemspec @@ -27,6 +27,6 @@ Gem::Specification.new do |spec| # contains spaceship, which is used for auth and dev portal interactions spec.add_dependency 'fastlane', '>= 2.1.0', '< 3.0.0' - spec.add_development_dependency 'bundler', '~> 1.7' + spec.add_development_dependency 'bundler', '~> 2.0.2' spec.add_development_dependency 'rake', '~> 10.0' end