Skip to content

Commit

Permalink
Added windows OS check; Added sudo check; Added expanded output; Dir …
Browse files Browse the repository at this point in the history
…permissions checks;
  • Loading branch information
rex committed Feb 24, 2014
1 parent d75924a commit f3b828d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 32 deletions.
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
gem "thor", ">= 0.17.x"
gem "highline", ">= 1.5.x"
gem "thor", ">= 0.17.0"
gem "highline", ">= 1.5.0"

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem 'coveralls', require: false
gem "rake", "~> 10.x"
gem "shoulda", ">= 3.x"
gem "rake", "~> 10.0"
gem "shoulda", ">= 3.0"
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0"
gem "jeweler", "~> 2.0.1"
gem "simplecov", ">= 0.8.x"
gem "simplecov", ">= 0.8.0"
end
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.0)
coveralls
highline (>= 1.5.x)
highline (>= 1.5.0)
jeweler (~> 2.0.1)
rake (~> 10.x)
rake (~> 10.0)
rdoc (~> 3.12)
shoulda (>= 3.x)
simplecov (>= 0.8.x)
thor (>= 0.17.x)
shoulda (>= 3.0)
simplecov (>= 0.8.0)
thor (>= 0.17.0)
13 changes: 2 additions & 11 deletions bin/server
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

require 'server/colorizer' # Bring in our string colors
require 'server/log' # Initialize our logs

$Log.debug("libdir > #{libdir}")
require 'server/signals' # Initialize our signal listeners

$Log.debug("ARGV: #{ARGV}")

Signal.trap("INT") { exit 1 }

require 'server'

Server.init

$Log.debug( "Server runtime path: #{Server.runtime_path}" )

$Log.debug( 'Requiring CLI' )
require 'server/cli'

$Log.debug( "Running server" )

Server::CLI.start(ARGV)
# Server::CLI.explain
Server::CLI.start(ARGV)
19 changes: 13 additions & 6 deletions lib/server.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
require 'server/sys'

module Server

class << self

attr_accessor :settings
attr_reader :runtime_path

autoload :CLI, 'server/cli'
autoload :Conf, 'server/conf'
autoload :Installed, 'server/installed'
autoload :Sys, 'server/sys'
attr_reader :runtime_path, :dir_sys, :dir_base

def init
@settings = { :setting_one => "foo", :setting_two => "bar" }
@runtime_path = File.expand_path('..', File.dirname( __FILE__ ) )

Server::Sys.init
end

def dir_sys
"/usr/local/etc"
end

def dir_base
"#{self.dir_sys}/server-gem"
end

end
Expand Down
1 change: 1 addition & 0 deletions lib/server/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CLI < Thor
class_option :info, :type => :boolean, :aliases => "-v", :desc => "Enable info logging"
class_option :verbose, :type => :boolean, :aliases => "-vv", :desc => "Enable verbose logging"
class_option :quiet, :type => :boolean, :aliases => "-q", :desc => "Silence all non-error logging"
class_option :expanded, :type => :boolean, :aliases => "-e", :desc => "Make logging output more roomy and easy to read"

no_commands do
def self.explain
Expand Down
6 changes: 5 additions & 1 deletion lib/server/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
prompt = "✓ ".blue
end

"#{prompt} #{msg.strip} \n"
if ARGV.include? "-e"
"#{prompt} #{datetime.strftime("%Y/%m/%d %H:%M:%S")} \n » #{msg.strip} \n\n"
else
"#{prompt} #{msg.strip} \n"
end
end

# $Log.debug("This is a debug message")
Expand Down
1 change: 1 addition & 0 deletions lib/server/signals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Signal.trap("INT") { exit 1 }
33 changes: 29 additions & 4 deletions lib/server/sys.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
require 'rbconfig'
require 'pathname'

module Server

class Sys

def self.yum_available?
`which yum` != ""
def self.init
self.running_on_windows?
self.running_as_sudo?
self.sysdir_writable?
end

def self.running_on_windows?
if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin/i
$Log.fatal("This gem and its tools are currently useless for Windows users. Maybe someday...")
abort()
end
end

def self.brew_available?
`which brew` != ""
def self.running_as_sudo?
if( Process.euid == 0 )
$Log.fatal("Cowardly avoiding sudo. Re-run without sudo.")
abort()
end
end

def self.sysdir_writable?
sysdir = Pathname.new(Server.dir_sys)

$Log.info("#{sysdir} is writable") if sysdir.writable?
$Log.fatal("#{sysdir} is not writable!") if !sysdir.writable?
abort() if !sysdir.writable?

sysdir.writable?
end

end
Expand Down

0 comments on commit f3b828d

Please sign in to comment.