passify 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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in passify.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Fabian Schwahn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # passify
2
+ `passify` is a command line interface (CLI) for [Passenger](http://www.modrails.com/), equivalent to what [powder](https://github.com/Rodreegez/powder) and [powify](https://github.com/sethvargo/powify) are for [pow](http://pow.cx/). I used the [PassengerPane](https://github.com/Fingertips/passengerpane), however I wanted the simplicity and speed of a CLI for that task.
3
+
4
+ ## Installation
5
+ gem install passify
6
+
7
+ ## Usage
8
+ `passify` is fully compatible with the PassengerPane, and only runs on MacOSX right now. The first step after the installation is to run the `install`-command:
9
+
10
+ passify install
11
+
12
+ This is necessary to ensure that Apache is set up correctly. If Passenger and the PassengerPane are already installed this command does nothing. To create a new application enter the application path and run
13
+
14
+ passify add [name]
15
+
16
+ The application name is optional, if none is provided `passify` creates the name from the current working directory. After creating an application it can be opened in the browser by running
17
+
18
+ passify open [name]
19
+
20
+ To restart the application run
21
+
22
+ passify restart
23
+
24
+ To remove the application run
25
+
26
+ passify remove [name]
27
+
28
+ A list of all applications served with `passify` can be viewed by running
29
+
30
+ passify list
31
+
32
+ Last but not least, `passify` can be removed from Apache by running
33
+
34
+ passify uninstall
35
+
36
+ Please note that this will also disable the PassengerPane. If you don't want to use `passify` anymore, but keep on using PassengerPane, just remove the gem:
37
+
38
+ gem uninstall passify
39
+
40
+ ### RVM
41
+ It makes sense to create a wrapper for `passify` if you are using multiple versions of ruby. If `passify` as installed for MRI 1.8.7, run the following command:
42
+
43
+ rvm wrapper 1.8.7 --no-prefix passify
44
+
45
+ ## License
46
+ Released under the MIT License. See the LICENSE file for further details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'passify/cli'
3
+
4
+ Passify::CLI.start
@@ -0,0 +1,213 @@
1
+ require 'rubygems'
2
+ require 'thor'
3
+ require 'passify/version'
4
+
5
+ module Passify
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+
9
+ APACHE_CONF = '/etc/apache2/httpd.conf'
10
+ VHOSTS_DIR = '/private/etc/apache2/passenger_pane_vhosts'
11
+
12
+ desc "add", "Creates an application from the current working directory."
13
+ def add(name = nil)
14
+ error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
15
+ error("This directory can not be served with Passenger. Please create a `config.ru`-file.") unless is_valid_app?
16
+ name = File.basename(pwd) if name.nil? || name.empty?
17
+ name = urlify(name)
18
+ host = "#{name}.local"
19
+ if app_exists?(host)
20
+ if is_same_app?(host, pwd)
21
+ notice("This directory is already being served from http://#{host}. Run `passify open #{name}` to view it.")
22
+ else
23
+ exit if no?("A different app already exists with under http://#{host}. Do you want to overwrite it?")
24
+ remove(name)
25
+ end
26
+ end
27
+
28
+ sudome
29
+ create_vhost(host, pwd)
30
+ register_host(host)
31
+ system("apachectl graceful > /dev/null 2>&1")
32
+ say "The application was successfully set up and can be reached from http://#{host} . Run `passify open #{name}` to view it."
33
+ end
34
+
35
+ desc "remove", "Removes an existing link to the current working directory."
36
+ def remove(name = nil)
37
+ error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
38
+ name = File.basename(pwd) if name.nil? || name.empty?
39
+ name = urlify(name)
40
+ host = "#{name}.local"
41
+ notice("No application exists under http://#{host} .") unless app_exists?(host)
42
+ sudome
43
+ remove_file(vhost_file(host))
44
+ unregister_host(host)
45
+ end
46
+
47
+ desc "install", "Installs passify into the local Apache installation."
48
+ def install
49
+ error("Passenger seems not to be installed. Refer to http://www.modrails.com/ for installation instructions.") unless passenger_installed?
50
+ notice("passify is already installed.") if passify_installed?
51
+ sudome
52
+ append_to_file APACHE_CONF, <<-eos
53
+ \n\n# Added by the Passenger preference pane
54
+ # Make sure to include the Passenger configuration (the LoadModule,
55
+ # PassengerRoot, and PassengerRuby directives) before this section.
56
+ <IfModule passenger_module>
57
+ NameVirtualHost *:80
58
+ <VirtualHost *:80>
59
+ ServerName _default_
60
+ </VirtualHost>
61
+ Include /private/etc/apache2/passenger_pane_vhosts/*.conf
62
+ </IfModule>
63
+ eos
64
+ system("apachectl graceful > /dev/null 2>&1")
65
+ FileUtils.mkdir_p(VHOSTS_DIR)
66
+ say "The installation of passify is complete."
67
+ end
68
+
69
+ desc "uninstall", "Uninstalls passify"
70
+ def uninstall
71
+ notice("passify is not installed.") unless passify_installed?
72
+ sudome
73
+ first_config_line = find_line_in_conf('# Added by the Passenger preference pane').to_i
74
+ system("sed -i '' '#{first_config_line},#{first_config_line+9}d' #{APACHE_CONF}")
75
+ say "The uninstallation of passify is complete. The vhosts in `#{VHOSTS_DIR}` have not been deleted."
76
+ end
77
+
78
+ desc "restart", "Restart the current application"
79
+ def restart
80
+ notice("The current directory does not seem to be a passenger application.") unless is_valid_app?
81
+ FileUtils.mkdir_p('tmp')
82
+ system "touch tmp/restart.txt"
83
+ end
84
+
85
+ desc "list", "Lists all applications served with passify."
86
+ def list
87
+ error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
88
+ Dir.foreach(VHOSTS_DIR) do |entry|
89
+ if File.file?("#{VHOSTS_DIR}/#{entry}")
90
+ host = entry[0..-12]
91
+ say " #{host} --> #{directory_for_host(host)}"
92
+ end
93
+ end
94
+ end
95
+
96
+ desc "open", "Opens the current working directory in browser."
97
+ def open(name = nil)
98
+ error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
99
+ name = File.basename(pwd) if name.nil? || name.empty?
100
+ name = urlify(name)
101
+ host = "#{name}.local"
102
+ system("open http://#{host}")
103
+ end
104
+
105
+ desc "version", "Shows the version"
106
+ def version
107
+ say "passify #{Passify::VERSION}"
108
+ end
109
+
110
+ private
111
+ # http://jimeh.me/blog/2010/02/22/built-in-sudo-for-ruby-command-line-tools/
112
+ def sudome
113
+ exec("#{sudo_command} passify #{ARGV.join(' ')}") if ENV["USER"] != "root"
114
+ end
115
+
116
+ def sudo_command
117
+ rvm_installed? ? 'rvmsudo' : 'sudo'
118
+ end
119
+
120
+ def rvm_installed?
121
+ system("which rvm > /dev/null 2>&1")
122
+ end
123
+
124
+ def passify_installed?
125
+ system("grep 'Include \\/private\\/etc\\/apache2\\/passenger_pane_vhosts\\/\\*\\.conf' #{APACHE_CONF} > /dev/null 2>&1")
126
+ end
127
+
128
+ def passenger_installed?
129
+ system("grep 'PassengerRuby' #{APACHE_CONF} > /dev/null 2>&1")
130
+ end
131
+
132
+ def is_valid_app?
133
+ if is_rack_app?
134
+ FileUtils.mkdir_p('public')
135
+ FileUtils.mkdir_p('tmp')
136
+ true
137
+ elsif is_rails2_app?
138
+ true
139
+ else
140
+ false
141
+ end
142
+ end
143
+
144
+ def is_rack_app?
145
+ File.exists?('config.ru')
146
+ end
147
+
148
+ def is_rails2_app?
149
+ system("grep 'RAILS_GEM_VERSION' config/environment.rb > /dev/null 2>&1")
150
+ end
151
+
152
+ def app_exists?(host)
153
+ File.exists?(vhost_file(host))
154
+ end
155
+
156
+ def is_same_app?(host, dir)
157
+ directory_for_host(host) == dir
158
+ end
159
+
160
+ def directory_for_host(host)
161
+ `grep 'DocumentRoot' #{vhost_file(host)}`.scan(/"([^"]*)"/).flatten[0][0..-8]
162
+ end
163
+
164
+ def find_line_in_conf(pattern)
165
+ `grep -n '#{pattern}' #{APACHE_CONF}`.split(":").first
166
+ end
167
+
168
+ def pwd
169
+ @pwd ||= Dir.pwd
170
+ end
171
+
172
+ def urlify(name)
173
+ name.downcase.gsub(/[\s\_]/, '-').gsub(/[^a-z\d\-]/, '').gsub(/\-+/, '-')
174
+ end
175
+
176
+ def error(message)
177
+ say message, :red
178
+ exit(false)
179
+ end
180
+
181
+ def notice(message)
182
+ say message, :yellow
183
+ exit
184
+ end
185
+
186
+ def create_vhost(host, path)
187
+ create_file vhost_file(host), <<-eos
188
+ <VirtualHost *:80>
189
+ ServerName #{host}
190
+ DocumentRoot "#{path}/public"
191
+ RackEnv development
192
+ <Directory "#{path}/public">
193
+ Allow from all
194
+ Options -MultiViews
195
+ </Directory>
196
+ </VirtualHost>
197
+ eos
198
+ end
199
+
200
+ def vhost_file(host)
201
+ "#{VHOSTS_DIR}/#{host}.vhost.conf"
202
+ end
203
+
204
+ def register_host(host)
205
+ system("/usr/bin/dscl localhost -create /Local/Default/Hosts/#{host} IPAddress 127.0.0.1 > /dev/null 2>&1")
206
+ end
207
+
208
+ def unregister_host(host)
209
+ system("/usr/bin/dscl localhost -delete /Local/Default/Hosts/#{host} > /dev/null 2>&1")
210
+ end
211
+
212
+ end
213
+ end
@@ -0,0 +1,3 @@
1
+ module Passify
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "passify/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "passify"
7
+ s.version = Passify::VERSION
8
+ s.authors = ["Fabian Schwahn"]
9
+ s.email = ["fabian.schwahn@gmail.com"]
10
+ s.homepage = "https://github.com/fschwahn/passify"
11
+ s.summary = %q{PassengerPane-compatible CLI for Phusion Passenger}
12
+ s.description = %q{passify is a command line interface (CLI) for Phusion Passenger, equivalent to what powder and powify are for pow. passify is compatible with PassengerPane.}
13
+
14
+ s.rubyforge_project = "passify"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency "thor"
23
+ s.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passify
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Fabian Schwahn
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ version_requirements: *id001
33
+ name: thor
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ version_requirements: *id002
47
+ name: rake
48
+ description: passify is a command line interface (CLI) for Phusion Passenger, equivalent to what powder and powify are for pow. passify is compatible with PassengerPane.
49
+ email:
50
+ - fabian.schwahn@gmail.com
51
+ executables:
52
+ - passify
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - bin/passify
64
+ - lib/passify/cli.rb
65
+ - lib/passify/version.rb
66
+ - passify.gemspec
67
+ homepage: https://github.com/fschwahn/passify
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project: passify
96
+ rubygems_version: 1.8.9
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: PassengerPane-compatible CLI for Phusion Passenger
100
+ test_files: []
101
+