dev_osx_updater 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a98d0161a7791f0018f5361406bd774c95179081
4
+ data.tar.gz: 2885ee8e8ad42703f382148a2e7efcdebd0f43ab
5
+ SHA512:
6
+ metadata.gz: f32cc61e0d4c93a48a69e697cbfdd26857b89cc79f13b9ba3d9127659c685861abe317aa8c8892f95f6d5c255209a77f73a2a30375a2684b804ffef55d3e8b28
7
+ data.tar.gz: ee02c2ad62bf24363b2af22172c26b6c8b2b48f143d8bc35169b7e1d7b923629ae28415fac2a729b11ff6c258d4d8b97ef8c0d70cafbb1250b79aa7caa083ac7
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # DevOsxUpdater
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dev_osx_updater`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dev_osx_updater'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dev_osx_updater
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/dev_osx_updater/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ os = Gem::Platform.local
4
+
5
+ if os.to_s =~ /[darwin]/i
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'system')
7
+ System::Update.new.perform
8
+ else
9
+ puts 'This program currently requires Mac OSX to run. In a future release we hope to make it Linux compatible.'.colorize(:red).bold
10
+ end
data/lib/brew.rb ADDED
@@ -0,0 +1,35 @@
1
+ class Brew
2
+ class << self
3
+ def installed?
4
+ File.exist?('/usr/local/bin/brew')
5
+ end
6
+
7
+ def cleanup
8
+ puts 'Cleanup of Homebrew packages'.colorize(:light_white).bold
9
+ if run?
10
+ Open3.popen3('brew cleanup') do |stdin, stdout|
11
+ output = stdout.read
12
+ if output.empty?
13
+ puts ' - Homebrew packages already clean.'.colorize(:green)
14
+ else
15
+ puts ' - Cleaned Homebrew packages.'.colorize(:green)
16
+ end
17
+ end
18
+ else
19
+ puts ' - Skipped.'.colorize(:red)
20
+ end
21
+ break_output
22
+ end
23
+
24
+ def update
25
+ check_update_message('Homebrew')
26
+ if %x(brew update | grep Already)
27
+ puts ' - Homebrew packages already up to date.'.colorize(:green)
28
+ else
29
+ puts ' - Updating Homebrew packages...'.colorize(:green)
30
+ system 'brew update'
31
+ end
32
+ break_output
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module DevOsxUpdater
2
+ VERSION = '0.0.1'
3
+ end
data/lib/osx.rb ADDED
@@ -0,0 +1,72 @@
1
+ class OSX
2
+ using StringExtensions
3
+
4
+ class << self
5
+ def intro
6
+ puts <<-EOS.undent.colorize(:light_white)
7
+ ##################
8
+ # Mac OSX checks #
9
+ ##################
10
+ EOS
11
+ break_output
12
+ end
13
+
14
+ def system_info
15
+ cpu = %x(sysctl -n machdep.cpu.brand_string).delete!("\n")
16
+ osx = %x(sw_vers | awk -F':\t' '{print $2}' | paste -d ' ' - - -).delete!("\n")
17
+ hostname = %x(scutil --get ComputerName).delete!("\n")
18
+ ram = %x(sysctl -n hw.memsize | awk '{print $0/1073741824" GB"}').delete!("\n")
19
+ ruby = %x(ruby -e 'puts RUBY_DESCRIPTION').delete!("\n")
20
+
21
+ break_output
22
+
23
+ puts <<-EOS.undent.colorize(:light_white).bold
24
+ System information:
25
+ - CPU: #{cpu}
26
+ - OSX: #{osx}
27
+ - Host: #{hostname}
28
+ - RAM: #{ram}
29
+ - Ruby: #{ruby}
30
+ EOS
31
+
32
+ break_output
33
+ end
34
+
35
+ def check_mac_store_updates
36
+ check_update_message('Mac App Store')
37
+ if run?
38
+ Open3.popen3('softwareupdate -l') do |stdin, stdout, stderr|
39
+ output = stdout.read
40
+ error = stderr.read
41
+ updates = output.split(/\r\n|\r|\n/, 5).last
42
+ if output.include?('Software Update found')
43
+ puts updates
44
+ # %x(softwareupdate -i -a) - Commented out as we dont want to auto update yet.
45
+ end
46
+ puts ' - No new software updates available.' if error.include?('No new software available')
47
+ end
48
+ else
49
+ puts ' - Skipped.'.colorize(:red)
50
+ end
51
+ break_output
52
+ end
53
+
54
+ def repair_disk_permissions
55
+ puts '# Repairing OSX disk permissions'
56
+ if run?
57
+ Open3.popen2e('diskutil repairPermissions /') do |stdin, stdout_err, wait_thr|
58
+ while line = stdout_err.gets
59
+ puts line.delete!("\n").indent(4).colorize(:green)
60
+ end
61
+
62
+ exit_status = wait_thr.value
63
+ unless exit_status.success?
64
+ abort "FAILED !!! #{cmd}"
65
+ end
66
+ end
67
+ else
68
+ puts ' - Skipped.'.colorize(:red)
69
+ end
70
+ end
71
+ end
72
+ end
data/lib/rbenv.rb ADDED
@@ -0,0 +1,15 @@
1
+ class Rbenv
2
+ class << self
3
+ def installed?
4
+ File.exist? File.expand_path('~/.rbenv')
5
+ end
6
+
7
+ def update
8
+ check_update_message('rbenv')
9
+ Open3.popen3('cd ~/.rbenv && git pull && cd plugins/ruby-build/ && git pull') do |stdin, stdout, stderr, thread|
10
+ puts ' - rbenv updated.'.colorize(:green)
11
+ end
12
+ break_output
13
+ end
14
+ end
15
+ end
data/lib/ruby.rb ADDED
@@ -0,0 +1,41 @@
1
+ class Ruby
2
+ class << self
3
+ def check_rubygems_version
4
+ check_update_message('Rubygems')
5
+ get_gem_json('rubygems-update')
6
+
7
+ current = %x(gem -v).delete!("\n")
8
+ latest = @response['version']
9
+
10
+ if Gem::Version.new(current) < Gem::Version.new(latest)
11
+ system 'gem update --system'
12
+ else
13
+ puts " - You currently have Rubygems #{current} installed which is the latest version.".colorize(:green)
14
+ end
15
+
16
+ break_output
17
+ end
18
+
19
+ def check_bundler_version
20
+ check_update_message('Bundler')
21
+ get_gem_json('bundler')
22
+
23
+ current = %x(bundler -v).delete!("Bundler version\n")
24
+ latest = @response['version']
25
+
26
+ if current == nil || Gem::Version.new(current) < Gem::Version.new(latest)
27
+ system 'gem install bundler'
28
+ else
29
+ puts " - You currently have Bundler #{current} installed which is the latest version.".colorize(:green)
30
+ end
31
+
32
+ break_output
33
+ end
34
+
35
+ def get_gem_json(name)
36
+ uri = URI("https://rubygems.org/api/v1/gems/#{name}.json")
37
+ @response = Net::HTTP.get(uri)
38
+ @response = JSON.parse(@response)
39
+ end
40
+ end
41
+ end
data/lib/rvm.rb ADDED
@@ -0,0 +1,35 @@
1
+ class RVM
2
+ class << self
3
+ def installed?
4
+ File.exist? File.expand_path('~/.rvm')
5
+ end
6
+
7
+ def update
8
+ check_update_message('RVM')
9
+ Open3.popen3('rvm get stable') do |stdin, stdout|
10
+ output = stdout.read
11
+ puts ' - RVM updated.'.colorize(:green) if output.include?('RVM reloaded')
12
+ end
13
+ break_output
14
+ end
15
+
16
+ def cleanup
17
+ puts 'Cleanup of RVM data'.colorize(:light_white).bold
18
+ if run?
19
+ begin
20
+ PTY.spawn('rvm cleanup all') do |stdin, stdout, stderr, thread|
21
+ begin
22
+ stdin.each { |line| print line.indent(2) }
23
+ rescue Errno::EIO
24
+ end
25
+ end
26
+ rescue PTY::ChildExited
27
+ puts 'The child process exited!'
28
+ end
29
+ else
30
+ puts ' - Skipped.'.colorize(:red)
31
+ end
32
+ break_output
33
+ end
34
+ end
35
+ end
data/lib/system.rb ADDED
@@ -0,0 +1,47 @@
1
+ $LOAD_PATH << File.expand_path('..', __FILE__)
2
+ # require_relative 'lib'
3
+
4
+ # Gems
5
+ require 'colorize'
6
+ require 'open3'
7
+ require 'pty'
8
+ require 'json'
9
+ require 'net/http'
10
+
11
+ # Local files
12
+ require 'utility'
13
+ require 'rvm'
14
+ require 'brew'
15
+ require 'ruby'
16
+ require 'osx'
17
+ require 'zsh'
18
+ require 'rbenv'
19
+
20
+ module System
21
+ class Update
22
+ AUTO_RUN = ARGV[0]
23
+
24
+ def perform
25
+ OSX.system_info
26
+ Ruby.check_rubygems_version
27
+ Ruby.check_bundler_version
28
+
29
+ ZSH.update if ZSH.installed?
30
+ Rbenv.update if Rbenv.installed?
31
+
32
+ if Brew.installed?
33
+ Brew.update
34
+ Brew.cleanup
35
+ end
36
+
37
+ if RVM.installed?
38
+ RVM.update
39
+ RVM.cleanup
40
+ end
41
+
42
+ OSX.intro
43
+ OSX.check_mac_store_updates
44
+ OSX.repair_disk_permissions
45
+ end
46
+ end
47
+ end
data/lib/utility.rb ADDED
@@ -0,0 +1,62 @@
1
+ module StringExtensions
2
+ refine String do
3
+ def undent
4
+ gsub(/^.{#{(slice(/^ +/) || '').length}}/, '')
5
+ end
6
+
7
+ alias_method :undent_________________________________________________________72, :undent
8
+ end
9
+ end
10
+
11
+ String.class_eval do
12
+ def indent(count, char = ' ')
13
+ gsub(/([^\n]*)(\n|$)/) do |match|
14
+ last_iteration = ($1 == '' && $2 == '')
15
+ line = ''
16
+ line << (char * count) unless last_iteration
17
+ line << $1
18
+ line << $2
19
+ line
20
+ end
21
+ end
22
+ end
23
+
24
+ def file_or_folder_exists?(file)
25
+ home = ENV['HOME']
26
+ path = "#{home}" "#{file}"
27
+ File.exist?(path)
28
+ end
29
+
30
+ def check_update_message(app)
31
+ puts "Checking #{app} for updates...".colorize(:light_white).bold
32
+ end
33
+
34
+ def break_output
35
+ puts ''
36
+ end
37
+
38
+ def yes_or_no
39
+ begin
40
+ system('stty raw -echo')
41
+ str = STDIN.getc
42
+ ensure
43
+ system('stty -raw echo')
44
+ end
45
+ if str == 'y'
46
+ puts ' - Performing...'
47
+ return true
48
+ elsif str == 'n'
49
+ return false
50
+ else
51
+ raise 'Invalid choice. Options are "y" or "n"'
52
+ end
53
+ end
54
+
55
+ def run?
56
+ if System::Update::AUTO_RUN == '--auto'
57
+ return true
58
+ else
59
+ puts ' - Do you want to perform this action? (y/n)'
60
+ yes_or_no
61
+ end
62
+ end
data/lib/zsh.rb ADDED
@@ -0,0 +1,22 @@
1
+ class ZSH
2
+ class << self
3
+ def installed?
4
+ file_or_folder_exists?('/.oh-my-zsh')
5
+ end
6
+
7
+ def update
8
+ check_update_message('Oh My Zsh')
9
+
10
+ Open3.popen3('env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh') do |stdin, stdout|
11
+ output = stdout.read
12
+ if output.include?('Current branch master is up to date')
13
+ puts ' - Oh My Zsh already up to date.'.colorize(:green)
14
+ else
15
+ puts ' - Updating Oh My Zsh...'.colorize(:green)
16
+ system 'env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh'
17
+ end
18
+ end
19
+ break_output
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev_osx_updater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Callum Barratt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-20 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Keep your development tools up to date like homebrew, zsh with an easy
70
+ run all script.
71
+ email:
72
+ - callum@bolser.co.uk
73
+ executables:
74
+ - dev_osx_update
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - README.md
79
+ - bin/dev_osx_update
80
+ - lib/brew.rb
81
+ - lib/dev_osx_updater/version.rb
82
+ - lib/osx.rb
83
+ - lib/rbenv.rb
84
+ - lib/ruby.rb
85
+ - lib/rvm.rb
86
+ - lib/system.rb
87
+ - lib/utility.rb
88
+ - lib/zsh.rb
89
+ homepage: https://github.com/cbarratt/mac_system_update
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.7
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Updates todays Ruby/Rails development tools used for developers.
113
+ test_files: []