boxen-halyard 2.8.0.akerl9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require "boxen/preflight"
2
+
3
+ class Boxen::Preflight::Rbenv < Boxen::Preflight
4
+ def run
5
+ warn "You have an existing rbenv installed in ~/.rbenv.",
6
+ "Boxen provides its own rbenv, so consider deleting yours."
7
+ end
8
+
9
+ def ok?
10
+ !File.exist? "#{ENV['HOME']}/.rbenv"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "boxen/preflight"
2
+
3
+ class Boxen::Preflight::RVM < Boxen::Preflight
4
+ def run
5
+ abort "You have an rvm installed in ~/.rvm.",
6
+ "Boxen uses rbenv to install ruby, so please `rvm implode`"
7
+ end
8
+
9
+ def ok?
10
+ !File.exist? "#{ENV['HOME']}/.rvm"
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Boxen
2
+
3
+ # A project managed by Boxen.
4
+
5
+ class Project
6
+
7
+ # The directory where this project's repo should live.
8
+
9
+ attr_reader :dir
10
+
11
+ # The name of this project.
12
+
13
+ attr_reader :name
14
+
15
+ def initialize(dir)
16
+ @dir = dir
17
+ @name = File.basename @dir
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,122 @@
1
+ require "fileutils"
2
+ require "boxen/util"
3
+
4
+ module Boxen
5
+
6
+ # Manages an invocation of puppet.
7
+
8
+ class Puppeteer
9
+
10
+ class Status < Struct.new(:code)
11
+ # Puppet's detailed exit codes reserves 2 for a successful run with changes
12
+ def success?
13
+ [0,2].include?(code)
14
+ end
15
+ end
16
+
17
+ attr_reader :config
18
+
19
+ def initialize(config)
20
+ @config = config
21
+ end
22
+
23
+ def command
24
+ manifestdir = "#{config.repodir}/manifests"
25
+ puppet = "#{config.repodir}/bin/puppet"
26
+
27
+ [puppet, "apply", flags, manifestdir].flatten
28
+ end
29
+
30
+ def hiera_config
31
+ if File.exist? "#{config.repodir}/config/hiera.yaml"
32
+ "#{config.repodir}/config/hiera.yaml"
33
+ else
34
+ "/dev/null"
35
+ end
36
+ end
37
+
38
+ def flags
39
+ flags = []
40
+ root = File.expand_path "../../..", __FILE__
41
+
42
+ flags << ["--group", "admin"]
43
+ flags << ["--confdir", "#{config.puppetdir}/conf"]
44
+ flags << ["--vardir", "#{config.puppetdir}/var"]
45
+ flags << ["--libdir", "#{config.repodir}/lib"]#:#{root}/lib"]
46
+ flags << ["--libdir", "#{root}/lib"]
47
+ flags << ["--modulepath", "#{config.repodir}/modules:#{config.repodir}/shared"]
48
+
49
+ # Don't ever complain about Hiera to me
50
+ flags << ["--hiera_config", hiera_config]
51
+
52
+ # Log to both the console and a file.
53
+
54
+ flags << ["--logdest", config.logfile]
55
+ flags << ["--logdest", "console"]
56
+
57
+ # For some reason Puppet tries to set up a bunch of rrd stuff
58
+ # (user, group) unless reports are completely disabled.
59
+
60
+ flags << "--no-report" unless config.report?
61
+ flags << "--detailed-exitcodes"
62
+
63
+ flags << "--graph" if config.graph?
64
+
65
+ flags << "--show_diff"
66
+
67
+ if config.profile?
68
+ flags << "--evaltrace"
69
+ flags << "--summarize"
70
+ flags << "--verbose"
71
+ end
72
+
73
+ if config.future_parser?
74
+ flags << "--parser=future"
75
+ end
76
+
77
+ flags << "--debug" if config.debug?
78
+ flags << "--noop" if config.pretend?
79
+
80
+ flags << "--color=false" unless config.color?
81
+
82
+ flags.flatten
83
+ end
84
+
85
+ def run
86
+ FileUtils.mkdir_p config.puppetdir
87
+
88
+ FileUtils.rm_f config.logfile
89
+
90
+ FileUtils.rm_rf "#{config.puppetdir}/var/reports" if config.report?
91
+
92
+ FileUtils.rm_rf "#{config.puppetdir}/var/state/graphs" if config.graph?
93
+
94
+ FileUtils.mkdir_p File.dirname config.logfile
95
+ FileUtils.touch config.logfile
96
+
97
+ if File.file? "Puppetfile"
98
+ librarian = "#{config.repodir}/bin/librarian-puppet"
99
+
100
+ unless config.enterprise?
101
+ # Set an environment variable for librarian-puppet's
102
+ # github_tarball source strategy.
103
+ ENV["GITHUB_API_TOKEN"] = config.token
104
+ end
105
+
106
+ librarian_command = [librarian, "install", "--path=#{config.repodir}/shared"]
107
+ librarian_command << "--verbose" if config.debug?
108
+
109
+ warn librarian_command.join(" ") if config.debug?
110
+ unless system *librarian_command
111
+ abort "Can't run Puppet, fetching dependencies with librarian failed."
112
+ end
113
+ end
114
+
115
+ warn command.join(" ") if config.debug?
116
+
117
+ Boxen::Util.sudo *command
118
+
119
+ Status.new($?.exitstatus)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,149 @@
1
+ require "boxen/checkout"
2
+ require "boxen/config"
3
+ require "boxen/hook"
4
+ require "boxen/flags"
5
+ require "boxen/puppeteer"
6
+ require "boxen/service"
7
+ require "boxen/util"
8
+ require "facter"
9
+
10
+ module Boxen
11
+ class Runner
12
+ attr_reader :config
13
+ attr_reader :flags
14
+ attr_reader :puppet
15
+ attr_reader :checkout
16
+ attr_reader :hooks
17
+
18
+ def initialize(config, flags)
19
+ @config = config
20
+ @flags = flags
21
+ @puppet = Boxen::Puppeteer.new(@config)
22
+ @checkout = Boxen::Checkout.new(@config)
23
+ @hooks = Boxen::Hook.all
24
+ end
25
+
26
+ def process
27
+ # --env prints out the current BOXEN_ env vars.
28
+
29
+ exec "env | grep ^BOXEN_ | sort" if flags.env?
30
+
31
+ process_flags
32
+
33
+ process_args
34
+
35
+ # Actually run Puppet and return its result
36
+
37
+ puppet.run
38
+ end
39
+
40
+ def run
41
+ report(process)
42
+ end
43
+
44
+ def report(result)
45
+ hooks.each { |hook| hook.new(config, checkout, puppet, result).run }
46
+
47
+ result
48
+ end
49
+
50
+ def process_flags
51
+
52
+ # --projects prints a list of available projects and exits.
53
+
54
+ if flags.projects?
55
+ puts "You can install any of these projects with `#{$0} <project-name>`:\n"
56
+
57
+ config.projects.each do |project|
58
+ puts " #{project.name}"
59
+ end
60
+
61
+ exit
62
+ end
63
+
64
+ # --disable-services stops all services
65
+
66
+ if flags.disable_services?
67
+ Boxen::Service.list.each do |service|
68
+ puts "Disabling #{service}..."
69
+ service.disable
70
+ end
71
+
72
+ exit
73
+ end
74
+
75
+ # --enable-services starts all services
76
+
77
+ if flags.enable_services?
78
+ Boxen::Service.list.each do |service|
79
+ puts "Enabling #{service}..."
80
+ service.enable
81
+ end
82
+
83
+ exit
84
+ end
85
+
86
+ # --disable-service [name] stops a service
87
+
88
+ if flags.disable_service?
89
+ service = Boxen::Service.new(flags.disable_service)
90
+ puts "Disabling #{service}..."
91
+ service.disable
92
+
93
+ exit
94
+ end
95
+
96
+ # --enable-service [name] starts a service
97
+
98
+ if flags.enable_service?
99
+ service = Boxen::Service.new(flags.enable_service)
100
+ puts "Enabling #{service}..."
101
+ service.enable
102
+
103
+ exit
104
+ end
105
+
106
+ # --restart-service [name] starts a service
107
+
108
+ if flags.restart_service?
109
+ service = Boxen::Service.new(flags.restart_service)
110
+ puts "Restarting #{service}..."
111
+ service.disable
112
+ service.enable
113
+
114
+ exit
115
+ end
116
+
117
+ # --list-services lists all services
118
+
119
+ if flags.list_services?
120
+ Boxen::Service.list.each do |service|
121
+ puts service
122
+ end
123
+
124
+ exit
125
+ end
126
+
127
+ # --restart-services restarts all services
128
+
129
+ if flags.restart_services?
130
+ Boxen::Service.list_enabled.each do |service|
131
+ puts "Restarting #{service}..."
132
+ service.disable
133
+ service.enable
134
+ end
135
+
136
+ exit
137
+ end
138
+
139
+ end
140
+
141
+ def process_args
142
+ projects = flags.args.join(',')
143
+ File.open("#{config.repodir}/.projects", "w+") do |f|
144
+ f.truncate 0
145
+ f.write projects
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,58 @@
1
+ require "boxen/util"
2
+
3
+ module Boxen
4
+ class Service
5
+ attr_reader :name
6
+
7
+ def self.list
8
+ files.collect do |service|
9
+ new(human_name(service))
10
+ end
11
+ end
12
+
13
+ def self.list_enabled
14
+ prefix = /^dev\./
15
+ enabled = capture_output("sudo /bin/launchctl list").split("\n").map { |l| l.split(/\s/) }.map(&:last)
16
+ names = enabled.grep(prefix).map { |name| name.sub(prefix, "") }.compact
17
+ names.map { |name| new(name) }
18
+ end
19
+
20
+ def initialize(name)
21
+ @name = name
22
+ end
23
+
24
+ def to_s
25
+ name
26
+ end
27
+
28
+ def enable
29
+ Boxen::Util.sudo('/bin/launchctl', 'load', '-w', location)
30
+ end
31
+
32
+ def disable
33
+ Boxen::Util.sudo('/bin/launchctl', 'unload', '-w', location)
34
+ end
35
+
36
+ private
37
+
38
+ def self.capture_output(command)
39
+ `#{command}`
40
+ end
41
+
42
+ def location
43
+ "#{self.class.location}/dev.#{name}.plist"
44
+ end
45
+
46
+ def self.location
47
+ "/Library/LaunchDaemons"
48
+ end
49
+
50
+ def self.files
51
+ Dir["#{location}/dev.*.plist"]
52
+ end
53
+
54
+ def self.human_name(service)
55
+ service.match(/dev\.(.+)\.plist$/)[1]
56
+ end
57
+ end
58
+ end
data/lib/boxen/util.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Boxen
2
+ module Util
3
+
4
+ # Is Boxen active?
5
+
6
+ def self.active?
7
+ ENV.include? "BOXEN_HOME"
8
+ end
9
+
10
+
11
+ # Run `args` as a system command with sudo if necessary.
12
+
13
+ def self.sudo *args
14
+ system "sudo", "-p", "Password for sudo: ", *args
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ require "json"
2
+ require "boxen/config"
3
+
4
+ config = Boxen::Config.load
5
+ facts = {}
6
+ factsdir = "#{config.homedir}/config/facts"
7
+ dot_boxen = "#{ENV['HOME']}/.boxen"
8
+ user_config = "#{dot_boxen}/config.json"
9
+
10
+ facts["github_login"] = config.login
11
+ facts["github_email"] = config.email
12
+ facts["github_name"] = config.name
13
+ facts["github_token"] = config.token
14
+
15
+ facts["boxen_home"] = config.homedir
16
+ facts["boxen_srcdir"] = config.srcdir
17
+ facts["boxen_repodir"] = config.repodir
18
+ facts["boxen_user"] = config.user
19
+ facts["luser"] = config.user # this is goin' away
20
+
21
+ Dir["#{config.homedir}/config/facts/*.json"].each do |file|
22
+ facts.merge! JSON.parse File.read file
23
+ end
24
+
25
+ if File.directory?(dot_boxen) && File.file?(user_config)
26
+ facts.merge! JSON.parse(File.read(user_config))
27
+ end
28
+
29
+ if File.file?(dot_boxen)
30
+ warn "DEPRECATION: ~/.boxen is deprecated and will be removed in 2.0; use ~/.boxen/config.json instead!"
31
+ facts.merge! JSON.parse(File.read(dot_boxen))
32
+ end
33
+
34
+ facts.each { |k, v| Facter.add(k) { setcode { v } } }
@@ -0,0 +1,13 @@
1
+ # Faraday helpfully reminds you to install `system_timer` if you're
2
+ # running Ruby 1.8, since Timeout can give unreliable results. We
3
+ # can't do this during first-time runs, since there's no C compiler
4
+ # available.
5
+ #
6
+ # To squash the message and stop confusing people, this shim just
7
+ # exposes Timeout as SystemTimer. I'm a bad person.
8
+
9
+
10
+ if (!defined?(RUBY_ENGINE) || "ruby" == RUBY_ENGINE) && RUBY_VERSION < '1.9'
11
+ require "timeout"
12
+ SystemTimer = Timeout
13
+ end