fpm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/bin/fpm +158 -0
  2. metadata +81 -0
data/bin/fpm ADDED
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+
4
+ require "optparse"
5
+ require "ostruct"
6
+ require "erb"
7
+
8
+ def main(args)
9
+ settings = OpenStruct.new
10
+
11
+ opts = OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{$0} [options]"
13
+
14
+ opts.on("-p PACKAGEFILE", "--package PACKAGEFILE",
15
+ "The package file to manage") do |path|
16
+ if path =~ /^\//
17
+ settings.package_path = path
18
+ else
19
+ settings.package_path = "#{Dir.pwd}/#{path}"
20
+ end
21
+ end
22
+
23
+ opts.on("-n PACKAGENAME", "--name PACKAGENAME",
24
+ "What name to give to the package") do |name|
25
+ settings.package_name = name
26
+ end
27
+
28
+ opts.on("-v VERSION", "--version VERSION",
29
+ "version to give the package") do |version|
30
+ settings.version = version
31
+ end
32
+
33
+ opts.on("-d DEPENDENCY", "--depends DEPENDENCY") do |dep|
34
+ settings.dependencies ||= []
35
+ settings.dependencies << dep
36
+ end
37
+
38
+ opts.on("-a ARCHITECTURE", "--architecture ARCHITECTURE") do |arch|
39
+ settings.architecture = arch
40
+ end
41
+
42
+ opts.on("-m MAINTAINER", "--maintainer MAINTAINER") do |maintainer|
43
+ settings.maintainer = maintainer
44
+ end
45
+
46
+ opts.on("-C DIRECTORY", "Change directory before searching for files") do |dir|
47
+ settings.chdir = dir
48
+ end
49
+ end # OptionParser
50
+
51
+ opts.parse!(args)
52
+
53
+ # Actions:
54
+ # create package
55
+ #
56
+ # files: add, remove
57
+ # scripts: add, remove
58
+ # metadata: set, add, remove
59
+
60
+ if !settings.package_path
61
+ $stderr.puts "No package file given to manage. Give with -p PACKAGEFILE"
62
+ return 1
63
+ end
64
+
65
+ paths = args
66
+ type = settings.package_path.split(".")[-1]
67
+
68
+ mkbinding = lambda do
69
+ package = settings.package_name
70
+ version = settings.version
71
+ package_iteration = 1
72
+
73
+ maintainer = (settings.maintainer or "<#{ENV["USER"]}>")
74
+ category = (settings.category or "X11")
75
+ summary = (settings.summary or "no summary given for #{package}-#{version}")
76
+
77
+ architecture = (settings.architecture or %x(uname -m).chomp)
78
+ if architecture == "x86_64" && type == "deb"
79
+ architecture = "amd64"
80
+ end
81
+
82
+
83
+ url = (settings.url or "http://example.com/")
84
+ dependencies = (settings.dependencies or [])
85
+ return binding
86
+ end
87
+
88
+ metadata = mkbinding.call
89
+
90
+ package_path = settings.package_path
91
+ package_path.gsub!(/VERSION/, eval('"#{version}-#{package_iteration}"', metadata))
92
+ package_path.gsub!(/ARCH/, eval("architecture", metadata))
93
+
94
+
95
+ if type != "deb"
96
+ $stderr.puts "Unsupported package type '#{type}'"
97
+ return 1
98
+ end
99
+
100
+
101
+ builddir = "#{Dir.pwd}/build-#{type}-#{File.basename(package_path)}"
102
+ Dir.mkdir(builddir) if !File.directory?(builddir)
103
+ template = File.new("#{File.dirname(__FILE__)}/../templates/#{type}.erb").read()
104
+
105
+ Dir.chdir(settings.chdir || ".") do
106
+ puts Dir.pwd
107
+
108
+ # Add directories first.
109
+ dirs = []
110
+ paths.each do |path|
111
+ while path != "/" and path != "."
112
+ if !dirs.include?(path) or File.symlink?(path)
113
+ dirs << path
114
+ else
115
+ #puts "Skipping: #{path}"
116
+ #puts !dirs.include?(path)
117
+ #puts !File.symlink?(path)
118
+ end
119
+ path = File.dirname(path)
120
+ end
121
+ end
122
+ dirs = dirs.sort { |a,b| a.length <=> b.length}
123
+ puts dirs.join("\n")
124
+ system(*["tar", "--owner=root", "--group=root", "-cf", "#{builddir}/data.tar", "--no-recursion", *dirs])
125
+ puts paths.join("\n")
126
+ #paths = paths.reject { |p| File.symlink?(p) }
127
+ system(*["tar", "--owner=root", "--group=root", "-rf", "#{builddir}/data.tar", *paths])
128
+ system(*["gzip", "-f", "#{builddir}/data.tar"])
129
+
130
+ # Generate md5sums
131
+ md5sums = []
132
+ paths.each do |path|
133
+ md5sums += %x{find #{path} -type f -print0 | xargs -0 md5sum}.split("\n")
134
+ end
135
+ File.open("#{builddir}/md5sums", "w") { |f| f.puts md5sums.join("\n") }
136
+
137
+ # Generate 'control' file
138
+ control = ERB.new(template).result(metadata)
139
+ File.open("#{builddir}/control", "w") { |f| f.puts control }
140
+ end
141
+
142
+ # create control.tar.gz
143
+ Dir.chdir(builddir) do
144
+ system("tar -zcf control.tar.gz control md5sums")
145
+ end
146
+
147
+ Dir.chdir(builddir) do
148
+ # create debian-binary
149
+ File.open("debian-binary", "w") { |f| f.puts "2.0" }
150
+ end
151
+
152
+ Dir.chdir(builddir) do
153
+ system("ar -qc #{package_path} debian-binary control.tar.gz data.tar.gz")
154
+ end
155
+ end
156
+
157
+ ret = main(ARGV)
158
+ exit(ret != nil ? ret : 0)
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fpm
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jordan Sissel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-03 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Turn directories into packages. Fix broken packages. Win the package management game.
36
+ email: jls@semicomplete.com
37
+ executables:
38
+ - fpm
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - bin/fpm
45
+ has_rdoc: true
46
+ homepage: https://github.com/jordansissel/fpm
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: fpm - package building and mangling
80
+ test_files: []
81
+