summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-12 23:53:51 -0800
committerelijah <elijah@riseup.net>2012-11-12 23:53:51 -0800
commitc37a35df81b2d6becc09f1820240db24c3ec632c (patch)
tree50187e4ab1face237760614ecf844b42efdd51e1 /Rakefile
parentc90d30621e042cc3e52ffc87e3491ab110a57e9e (diff)
first fully working version of leap_ca
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile93
1 files changed, 93 insertions, 0 deletions
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..e28f38f
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,93 @@
+require "rubygems"
+require "highline/import"
+require "pty"
+require "fileutils"
+require 'rake/testtask'
+
+##
+## HELPER
+##
+
+def run(cmd)
+ PTY.spawn(cmd) do |output, input, pid|
+ begin
+ while line = output.gets do
+ puts line
+ end
+ rescue Errno::EIO
+ end
+ end
+rescue PTY::ChildExited
+end
+
+##
+## GEM BUILDING AND INSTALLING
+##
+
+$spec_path = 'leap_ca.gemspec'
+$spec = eval(File.read($spec_path))
+$base_dir = File.dirname(__FILE__)
+$gem_path = File.join($base_dir, 'pkg', "#{$spec.name}-#{$spec.version}.gem")
+
+def built_gem_path
+ Dir[File.join($base_dir, "#{$spec.name}-*.gem")].sort_by{|f| File.mtime(f)}.last
+end
+
+desc "Build #{$spec.name}-#{$spec.version}.gem into the pkg directory"
+task 'build' do
+ FileUtils.mkdir_p(File.join($base_dir, 'pkg'))
+ FileUtils.rm($gem_path) if File.exists?($gem_path)
+ run "gem build -V '#{$spec_path}'"
+ file_name = File.basename(built_gem_path)
+ FileUtils.mv(built_gem_path, 'pkg')
+ say "#{$spec.name} #{$spec.version} built to pkg/#{file_name}"
+end
+
+desc "Install #{$spec.name}-#{$spec.version}.gem into either system-wide or user gems"
+task 'install' do
+ if !File.exists?($gem_path)
+ say("Could not file #{$gem_path}. Try running 'rake build'")
+ else
+ if ENV["USER"] == "root"
+ run "gem install '#{$gem_path}'"
+ else
+ home_gem_path = Gem.path.grep(/home/).first
+ say("You are installing as an unprivileged user, which will result in the installation being placed in '#{home_gem_path}'.")
+ if agree("Do you want to continue installing to #{home_gem_path}? ")
+ run "gem install '#{$gem_path}' --user-install"
+ end
+ end
+ end
+end
+
+desc "Uninstall #{$spec.name}-#{$spec.version}.gem from either system-wide or user gems"
+task 'uninstall' do
+ if ENV["USER"] == "root"
+ say("Removing #{$spec.name}-#{$spec.version}.gem from system-wide gems")
+ run "gem uninstall '#{$spec.name}' --version #{$spec.version} --verbose -x -I"
+ else
+ say("Removing #{$spec.name}-#{$spec.version}.gem from user's gems")
+ run "gem uninstall '#{$spec.name}' --version #{$spec.version} --verbose --user-install -x -I"
+ end
+end
+
+##
+## TESTING
+##
+
+Rake::TestTask.new do |t|
+ t.pattern = "test/unit/*_test.rb"
+end
+task :default => :test
+
+##
+## DOCUMENTATION
+##
+
+# require 'rdoc/task'
+
+# Rake::RDocTask.new do |rd|
+# rd.main = "README.rdoc"
+# rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
+# rd.title = 'Your application title'
+# end