bin/derpy in derpy-1.1.6 vs bin/derpy in derpy-2.0.0
- old
+ new
@@ -1,4 +1,87 @@
#!/usr/bin/env ruby
require 'capistrano/cli'
-Capistrano::CLI.execute
+require 'fileutils'
+
+def derpy_capistrano
+ Capistrano::CLI.execute
+end
+
+def derpy_install
+ # make sure the user provided a target directory
+ if ARGV.length == 1
+ abort "Please specify the target directory."
+ # make sure the user didn't provide too many arguments
+ elsif ARGV.length > 2
+ abort "Too many arguments; please specify only the target directory."
+ end
+
+ # set the target directory
+ site_target_dir = ARGV[1]
+
+ # check if the target directory exists
+ if Dir.exists?(site_target_dir)
+ abort "Error: The target directory already exists."
+ end
+
+ # make remote repos
+ system('ssh git@git.3sign.com "cd git; mkdir [sitename] [sitename]/[sitename].git; cd [sitename]/[sitename].git; git --bare init;"'.gsub('[sitename]',site_target_dir))
+
+ # fetch and execute the drush make file
+ system('git clone git@github.com:3sign/threesign-standard-makefile.git')
+ system('drush make threesign-standard-makefile/threesign.make ' + site_target_dir)
+
+ # remove the drush make file
+ FileUtils.rm_rf 'threesign-standard-makefile'
+
+ Dir.chdir(site_target_dir) do
+ # remove .git directories
+ FileUtils.rm_rf Dir.glob("./**/.git/")
+
+ # create patches and drush directories
+ FileUtils.mkdir('sites/all/patches')
+ FileUtils.mkdir('sites/all/drush')
+
+ # copy the aliases file to the drush dir
+ source = File.expand_path(File.dirname(__FILE__)) + "/../templates/aliases.drushrc.php"
+ FileUtils.cp(source, 'sites/all/drush')
+ # replace [sitename] with site_target_dir
+ text = File.read('sites/all/drush/aliases.drushrc.php')
+ puts = text.gsub('[sitename]',site_target_dir)
+ File.open('sites/all/drush/aliases.drushrc.php', "w") {|file| file << puts}
+
+ # create local .htaccess
+ FileUtils.cp('.htaccess', '.htaccess.local')
+ # alter local .htaccess to use VirtualDocumentRoot
+ text = File.read('.htaccess.local')
+ puts = text.gsub('# RewriteBase /','RewriteBase /')
+ File.open('.htaccess.local', "w") {|file| file << puts}
+
+ # set up the core repo
+ system('git init')
+ system('git remote add origin git@git.3sign.com:git/[sitename]/[sitename].git'.gsub('[sitename]',site_target_dir))
+ File.open('.gitignore', 'a') { |file|
+ file.puts "# Ignore local .htaccess."
+ file.puts ".htaccess.local"
+ file.puts "# Ignore Capistrano config paths."
+ file.puts "Capfile"
+ file.puts "config"
+ file.puts "build"
+ }
+ # initial push
+ system('git add .')
+ system('git commit -am "initial commit"')
+ system('git push origin master')
+
+ puts "Derpy finished installing " + site_target_dir + ", YO!"
+ end
+end
+
+if ARGV.empty?
+ abort "Use 'derpy -T' to display Capistrano tasks.
+Use 'derpy install [sitename]' to install a new Drupal site."
+elsif ARGV.first == "install"
+ derpy_install
+else
+ derpy_capistrano
+end
\ No newline at end of file