vh 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -1
- data/bin/vh +19 -3
- data/lib/vh.rb +18 -1
- data/lib/vh/apache_config.rb +1 -1
- data/lib/vh/apache_installer.rb +57 -0
- data/lib/vh/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
Virtual Hosts manager for the CLI -- a dead simple script to add new virtual hosts
|
4
4
|
that will ease the local development of web apps with Apache.
|
5
5
|
|
6
|
+
**This is currently a WIP so things will not likely work** :)
|
7
|
+
|
8
|
+
## Prerequisites
|
9
|
+
|
10
|
+
Add this line to your `/etc/apache2/httpd.conf`:
|
11
|
+
|
12
|
+
Include /etc/apache2/extra/httpd-vhosts.conf
|
13
|
+
|
6
14
|
## Installation
|
7
15
|
|
8
16
|
Add this line to your application's Gemfile:
|
@@ -49,4 +57,4 @@ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIG
|
|
49
57
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
50
58
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
51
59
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
52
|
-
```
|
60
|
+
```
|
data/bin/vh
CHANGED
@@ -5,9 +5,25 @@ require "pathname"
|
|
5
5
|
|
6
6
|
# Validate required arguments
|
7
7
|
if ARGV.length < 2
|
8
|
-
puts
|
9
|
-
|
10
|
-
|
8
|
+
puts <<-HELP
|
9
|
+
You seem to have missed some arguments.
|
10
|
+
Here is a simple usage section for you to enjoy:
|
11
|
+
|
12
|
+
#{$0} PATH HOSTNAME
|
13
|
+
|
14
|
+
Where:
|
15
|
+
- PATH: Is a filesystem path (relative or absolute) to the web root.
|
16
|
+
- HOSTNAME: Is the hostname that you'll use to access the web.
|
17
|
+
|
18
|
+
For instance, executing:
|
19
|
+
|
20
|
+
#{$0} ./web my.nifty.server
|
21
|
+
|
22
|
+
Will create a new web root at ./web that will be accessed
|
23
|
+
via http://my.nifty.server/
|
24
|
+
|
25
|
+
HELP
|
26
|
+
|
11
27
|
exit 1
|
12
28
|
end
|
13
29
|
|
data/lib/vh.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "vh/apache_installer"
|
1
2
|
require "vh/apache_config"
|
2
3
|
require "vh/hosts_config"
|
3
4
|
require "vh/apache_handler"
|
@@ -14,6 +15,9 @@ module Vh
|
|
14
15
|
#
|
15
16
|
# @return [Vh]
|
16
17
|
def self.add(path, hostname)
|
18
|
+
# Check and install if necessary the configuration on the web server
|
19
|
+
self.install
|
20
|
+
|
17
21
|
# Add the host to the Apache configuration
|
18
22
|
apache_config = ApacheConfig.new path, hostname
|
19
23
|
apache_config.run
|
@@ -28,4 +32,17 @@ module Vh
|
|
28
32
|
|
29
33
|
return self
|
30
34
|
end
|
31
|
-
|
35
|
+
|
36
|
+
# Installs - if necessary - the initial configuration needed
|
37
|
+
# for the Virtual Hosts to be properly included in the Apache
|
38
|
+
# configuration.
|
39
|
+
#
|
40
|
+
# @return [Vh]
|
41
|
+
def self.install
|
42
|
+
# Install the Apache configuration include
|
43
|
+
apache_installer = ApacheInstaller.new
|
44
|
+
apache_installer.run
|
45
|
+
|
46
|
+
return self
|
47
|
+
end
|
48
|
+
end
|
data/lib/vh/apache_config.rb
CHANGED
@@ -30,7 +30,7 @@ module Vh
|
|
30
30
|
|
31
31
|
# Check if the configuration file is writable
|
32
32
|
unless check_writable?
|
33
|
-
puts "The Apache configuration file is not writable by the current user."
|
33
|
+
puts "The Apache configuration file (#{@config_path}) is not writable by the current user."
|
34
34
|
return false
|
35
35
|
end
|
36
36
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "vh/base_config"
|
2
|
+
require "vh/apache_config"
|
3
|
+
|
4
|
+
module Vh
|
5
|
+
# Apache installation manager
|
6
|
+
class ApacheInstaller < BaseConfig
|
7
|
+
DEFAULT_CONFIG_PATH = "/etc/apache2/httpd.conf"
|
8
|
+
|
9
|
+
# Initializes a new instance of this class.
|
10
|
+
#
|
11
|
+
# @param [String] target_path The path to the vh configuration file that will be included by Apache.
|
12
|
+
# @param [String] config_path The path to the configuration path (optional, defaults to `DEFAULT_CONFIG_PATH`).
|
13
|
+
def initialize(target_path = ApacheConfig::DEFAULT_CONFIG_PATH, config_path = DEFAULT_CONFIG_PATH)
|
14
|
+
@target = Pathname.new(target_path).realpath.to_s
|
15
|
+
@config_path = config_path
|
16
|
+
end
|
17
|
+
|
18
|
+
# Performs any necessary checks prior to modifying the configuration file
|
19
|
+
# and returns a `Boolean` value indicating whether the checks were successful or not.
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
def check?
|
23
|
+
# Check if the configuration path exists and is a file
|
24
|
+
unless File.exists? @config_path
|
25
|
+
puts "#{@config_path} is not a valid path."
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
# Check if the configuration file is writable
|
30
|
+
unless check_writable?
|
31
|
+
puts "The Apache configuration file (#{@config_path}) is not writable by the current user."
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Check if there is not already a virtual host defined with the same host name
|
36
|
+
unless check_content? /^\s*Include\s+#{@target}$/i
|
37
|
+
puts "The target configuration file (#{@target}) is already being included by Apache."
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
|
41
|
+
# Success! :)
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
# Generates the new content that will be appended to the configuration file.
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
def new_config_content
|
49
|
+
return <<-VHOST
|
50
|
+
|
51
|
+
# vh configuration file
|
52
|
+
Include #{@target}
|
53
|
+
# /vh configuration file
|
54
|
+
VHOST
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/vh/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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: 2012-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/vh.rb
|
45
45
|
- lib/vh/apache_config.rb
|
46
46
|
- lib/vh/apache_handler.rb
|
47
|
+
- lib/vh/apache_installer.rb
|
47
48
|
- lib/vh/base_config.rb
|
48
49
|
- lib/vh/hosts_config.rb
|
49
50
|
- lib/vh/version.rb
|