Class: XcodeUnsigner

Inherits:
Object
  • Object
show all
Extended by:
CLI
Defined in:
lib/xcode_unsigner.rb

Class Method Summary collapse

Methods included from CLI

codesign_exists?, dry_run?, install_launch_agent?, no_colors?, non_interactive?, separator, uninstall_launch_agent?, unsafe_unsign_xcode?, unsign_xcode?

Class Method Details

.copy_noticeObject



73
74
75
76
77
78
79
# File 'lib/xcode_unsigner.rb', line 73

def self.copy_notice
  [
    'We recommend keeping a signed version of Xcode, so this tool will:',
    '- Create a copy of Xcode.app called Xcode-unsigned.app (consider the disk space requirements)',
    '- Unsign Xcode-unsigned.app'
  ]
end

.noticeObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/xcode_unsigner.rb', line 62

def self.notice
  [
    'Unsigning Xcode will make it skip library validation allowing it to load plugins.'.colorize(:yellow),
    '',
    'However, an unsigned Xcode presents security risks, '\
    'and will be untrusted by both Apple and your system.'.colorize(:red),
    'Please make sure that you have launched this version of Xcode at least '\
    'once before unsigning.'.colorize(:red)
  ]
end

.promptObject



81
82
83
84
85
# File 'lib/xcode_unsigner.rb', line 81

def self.prompt
  "Choose which Xcode.app you would like to "\
  "#{CLI.unsafe_unsign_xcode? ? '' : 'copy and '}"\
  "unsign (use arrows)"
end

.unsign_xcodeObject



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
# File 'lib/xcode_unsigner.rb', line 6

def self.unsign_xcode
  unless CLI.codesign_exists?
    # Not sure if codesign comes pre-installed on fresh macOS, so we'll check
    # Send a pull request if you think it does :)
    error 'The `codesign` tool could not be found on your system'
    return
  end

  process 'Looking for Xcode...'
  xcodes = Xcode.find_xcodes
                .select { |xcode| xcode.version.to_f >= 8 }
                .select(&:signed?)

  separator

  if xcodes.empty?
    error "Didn't find any Xcode 8+ installed on your system."
    return
  else
    puts notice
    puts copy_notice unless CLI.unsafe_unsign_xcode?
  end

  separator

  selection = Ask.list prompt, ['Cancel', xcodes].flatten
  return unless selection && selection != 0

  xcode = xcodes[selection - 1]

  unsign_xcodebuild = Ask.confirm "Unsign xcodebuild too?"

  if CLI.unsafe_unsign_xcode?
    new_xcode = xcode
  else
    new_xcode_path = '/Applications/Xcode-unsigned.app'
    if Dir.exist?(new_xcode_path)
      error 'Xcode-unsigned.app already exists.'
      return
    end

    process 'Copying Xcode... (this might take a while)'
    FileUtils.cp_r(xcode.path, new_xcode_path)
    new_xcode = Xcode.new(new_xcode_path)
  end

  process 'Unsigning...'
  if new_xcode.unsign_binary! &&
     (!unsign_xcodebuild || (unsign_xcodebuild && new_xcode.unsign_xcodebuild!))
    success 'Finished! 🎉'
  else
    error "Could not unsign #{File.basename(new_xcode.path)}\n"\
          'Create an issue on https://github.com/inket/update_xcode_plugins/issues'
  end
end