dmg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dmg.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/dmg ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/dmg'
4
+
5
+ DMG::CLI.run!
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "dmg/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "dmg"
7
+ s.version = Dmg::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Philippe Creux"]
10
+ s.email = ["pcreux@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Install popular applications provided as dmgs from the command line}
13
+ s.description = %q{It's like apt-get for Mac}
14
+
15
+ s.default_executable = %q{dmg}
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,7 @@
1
+ module DMG; end
2
+
3
+ require 'yaml'
4
+
5
+ %w{errors pkg cli}.each do |file|
6
+ require File.dirname(__FILE__) + "/dmg/#{file}"
7
+ end
@@ -0,0 +1,16 @@
1
+ class DMG::CLI
2
+ def self.run!
3
+ case ARGV[0]
4
+ when "install"
5
+ DMG::Pkg.install(ARGV[1..-1])
6
+ when "list"
7
+ DMG::Pkg.list
8
+ else
9
+ puts <<-EOF
10
+ Usage:
11
+ dmg install PACKAGE
12
+ dmg list
13
+ EOF
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module DMG
2
+ class DMGError < StandardError
3
+ end
4
+
5
+ class PackageNotFound < DMGError
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ module DMG
2
+ class Pkg
3
+ def self.list
4
+ puts all.map(&:name)
5
+ end
6
+
7
+ def self.install(pkg_names)
8
+ pkgs = pkg_names.map { |pkg_name| find!(pkg_name) }
9
+ pkgs.each(&:install!)
10
+ end
11
+
12
+ def self.all
13
+ return @@all if defined?(@@all)
14
+ @@all = []
15
+ pkgs = YAML.load_file(File.dirname(__FILE__) + '/pkgs.yml')
16
+ pkgs.each do |key, values|
17
+ @@all << Pkg.new({'name' => key}.merge(values))
18
+ end
19
+
20
+ @@all
21
+ end
22
+
23
+ attr_reader :name, :package, :url, :volume_dir
24
+
25
+ def initialize(args)
26
+ @name = args['name']
27
+ @package = args['package']
28
+ @url = args['url']
29
+ @volume_dir = args['volume_dir'] || @package
30
+ end
31
+
32
+ def install!
33
+ dmg_file = "~/Downloads/#{package}.dmg"
34
+ destination = '/Applications'
35
+
36
+ if "hdiutil info"[/image-path.*#{dmg_file}/]
37
+ puts "#{name} is already installed"
38
+ return
39
+ end
40
+
41
+ #run_cmd("curl -L #{url} -o #{dmg_file}")
42
+ run_cmd("hdid #{dmg_file}")
43
+ run_cmd "sudo cp -r '/Volumes/#{volume_dir}/#{package}.app' #{destination}"
44
+ run_cmd "hdiutil detach '/Volumes/#{volume_dir}'"
45
+ run_cmd("sudo chmod 755 #{destination}/#{package}.app/Contents/MacOS/#{package}")
46
+ end
47
+
48
+ protected
49
+
50
+ def self.find!(pkg_name)
51
+ pkg = all.select { |pkg| pkg.name == pkg_name }.first
52
+ raise PackageNotFound, "Can't find a package called '#{pkg_name}'" unless pkg
53
+
54
+ pkg
55
+ end
56
+
57
+ def run_cmd(cmd)
58
+ puts cmd
59
+ raise DMGError, "Failed to run a command" unless system(cmd)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,34 @@
1
+ dropbox:
2
+ package: Dropbox
3
+ volume_dir: Dropbox Installer
4
+ url: "http://www.dropbox.com/download?plat=mac"
5
+
6
+ chrome:
7
+ package: Google Chrome
8
+ url: "https://dl-ssl.google.com/chrome/mac/stable/GGRM/googlechrome.dmg"
9
+
10
+ skype:
11
+ package: Skype
12
+ url: http://www.skype.com/go/getskype-macosx.dmg
13
+
14
+ steam:
15
+ package: Steam
16
+ url: http://cdn.store.steampowered.com/public/client/installer/steam.dmg
17
+
18
+ macirssi:
19
+ package: MacIrssi
20
+ url: http://www.sysctl.co.uk/projects/macirssi/downloads/MacIrssi-0.8.6.6.dmg
21
+
22
+ picasa:
23
+ package: Picasa
24
+ url: http://dl.google.com/photos/picasamac38.dmg
25
+
26
+ adium:
27
+ package: Adium
28
+ volume_dir: Adium 1.4.1
29
+ url: http://download.adium.im/Adium_1.4.1.dmg
30
+
31
+ emacs:
32
+ package: Emacs
33
+ url: http://emacsformacosx.com/emacs-builds/Emacs-23.2-universal-10.6.3.dmg
34
+
@@ -0,0 +1,3 @@
1
+ module Dmg
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmg
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Philippe Creux
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-06 00:00:00 -07:00
19
+ default_executable: dmg
20
+ dependencies: []
21
+
22
+ description: It's like apt-get for Mac
23
+ email:
24
+ - pcreux@gmail.com
25
+ executables:
26
+ - dmg
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - bin/dmg
36
+ - dmg.gemspec
37
+ - lib/dmg.rb
38
+ - lib/dmg/cli.rb
39
+ - lib/dmg/errors.rb
40
+ - lib/dmg/pkg.rb
41
+ - lib/dmg/pkgs.yml
42
+ - lib/dmg/version.rb
43
+ has_rdoc: true
44
+ homepage: ""
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Install popular applications provided as dmgs from the command line
77
+ test_files: []
78
+