Class: XcodeUnsigner

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

Class Method Summary collapse

Methods included from CLI

chown_if_required, codesign_exists?, dry_run?, install_launch_agent?, no_colors?, non_interactive?, restore_xcode?, separator, uninstall_launch_agent?, unsign_xcode?

Class Method Details

.noticeObject



78
79
80
81
82
83
84
85
86
# File 'lib/xcode_unsigner.rb', line 78

def self.notice
  puts [
    '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),
    "This tool will create a backup and allow you to restore Xcode's signature by running\n",
    '$ update_xcode_plugins --restore'.colorize(:light_blue)
  ]
end

.restore_xcodeObject



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

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

  separator

  if xcodes.empty?
    error "Didn't find any Xcode 8+ that can be restored on your system."
    return
  end

  selection = Ask.list "Choose which Xcode you would like to restore (use arrows)", xcodes
  return unless selection

  xcode = xcodes[selection]

  separator

  process 'Restoring...'

  success = true

  if xcode.binary_restorable? && !xcode.restore_binary!
    error "Could not restore binary for #{xcode.path}"
    success = false
  end

  if xcode.xcodebuild_restorable? && !xcode.restore_xcodebuild!
    error "Could not restore xcodebuild for #{xcode.path}"
    success = false
  end

  success 'Finished! 🎉' if success
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
# File 'lib/xcode_unsigner.rb', line 6

def self.unsign_xcode
  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 signed Xcode 8+ on your system."
    return
  end

  notice
  separator

  selection = Ask.list "Choose which Xcode you would like to unsign (use arrows)", xcodes
  return unless selection

  xcode = xcodes[selection]

  unsign_xcodebuild = Ask.confirm "Unsign xcodebuild too?"

  separator

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