update_xcode_plugins 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f023d4bc2dd0a3f9de58bff30ae2ffb2c88fee4
4
- data.tar.gz: 303a5d87913f76c38f6027e03733c56183bc52d1
3
+ metadata.gz: f4c8f15764baf5b6abcc5987933aff96e9ac3b44
4
+ data.tar.gz: 08f4b1549988bc40de7b63c31cb3f7d9bc4fdae2
5
5
  SHA512:
6
- metadata.gz: f0ab4d2af6afe7f89b7d730ae57a99135996561189ea96d7af3304c37668737db6b8b6b88a63d39f798b58934bd88d187cb58964e2c69d0f085ecea4372fddfa
7
- data.tar.gz: fef9eaa666d9dd60c8bb5b9b4104f4c158ab4a7913157cb13dbc2bd77f0954c0ccefd6bf3f5e133dec56c2220b37d37ff73e97c31d570ad17dbdbd9e3725c687
6
+ metadata.gz: 24e196c7d18665d7603e0ba64a3282a83c1e37ed7c0ac78c8612097e666775262977d6656ed05220b334cfb52574cec1ef4da3a86cd4db9c1ea11aa434ca1935
7
+ data.tar.gz: d8da91bc440b22980b5d4ff19c3325128dd2740a661adb1c13b3630b411dc42427fb4b5b46bd828ba56e34155889db18df65aba3368153bf05f075fbdfd14f50
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016
3
+ Copyright (c) Mahdi Bchetnia 2016
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,58 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
23
+
24
+ ---------------------------------------------------------
25
+
26
+ ---------------------------------------------------------
27
+ unsign binary copyright notices
28
+ ---------------------------------------------------------
29
+
30
+ ---
31
+ unsign.c (ISC License)
32
+ Retrieved from https://github.com/steakknife/unsign
33
+ ---
34
+
35
+ Copyright (c) 2010
36
+ Permission to use, copy, modify, and/or distribute this software for any
37
+ purpose with or without fee is hereby granted, provided that the above
38
+ copyright notice and this permission notice appear in all copies.
39
+ The software is provided "as is" and the author disclaims all warranties
40
+ with regard to this software including all implied warranties of
41
+ merchantability and fitness. In no event shall the author be liable for
42
+ any special, direct, indirect, or consequential damages or any damages
43
+ whatsoever resulting from loss of use, data or profits, whether in an
44
+ action of contract, negligence or other tortious action, arising out of
45
+ or in connection with the use or performance of this software.
46
+
47
+
48
+ ---
49
+ endian.c
50
+ ---
51
+
52
+ Copyright (c) 2002 Thomas Moestl <tmm@FreeBSD.org>
53
+ All rights reserved.
54
+
55
+ Redistribution and use in source and binary forms, with or without
56
+ modification, are permitted provided that the following conditions
57
+ are met:
58
+ 1. Redistributions of source code must retain the above copyright
59
+ notice, this list of conditions and the following disclaimer.
60
+ 2. Redistributions in binary form must reproduce the above copyright
61
+ notice, this list of conditions and the following disclaimer in the
62
+ documentation and/or other materials provided with the distribution.
63
+
64
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
65
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
68
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74
+ SUCH DAMAGE.
75
+
76
+ $FreeBSD$
data/README.md CHANGED
@@ -4,6 +4,8 @@ This tool adds the missing UUIDs into the installed Xcode plug-ins so that they
4
4
 
5
5
  You can choose to run it once or install a **launch agent** that will trigger the tool every time any of your installed plugins are modified or Xcode/Xcode-beta gets updated.
6
6
 
7
+ This tool also allows you to unsign Xcode in order to run plugins on Xcode 8 and later. For more information on why this is needed, see [alcatraz/Alcatraz#475](https://github.com/alcatraz/Alcatraz/issues/475).
8
+
7
9
  #### Install
8
10
 
9
11
  ```shell
@@ -20,19 +22,25 @@ In Terminal:
20
22
  $ update_xcode_plugins
21
23
  ```
22
24
 
23
- ![](http://i.imgur.com/XQZHSND.png)
25
+ ![](http://i.imgur.com/0aw1bW4.png)
26
+
27
+ To use plugins on Xcode 8 and later, unsign Xcode with:
28
+
29
+ ```shell
30
+ $ update_xcode_plugins --unsign
31
+ ```
32
+
33
+ ![](http://i.imgur.com/3044DnB.png)
24
34
 
25
35
  ##### Other options
26
36
 
27
- For a dry run,
37
+ For a dry run to see which plugins will be updated,
28
38
 
29
39
  ```shell
30
40
  $ update_xcode_plugins --dry-run
31
41
  ```
32
42
 
33
- ![](http://i.imgur.com/SPdbt2V.png)
34
-
35
- To install the launch agent,
43
+ To install the launch agent for automatically updating plugins,
36
44
 
37
45
  ```shell
38
46
  $ update_xcode_plugins --install-launch-agent
@@ -46,4 +54,4 @@ $ update_xcode_plugins --uninstall-launch-agent
46
54
 
47
55
  #### Contact
48
56
 
49
- [@inket](https://github.com/inket) / [@inket](https://twitter.com/inket) on Twitter / [mahdi.jp](https://mahdi.jp)
57
+ [@inket](https://github.com/inket) / [@inket](https://twitter.com/inket) on Twitter / [mahdi.jp](https://mahdi.jp)
@@ -4,8 +4,14 @@ require_relative '../lib/update_xcode_plugins'
4
4
 
5
5
  if CLI.uninstall_launch_agent?
6
6
  LaunchAgent.uninstall
7
- elsif CLI.install_launch_agent?
8
- LaunchAgent.install(__FILE__)
9
7
  else
10
- PluginsUpdater.update_plugins
8
+ LaunchAgent.update_if_stale(__FILE__)
9
+
10
+ if CLI.install_launch_agent?
11
+ LaunchAgent.install(__FILE__)
12
+ elsif CLI.unsign_xcode?
13
+ XcodeUnsigner.unsign_xcode
14
+ else
15
+ PluginsUpdater.update_plugins
16
+ end
11
17
  end
data/lib/bin/unsign ADDED
Binary file
data/lib/cli.rb CHANGED
@@ -1,4 +1,4 @@
1
- class CLI
1
+ module CLI
2
2
  def self.dry_run?
3
3
  ARGV.include?('-d') || ARGV.include?('--dry-run')
4
4
  end
@@ -10,4 +10,26 @@ class CLI
10
10
  def self.uninstall_launch_agent?
11
11
  ARGV.include?('--uninstall-launch-agent')
12
12
  end
13
+
14
+ def self.unsign_xcode?
15
+ ARGV.include?('--unsign')
16
+ end
17
+
18
+ def self.codesign_exists?
19
+ `which codesign` && $CHILD_STATUS.exitstatus == 0
20
+ end
21
+
22
+ {
23
+ title: :blue,
24
+ process: :magenta,
25
+ warning: :yellow,
26
+ error: :red,
27
+ success: :green
28
+ }.each do |type, color|
29
+ define_method type.to_sym do |str| puts str.colorize(color) end
30
+ end
31
+
32
+ def separator
33
+ puts
34
+ end
13
35
  end
data/lib/launch_agent.rb CHANGED
@@ -1,14 +1,57 @@
1
1
  class LaunchAgent
2
+ extend CLI
3
+
2
4
  attr_accessor :bin_path
3
5
 
4
6
  def self.install(bin_path)
5
- LaunchAgent.new(bin_path).install
6
- puts 'Done.'
7
+ if !installed?
8
+ LaunchAgent.new(File.expand_path(bin_path)).install
9
+ success 'Installed! 🎉'
10
+ else
11
+ warning 'Launch agent is already installed!'
12
+ end
7
13
  end
8
14
 
9
15
  def self.uninstall
10
- LaunchAgent.new.uninstall
11
- puts 'Done.'
16
+ if installed?
17
+ LaunchAgent.new.uninstall
18
+ success 'Uninstalled! 🎉'
19
+ else
20
+ warning 'Launch agent is not installed!'
21
+ end
22
+ end
23
+
24
+ def self.update_if_stale(bin_path)
25
+ return unless stale?
26
+
27
+ launch_agent = LaunchAgent.new(File.expand_path(bin_path))
28
+ launch_agent.uninstall
29
+ launch_agent.install
30
+ success 'Updated launch agent.'
31
+ end
32
+
33
+ def self.stale?
34
+ if installed?
35
+ path = LaunchAgent.new.launch_agent_path
36
+
37
+ agent_xml = ''
38
+ File.open(path, 'r') do |file|
39
+ agent_xml = file.read
40
+ end
41
+
42
+ match = agent_xml.match(/update_xcode_plugins-(.*?)\//)
43
+ installed_version = match ? match[1] : nil
44
+
45
+ if installed_version && UpdateXcodePlugins::VERSION != installed_version
46
+ return true
47
+ end
48
+ end
49
+
50
+ false
51
+ end
52
+
53
+ def self.installed?
54
+ File.exist?(LaunchAgent.new.launch_agent_path)
12
55
  end
13
56
 
14
57
  def initialize(bin_path = nil)
@@ -2,46 +2,54 @@ require_relative 'xcode'
2
2
  require_relative 'xcode_plugin'
3
3
 
4
4
  class PluginsUpdater
5
+ extend CLI
6
+
5
7
  def self.update_plugins
6
8
  xcodes = Xcode.find_xcodes
7
9
 
8
10
  if xcodes.empty?
9
- puts "Didn't find any Xcode installed on your system."
11
+ error "Didn't find any Xcode installed on your system."
10
12
  return
11
13
  else
12
- puts 'Found:'
13
- puts xcodes
14
+ title 'Found:'
15
+ puts xcodes.map { |s| "- #{s}" }
14
16
  end
15
17
 
16
- puts separator
18
+ separator
17
19
 
18
20
  plugins = XcodePlugin.find_plugins
19
21
 
20
22
  if plugins.empty?
21
- puts "Didn't find any Xcode Plug-in installed on your system."
23
+ error "Didn't find any Xcode Plug-in installed on your system."
22
24
  return
23
25
  else
24
- puts 'Plugins:'
25
- puts plugins
26
+ title 'Plugins:'
27
+ puts plugins.map { |s| "- #{s}" }
26
28
  end
27
29
 
28
- puts separator
29
- puts 'Updating...'
30
+ separator
31
+ process 'Updating...'
30
32
 
31
33
  uuids = xcodes.collect(&:uuid)
32
34
  uuids.each do |uuid|
33
35
  plugins.each do |plugin|
34
36
  if plugin.add_uuid(uuid) && !CLI.dry_run?
35
- puts "Added #{uuid} to #{plugin}"
37
+ success "Added #{uuid} to #{plugin}"
36
38
  end
37
39
  end
38
40
  end
39
41
 
40
- puts separator
41
- puts 'Done.'
42
- end
42
+ separator
43
+ success 'Finished! 🎉'
43
44
 
44
- def self.separator
45
- '-----------------------------------------------'
45
+ if xcodes.any? { |xcode| xcode.version.to_f >= 8 }
46
+ separator
47
+ warning 'It seems that you have Xcode 8+ installed!'
48
+ puts 'Some plugins might not work on recent versions of Xcode because of library validation.',
49
+ "See #{'https://github.com/alcatraz/Alcatraz/issues/475'.underline}"
50
+
51
+ separator
52
+ puts "Run `#{'update_xcode_plugins --unsign'.bold}` to fix this."
53
+ end
46
54
  end
47
55
  end
@@ -1,2 +1,8 @@
1
+ require 'English'
2
+ require 'fileutils'
3
+ require 'colorize'
4
+ require 'inquirer'
5
+ require_relative 'version'
1
6
  require_relative 'plugins_updater'
7
+ require_relative 'xcode_unsigner'
2
8
  require_relative 'launch_agent'
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class UpdateXcodePlugins
2
- VERSION = '0.1'
2
+ VERSION = '0.2'.freeze
3
3
  end
data/lib/xcode.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require_relative 'bundle'
2
2
 
3
3
  class Xcode < Bundle
4
+ attr_accessor :signed
5
+
4
6
  def self.find_xcodes
5
7
  output = `mdfind kMDItemCFBundleIdentifier = "com.apple.dt.Xcode"`
6
8
  output.lines.collect do |xcode_path|
@@ -20,11 +22,47 @@ class Xcode < Bundle
20
22
  is_app && has_info
21
23
  end
22
24
 
25
+ def signed?
26
+ if signed.nil?
27
+ self.signed = `codesign -dv "#{path}" 2>/dev/null` &&
28
+ $CHILD_STATUS.exitstatus == 0
29
+ end
30
+
31
+ signed
32
+ end
33
+
34
+ def unsign!
35
+ `#{unsign_path} "#{binary_path}"` &&
36
+ $CHILD_STATUS.exitstatus == 0 &&
37
+ File.exist?(unsigned_binary_path) &&
38
+ FileUtils.mv(unsigned_binary_path, binary_path)
39
+ end
40
+
23
41
  def uuid
24
42
  defaults_read('DVTPlugInCompatibilityUUID')
25
43
  end
26
44
 
27
45
  def to_s
28
- "Xcode (#{version}) [#{uuid}]: #{path}"
46
+ unless signed.nil?
47
+ codesign_status = signed ? '[Signed]' : '[Unsigned]'
48
+ end
49
+
50
+ "Xcode (#{version}) [#{uuid}]#{codesign_status}: #{path}"
51
+ end
52
+
53
+ private
54
+
55
+ def binary_path
56
+ "#{path}/Contents/MacOS/Xcode"
57
+ end
58
+
59
+ def unsigned_binary_path
60
+ "#{binary_path}.unsigned"
61
+ end
62
+
63
+ def unsign_path
64
+ lib_path = File.expand_path(File.dirname(__FILE__))
65
+
66
+ "#{lib_path}/bin/unsign"
29
67
  end
30
68
  end
@@ -0,0 +1,69 @@
1
+ require_relative 'xcode'
2
+
3
+ class XcodeUnsigner
4
+ extend CLI
5
+
6
+ def self.unsign_xcode
7
+ unless CLI.codesign_exists?
8
+ # Not sure if codesign comes pre-installed on fresh macOS, so we'll check
9
+ # Send a pull request if you think it does :)
10
+ error 'The `codesign` tool could not be found on your system'
11
+ return
12
+ end
13
+
14
+ process 'Looking for Xcode...'
15
+ xcodes = Xcode.find_xcodes
16
+ .select { |xcode| xcode.version.to_f >= 8 }
17
+ .select(&:signed?)
18
+
19
+ separator
20
+
21
+ if xcodes.empty?
22
+ error "Didn't find any Xcode 8+ installed on your system."
23
+ return
24
+ else
25
+ puts notice
26
+ end
27
+
28
+ separator
29
+
30
+ selection = Ask.list 'Choose which Xcode.app you would like to copy and unsign (use arrows)',
31
+ ['Cancel', xcodes].flatten
32
+ return unless selection && selection != 0
33
+
34
+ xcode = xcodes[selection - 1]
35
+
36
+ new_xcode_path = '/Applications/Xcode-unsigned.app'
37
+ if Dir.exist?(new_xcode_path)
38
+ error 'Xcode-unsigned.app already exists.'
39
+ return
40
+ end
41
+
42
+ process 'Copying Xcode... (this might take a while)'
43
+ FileUtils.cp_r(xcode.path, new_xcode_path)
44
+
45
+ process 'Unsigning...'
46
+ new_xcode = Xcode.new(new_xcode_path)
47
+ if new_xcode.unsign!
48
+ success 'Finished! 🎉'
49
+ else
50
+ error "Could not unsign Xcode-unsigned.app\n"\
51
+ 'Create an issue on https://github.com/inket/update_xcode_plugins/issues'
52
+ end
53
+ end
54
+
55
+ def self.notice
56
+ [
57
+ 'Unsigning Xcode will make it skip library validation allowing it to load plugins.'.colorize(:yellow),
58
+ '',
59
+ 'However, an unsigned Xcode presents security risks, '\
60
+ 'and will be untrusted by both Apple and your system.'.colorize(:red),
61
+ 'Please make sure that you have launched this version of Xcode at least '\
62
+ 'once before unsigning.'.colorize(:red),
63
+ '',
64
+ 'We recommend keeping a signed version of Xcode, so this tool will:',
65
+ '- Create a copy of Xcode.app called Xcode-unsigned.app (consider the disk space requirements)',
66
+ '- Unsign Xcode-unsigned.app'
67
+ ]
68
+ end
69
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: update_xcode_plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mahdi Bchetnia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: inquirer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.1
13
41
  description: This tool adds the missing UUIDs into the installed Xcode plug-ins so
14
42
  that they can be loaded by newer versions of Xcode.
15
43
  email:
@@ -22,6 +50,7 @@ files:
22
50
  - LICENSE
23
51
  - README.md
24
52
  - bin/update_xcode_plugins
53
+ - lib/bin/unsign
25
54
  - lib/bundle.rb
26
55
  - lib/cli.rb
27
56
  - lib/launch_agent.rb
@@ -30,6 +59,7 @@ files:
30
59
  - lib/version.rb
31
60
  - lib/xcode.rb
32
61
  - lib/xcode_plugin.rb
62
+ - lib/xcode_unsigner.rb
33
63
  homepage: http://github.com/inket/update_xcode_plugins
34
64
  licenses:
35
65
  - MIT
@@ -50,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
80
  version: 1.3.6
51
81
  requirements: []
52
82
  rubyforge_project: update_xcode_plugins
53
- rubygems_version: 2.4.8
83
+ rubygems_version: 2.5.1
54
84
  signing_key:
55
85
  specification_version: 4
56
86
  summary: Updates Xcode plug-ins to match the installed Xcode versions.