devinstall 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/pkg-tool CHANGED
@@ -5,49 +5,51 @@ require 'devinstall'
5
5
  require 'devinstall/settings'
6
6
 
7
7
  begin
8
- opt =Getopt::Long.getopts(
9
- ['--version', '-v',],
10
- ['--package', '-p', Getopt::REQUIRED],
11
- ['--config', '-c', Getopt::REQUIRED],
12
- ['--type', '-t', Getopt::REQUIRED],
13
- ['--env', '-e', Getopt::REQUIRED],
14
- ['--build', '-b', ],
15
- ['--upload', '-u', ],
16
- ['--install', '-i', ],
17
- ['--help', '-h', ],
18
- )
8
+ opt =Getopt::Long.getopts(
9
+ ['--version', '-v',],
10
+ ['--package', '-p', Getopt::REQUIRED],
11
+ ['--config', '-c', Getopt::REQUIRED],
12
+ ['--type', '-t', Getopt::REQUIRED],
13
+ ['--env', '-e', Getopt::REQUIRED],
14
+ ['--build', '-b',],
15
+ ['--upload', '-u',],
16
+ ['--install', '-i',],
17
+ ['--help', '-h',],
18
+ )
19
19
  rescue
20
- puts "Invalid option in command line"
21
- puts 'Usage: pkg-install --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment> --build|--upload|--install'
20
+ puts 'Invalid option in command line'
21
+ help!
22
22
  exit!(1)
23
23
  end
24
24
 
25
+ def help!
26
+ puts 'Usage: pkg-install --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment> --build|--upload|--install'
27
+ end
28
+
25
29
  if opt['version']
26
30
  puts "devinstall version #{Devinstall::VERSION}"
27
31
  puts "pkg-tool version #{Devinstall::VERSION}"
28
32
  exit(0)
29
33
  end
34
+
30
35
  if opt['help']
31
- puts 'Usage: pkg-install --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment> --build|--upload|--install'
36
+ help!
32
37
  exit!(0)
33
38
  end
34
- if !( opt['package'] && opt['config'] && opt['type'] && opt['env'] && (opt['build'] || opt['upload'] || opt['install']))
39
+
40
+ unless opt['package'] && opt['config'] && opt['type'] && opt['env'] && (opt['build'] || opt['upload'] || opt['install'])
35
41
  puts 'You must speciffy --config file, --package, --type and --env and one of the actions (--build, --install, --upload)'
36
42
  exit!(0)
37
43
  end
38
44
  Settings.load!(opt['config'])
39
45
  package=Pkg.new(opt['package'])
40
46
 
41
- if opt[:build]
47
+ if opt['build']
42
48
  package.build!(opt['type'].to_sym)
43
- end
44
-
45
- if opt[:install]
49
+ elsif opt['install']
46
50
  package.build!(opt['type'].to_sym)
47
51
  package.install!(opt['env'].to_sym)
48
- end
49
-
50
- if opt[:upload]
52
+ elsif opt['upload']
51
53
  package.build!(opt['type'].to_sym)
52
54
  package.upload!(opt['env'].to_sym)
53
55
  end
data/doc/example.yml CHANGED
@@ -13,10 +13,12 @@ build:
13
13
  # folder - rsync to?
14
14
  # target - the folder where packages will be generated (defaults to folder)
15
15
  # user - for ssh / rsync
16
+ # arch is the architecture for the generated package (like amd64 or i686)
16
17
  user: dboca
17
18
  host: vm.development.lan
18
19
  folder: rs
19
20
  target: rs
21
+ arch: all
20
22
  install:
21
23
  # host - dev/prod deploy and install host
22
24
  # user - for scp / ssh / rsync (defaults to base[user])
@@ -28,12 +30,15 @@ install:
28
30
  type: deb
29
31
  folder: ~ ## folder for scp
30
32
  user: dboca1
33
+ arch: all
31
34
  prod:
32
35
  host: prod01.server.lan
33
36
  type: rpm
37
+ arch: all
34
38
  # user defaults to install[:user]
35
39
  repos:
36
40
  # for repository deployment
41
+ # in a repository should be all packages for all architectures so we don't have an 'arch:' field
37
42
  environments:
38
43
  dev:
39
44
  type: deb
@@ -1,3 +1,3 @@
1
1
  module Devinstall
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/devinstall.rb CHANGED
@@ -7,96 +7,100 @@ require 'devinstall/settings' ## in near future we will have to abandon Setting
7
7
  module Devinstall
8
8
  class Pkg
9
9
 
10
+
11
+ # @param [Symbol] type
10
12
  def get_version(type)
11
- if type == :deb # curently implemented only for .deb packages
12
- deb_changelog ="#{Settings.local[:folder]}/#{package}/debian/changelog"
13
+ if type == :deb
14
+ deb_changelog = "#{Settings.local[:folder]}/debian/changelog" # This is the folder that should be checked
13
15
  deb_package_version =File.open(deb_changelog, 'r').gets.chomp.sub(/^.*\((.*)\).*$/, "\1")
14
16
  @_package_version[:deb]=deb_package_version
15
17
  end
16
18
  end
19
+ end
17
20
 
18
- def new (package)
19
- # curently implemented only for .deb packages (for .rpm later :D)
20
- @package =package.to_sym
21
- @_package_version =Hash.new # versions for types:
22
- @package_files =Hash.new
23
- pname ="#{package}_#{get_version :deb}"
24
- @package_files[:deb] ={deb: "#{pname}_all.deb",
25
- tgz: "#{pname}.tar.gz",
26
- dsc: "#{pname}.dsc",
27
- chg: "#{pname}_debian.changes"}
28
- end
29
-
30
- def upload! (environment)
31
- scp =Settings.base[:scp]
32
- repo =Hash.new
33
- type =Settings.repos[environment][:type]
34
- [:user, :host, :folder].each do |k|
35
- fail("Unexistent key repos:#{environment}:#{k}") unless Settings.repos[environment].has_key?(k)
36
- repo[k]=Settings.repos[environment][k]
37
- end
38
- build(type)
39
- @package_files[type].each do |p|
40
- system("#{scp} #{Settings.local[:temp]}/#{p} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
41
- end
21
+ def new (package)
22
+ # curently implemented only for .deb packages (for .rpm later :D)
23
+ @package =package.to_sym
24
+ @_package_version =Hash.new # versions for types:
25
+ @package_files =Hash.new
26
+ arch =Settings.build[:arch]
27
+ pname ="#{package}_#{get_version :deb}"
28
+ @package_files[:deb] ={deb: "#{pname}_#{arch}.deb",
29
+ tgz: "#{pname}.tar.gz",
30
+ dsc: "#{pname}.dsc",
31
+ chg: "#{pname}_debian.changes"}
32
+ end
42
33
 
34
+ def upload! (environment)
35
+ scp =Settings.base[:scp]
36
+ repo =Hash.new
37
+ type =Settings.repos[environment][:type]
38
+ [:user, :host, :folder].each do |k|
39
+ fail("Unexistent key repos:#{environment}:#{k}") unless Settings.repos[environment].has_key?(k)
40
+ repo[k]=Settings.repos[environment][k]
41
+ end
42
+ build(type)
43
+ @package_files[type].each do |p|
44
+ system("#{scp} #{Settings.local[:temp]}/#{p} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
43
45
  end
46
+ end
44
47
 
45
- # @param [Symbol] type
46
- def build! (type)
47
- unless Settings.packages[@package].has_key?(type)
48
- puts("Package '#{@package}' cannot be built for the required environment")
49
- puts("undefined build configuration for '#{type.to_s}'")
48
+ # @param [Symbol] type
49
+ def build! (type)
50
+ unless Settings.packages[@package].has_key?(type)
51
+ puts("Package '#{@package}' cannot be built for the required environment")
52
+ puts("undefined build configuration for '#{type.to_s}'")
53
+ exit!(1)
54
+ end
55
+ build =Hash.new
56
+ [:user, :host, :folder, :target].each do |k|
57
+ unless Settings.build.has_key?(k)
58
+ puts("Undefined key 'build:#{k.to_s}:'")
50
59
  exit!(1)
51
60
  end
52
- build =Hash.new
53
- [:user, :host, :folder, :target].each do |k|
54
- unless Settings.build.has_key?(k)
55
- puts("Undefined key 'build:#{k.to_s}:'")
56
- exit!(1)
57
- end
58
- build[k]=Settings.build[k]
59
- end
60
- ssh =Settings.base[:ssh]
61
- build_command=Settings.packages[@package][type][:build_command]
62
- rsync =Settings.base[:rsync]
63
- local_folder =Settings.local[:folder]
64
- local_temp =Settings.local[:temp]
65
- build_command.sub('%f', Settings.build[:folder]).
66
- sub('%t', Settings.build[:target]).
67
- sub('%p', @package.to_s).
68
- sub('%T', type.to_s)
61
+ build[k]=Settings.build[k]
62
+ end
69
63
 
70
- system("#{rsync} -az #{local_folder}/ #{build[:user]}@#{build[:host]}:#{build[:folder]}")
71
- system("#{ssh} #{build[:user]}@#{build[:host]} -c \"#{build_command}\"")
72
- @package_files[type].each do |p|
73
- system("#{rsync} -az #{build[:user]}@#{build[:host]}/#{build[:target]}/#{p} #{local_temp}")
74
- end
64
+ ssh =Settings.base[:ssh]
65
+ build_command=Settings.packages[@package][type][:build_command]
66
+ rsync =Settings.base[:rsync]
67
+ local_folder =Settings.local[:folder]
68
+ local_temp =Settings.local[:temp]
69
+ build_command.sub('%f', Settings.build[:folder]).
70
+ sub('%t', Settings.build[:target]).
71
+ sub('%p', @package.to_s).
72
+ sub('%T', type.to_s)
73
+
74
+ system("#{rsync} -az #{local_folder}/ #{build[:user]}@#{build[:host]}:#{build[:folder]}")
75
+ system("#{ssh} #{build[:user]}@#{build[:host]} -c \"#{build_command}\"")
76
+ @package_files[type].each do |p|
77
+ system("#{rsync} -az #{build[:user]}@#{build[:host]}/#{build[:target]}/#{p} #{local_temp}")
75
78
  end
79
+ end
76
80
 
77
- def install! (environment)
78
- sudo =Settings.base[:sudo]
79
- scp =Settings.base[:scp]
80
- type =Settings.install[environment][:type]
81
- local_temp =Settings.local[:temp]
82
- build!(type)
83
- install=Hash.new
84
- [:user, :host, :folder].each do |k|
85
- unless Settings.install[environment].has_key?(k)
86
- puts "Undefined key 'install:#{environment.to_s}:#{k.to_s}'"
87
- exit!(1)
88
- end
89
- install[k]=Settings[environment][k]
90
- end
91
- case type.to_sym
92
- when :deb
93
- system("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{install[:host]}/#{install[:folder]}")
94
- system("#{sudo} #{build![:user]}@#{build[:host]} \"dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}")
95
- else
96
- puts "unknown package type '#{type.to_s}'"
97
- exit!(1)
81
+ def install! (environment)
82
+ sudo =Settings.base[:sudo]
83
+ scp =Settings.base[:scp]
84
+ type =Settings.install[environment][:type]
85
+ local_temp =Settings.local[:temp]
86
+ build!(type)
87
+ install=Hash.new
88
+ [:user, :host, :folder].each do |k|
89
+ unless Settings.install[environment].has_key?(k)
90
+ puts "Undefined key 'install:#{environment.to_s}:#{k.to_s}'"
91
+ exit!(1)
98
92
  end
93
+ install[k]=Settings[environment][k]
94
+ end
95
+ case type.to_sym
96
+ when :deb
97
+ system("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{install[:host]}/#{install[:folder]}")
98
+ system("#{sudo} #{build![:user]}@#{build[:host]} \"dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}")
99
+ else
100
+ puts "unknown package type '#{type.to_s}'"
101
+ exit!(1)
99
102
  end
100
103
  end
101
104
  end
102
105
 
106
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devinstall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler