Skip to content

Instantly share code, notes, and snippets.

@trev
Created January 19, 2012 05:00
Show Gist options
  • Save trev/1638057 to your computer and use it in GitHub Desktop.
Save trev/1638057 to your computer and use it in GitHub Desktop.
Prepdev
#!/usr/bin/env ruby
# A script to setup a PHP dev. environment on a local MacOSX 10.6.8+ machine
require 'optparse'
# This hash will hold all of the options
# parsed from the command-line by
# OptionParser.
options = {}
optparse = OptionParser.new do |opts|
# Set a banner, displayed at the top
# of the help screen.
opts.banner = "Usage: prepdev.rb [options] directory [virtual_host_name]"
# This displays the help screen, all programs are
# assumed to have this option.
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
# Parse the command-line.
optparse.parse!
# Display help if no first var
if ARGV[0].nil?
puts optparse.help
end
# Extract actual directory name from path
fullpath = ARGV[0]
dirname = fullpath.split('/').last
# Create Directory
if !File.directory? fullpath
# Directory doesn't exists so lets create it
begin
Dir.mkdir fullpath
rescue => e
puts "Could not create directory: " + e.message
end
end
# Create log directory
if !File.directory? '/var/log/apache2/' + dirname
# Directory doesn't exists so lets create it
begin
Dir.mkdir '/var/log/apache2/' + dirname
rescue => e
puts "Could not create directory: " + e.message
puts e.errno == 13 ? "Run script using sudo" : ""
end
end
# Create symlink to log directory
if !File.symlink? fullpath + '/logs'
#Symlink doesn't exists so lets create it
begin
File.symlink("/var/log/apache2/" + dirname, fullpath+ "/logs")
rescue => e
puts "Could not create log symlink: " + e.message
puts e.errno == 13 ? "Run script using sudo" : ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment