summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-09-10 08:41:05 +0200
committerAzul <azul@riseup.net>2013-09-10 08:41:05 +0200
commit32b79ec5865679655a4d3535ec5f97999da9d82e (patch)
tree545a5741e2e6e6138eac3f5b1023adfe0074b55e
parentfaeeb3ac56263a04b61f740b7d194b884a834d6a (diff)
copying over skeleton from leap_ca which worked similarly
-rw-r--r--Gemfile14
-rw-r--r--Gemfile.lock52
-rw-r--r--Rakefile93
-rwxr-xr-xbin/tapicero58
-rw-r--r--lib/tapicero/version.rb4
-rw-r--r--tapicero.gemspec29
6 files changed, 250 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..e5709fa
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,14 @@
+source "http://rubygems.org"
+
+# Declare your gem's dependencies in leap_ca.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+# To use debugger
+# gem 'ruby-debug'
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..3b42431
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,52 @@
+PATH
+ remote: .
+ specs:
+ tapicero (0.1.0)
+ couchrest (~> 1.1.3)
+ couchrest_model (~> 2.0.0.beta2)
+ daemons
+ yajl-ruby
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.2.14)
+ activesupport (= 3.2.14)
+ builder (~> 3.0.0)
+ activesupport (3.2.14)
+ i18n (~> 0.6, >= 0.6.4)
+ multi_json (~> 1.0)
+ builder (3.0.4)
+ couchrest (1.1.3)
+ mime-types (~> 1.15)
+ multi_json (~> 1.0)
+ rest-client (~> 1.6.1)
+ couchrest_model (2.0.0.beta2)
+ activemodel (~> 3.0)
+ couchrest (~> 1.1.3)
+ mime-types (~> 1.15)
+ tzinfo (~> 0.3.22)
+ daemons (1.1.9)
+ highline (1.6.19)
+ i18n (0.6.5)
+ metaclass (0.0.1)
+ mime-types (1.25)
+ minitest (3.2.0)
+ mocha (0.14.0)
+ metaclass (~> 0.0.1)
+ multi_json (1.8.0)
+ rake (10.1.0)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ tzinfo (0.3.37)
+ yajl-ruby (1.1.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ highline
+ minitest (~> 3.2.0)
+ mocha
+ rake
+ tapicero!
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
diff --git a/bin/tapicero b/bin/tapicero
new file mode 100755
index 0000000..d3b9d78
--- /dev/null
+++ b/bin/tapicero
@@ -0,0 +1,58 @@
+#!/usr/bin/ruby
+
+#
+# Tapicero Daemon
+#
+
+BASE_DIR = File.expand_path('../..', File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
+
+begin
+ #
+ # try without rubygems (might be already loaded or not present)
+ #
+ require 'tapicero/version'
+rescue LoadError
+ #
+ # try with rubygems
+ #
+ require "#{BASE_DIR}/lib/tapicero/version.rb"
+ Tapicero::REQUIRE_PATHS.each do |path|
+ path = File.expand_path(path, BASE_DIR)
+ $LOAD_PATH.unshift path unless $LOAD_PATH.include?(path)
+ end
+ require 'rubygems'
+ require 'tapicero/version'
+end
+
+# Graceful Ctrl-C
+Signal.trap("SIGINT") do
+ puts "\nQuit - leaving tapicero"
+ exit
+end
+
+# this changes later, so save the initial current directory
+CWD = Dir.pwd
+
+# handle --version ourselves
+if ARGV.grep(/--version/).any?
+ puts "tapicero #{Tapicero::VERSION}, ruby #{RUBY_VERSION}"
+ exit(0)
+end
+
+# --run-once will create databases for new users and then exit
+if ARGV.grep(/--once/).any? or ARGV.grep(/--run-once/).any?
+ require 'tapicero'
+ # TODO: implement me.
+ exit(0)
+end
+
+#
+# Start the daemon
+#
+require 'daemons'
+if ENV["USER"] == "root"
+ options = {:app_name => 'tapicero', :dir_mode => :system} # this will put the pid file in /var/run
+else
+ options = {:app_name => 'tapicero', :dir_mode => :normal, :dir => '/tmp'} # this will put the pid file in /tmp
+end
+Daemons.run("#{BASE_DIR}/lib/tapicero_daemon.rb", options)
diff --git a/lib/tapicero/version.rb b/lib/tapicero/version.rb
new file mode 100644
index 0000000..ec18e78
--- /dev/null
+++ b/lib/tapicero/version.rb
@@ -0,0 +1,4 @@
+module Tapicero
+ VERSION = "0.1.0"
+ REQUIRE_PATHS = ['lib']
+end
diff --git a/tapicero.gemspec b/tapicero.gemspec
new file mode 100644
index 0000000..8d80655
--- /dev/null
+++ b/tapicero.gemspec
@@ -0,0 +1,29 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "tapicero/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "tapicero"
+ s.version = Tapicero::VERSION
+ s.authors = ["Azul"]
+ s.email = ["azul@leap.se"]
+ s.homepage = "https://leap.se"
+ s.summary = "Tapicero - create per user databases for the LEAP Platform"
+ s.description = "Watches the couch database for users and creates per user databases when new users are created. This way soledad and the leap webapp do not need admin privileges required to create databases."
+
+ s.files = Dir["{config,lib}/**/*", 'bin/*'] + ["Rakefile", "Readme.md"]
+ s.test_files = Dir["test/**/*"]
+ s.bindir = 'bin'
+ s.executables << 'tapicero'
+
+ s.add_dependency "couchrest", "~> 1.1.3"
+ s.add_dependency "couchrest_model", "~> 2.0.0.beta2"
+ s.add_dependency "daemons"
+ s.add_dependency "yajl-ruby"
+ s.add_development_dependency "minitest", "~> 3.2.0"
+ s.add_development_dependency "mocha"
+ s.add_development_dependency "rake"
+ s.add_development_dependency "highline"
+end