-
Notifications
You must be signed in to change notification settings - Fork 7
/
briar_ideviceinstaller.rb
101 lines (82 loc) · 2.76 KB
/
briar_ideviceinstaller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require_relative './briar_dot_xamarin'
require_relative './briar_rm'
require_relative './briar_env'
require 'rainbow'
require 'ansi/logger'
require 'retriable'
@log = ANSI::Logger.new(STDOUT)
module Briar
module IDEVICEINSTALLER
require "run_loop"
def ideviceinstaller(device, cmd, opts={})
default_opts = {:build_script => ENV['IPA_BUILD_SCRIPT'],
:ipa => ENV['IPA'],
:bundle_id => expect_bundle_id(),
:idevice_installer => expect_ideviceinstaller()}
merged = default_opts.merge(opts)
cmds = [:install, :uninstall, :reinstall]
unless cmds.include? cmd
raise "illegal option '#{cmd}' must be one of '#{cmds}'"
end
build_script = merged[:build_script]
expect_build_script(build_script) if build_script
udid = read_device_info(device, :udid)
bin_path = merged[:idevice_installer]
bundle_id = merged[:bundle_id]
case cmd
when :install
if build_script
system "#{build_script}"
end
ipa = File.expand_path(merged[:ipa])
expect_ipa(ipa)
Retriable.retriable do
uninstall udid, bundle_id, bin_path
end
Retriable.retriable do
install udid, ipa, bundle_id, bin_path
end
when :uninstall
Retriable.retriable do
uninstall udid, bundle_id, bin_path
end
when :reinstall
RunLoop.deprecated('1.1.0', ':reinstall arg has been deprecated; use :install instead', :warn)
ideviceinstaller device, :install
end
end
def bundle_installed?(udid, bundle_id, installer)
cmd = "#{installer} -u #{udid} -l"
info = "EXEC: #{cmd}"
puts "#{Rainbow(info).cyan}"
`#{cmd}`.strip.split(/\s/).include? bundle_id
end
def install(udid, ipa, bundle_id, installer)
if bundle_installed? udid, bundle_id, installer
puts "#{Rainbow("bundle '#{bundle_id}' is already installed").green}"
return true
end
cmd = "#{installer} -u #{udid} --install #{ipa}"
info = "EXEC: #{cmd}"
puts "#{Rainbow(info).cyan}"
system cmd
unless bundle_installed?(udid, bundle_id, installer)
raise "could not install '#{ipa}' on '#{udid}' with '#{bundle_id}'"
end
true
end
def uninstall(udid, bundle_id, installer)
unless bundle_installed? udid, bundle_id, installer
return true
end
cmd = "#{installer} -u #{udid} --uninstall #{bundle_id}"
info = "EXEC: #{cmd}"
puts "#{Rainbow(info).cyan}"
system cmd
if bundle_installed?(udid, bundle_id, installer)
raise "could not uninstall '#{bundle_id}' on '#{udid}'"
end
true
end
end
end