#!/usr/bin/env ruby require 'optparse' require 'fileutils' OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} [path]" opts.on("-h", "--help", "Displays this help info") do puts opts exit 0 end begin opts.parse!(ARGV) rescue OptionParser::ParseError => e warn e.message puts opts exit 1 end end if ARGV.empty? abort "Please specify the directory to didify, e.g. `#{File.basename($0)} .'" elsif !File.exists?(ARGV.first) abort "`#{ARGV.first}' does not exist." elsif !File.directory?(ARGV.first) abort "`#{ARGV.first}' is not a directory." elsif ARGV.length > 1 abort "Too many arguments; please specify only the directory to didify." end def unindent(string) indentation = string[/\A\s*/] string.strip.gsub(/^#{indentation}/, "") end files = { "Capfile" => unindent(<<-FILE), require 'railsless-deploy' # gem install railsless-deploy require 'didi/recipes/didi.rb' # gem install capistrano-didi load 'config/deploy' require 'capistrano/ext/multistage' # gem install capistrano FILE "config/deploy.rb" => 'set :default_stage, "staging" set :stages, %w(dev acc staging prod) set :application, "PROJECT_NAME" set :repository, "git@gitlab.crosscheck.be:crosscheck/PROJECT_NAME" set :drupal_path, "docroot" set :baseline, "PROJECT_NAME_core" set :profile, "PROJECT_NAME_kickstart" set :domain, "PROJECT_NAME" set :sitemail, "support@crosscheck.be" set :adminpass, "drupal_admin_pass" set :theme_path, "#{drupal_path}/sites/PROJECT_NAME/themes/custom/#{theme}" # Compile .sass files to .css before "deploy:create_symlink", "grunt" # Re-enable the core module so dependencies are taken care of. before "drush:update", "drush:bl" # Clear cache before running any update commands (e.g. to update class registry # early). before "drush:update", "drush:cc" # Always trigger environment switch after deploy so the settings get updated. after "deploy", "drush:env_switch" # Development jobs, should not be executed after go-live. after "deploy", "drush:migrate" after "deploy", "drush:baseline_build" after "deploy", "drush:l10n_update" ', "config/deploy/dev.rb" => 'set :user, "crosscheck" server "SITE_NAME.dev.one-agency.be", :app, :web, :db, :primary => true set :deploy_to, "/home/www/vhosts/projects/PROJECT_NAME/dev/http" set :branch, "master" set :site, "SITE_NAME.dev.one-agency.be" set :db_type, "mysql" set :db_name, "PROJECT_NAME_dev" set :db_username, "PROJECT_NAME" set :db_password, "database_password" set :db_prefix, "" ', "config/deploy/acc.rb" => 'set :user, "crosscheck" server "SITE_NAME.acc.one-agency.be", :app, :web, :db, :primary => true set :deploy_to, "/home/www/vhosts/projects/PROJECT_NAME/acc/http" set :branch, "acc" set :site, "SITE_NAME.acc.one-agency.be" set :db_type, "mysql" set :db_name, "PROJECT_NAME_acc" set :db_username, "PROJECT_NAME" set :db_password, "database_password" set :db_prefix, "" ', "config/sql/scrub-database.sql" => < 0); -- don't leave e-mail addresses, etc in comments table. -- UPDATE comments SET name='Anonymous', mail='', homepage='http://example.com' WHERE uid=0; -- Scrub webform submissions. -- UPDATE webform_submitted_data set data='*scrubbed*'; -- remove sensitive customer data from custom module -- TRUNCATE custom_customer_lead_data; -- USER PASSWORDS -- These statements assume you want to preserve real passwords for developers. Change 'rid=3' to the -- developer or test role you want to preserve. -- DRUPAL 6 -- Remove passwords unless users have 'developer role' -- UPDATE users SET pass=md5('devpassword') WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3) AND uid > 0; -- Admin user should not be same but not really well known -- UPDATE users SET pass = MD5('supersecret!') WHERE uid = 1; -- DRUPAL 7 -- Drupal 7 requires sites to generate a hashed password specific to their site. A script in the -- docroot/scripts directory is provided for doing this. From your docroot run the following: -- -- scripts/password-hash.sh password -- -- this will generate a hash for the password "password". In the following statements replace -- $REPLACE THIS$ with your generated hash. -- Remove passwords unless users have 'developer role' -- UPDATE users SET pass='$REPLACE THIS$' WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3) AND uid > 0; -- Admin user should not be same but not really well known -- UPDATE users SET pass='$REPLACE THIS$' WHERE uid = 1; -- TRUNCATE accesslog; -- TRUNCATE access; -- TRUNCATE cache; -- TRUNCATE cache_filter; -- TRUNCATE cache_menu; -- TRUNCATE cache_page; -- TRUNCATE cache_views; -- TRUNCATE cache_views_data; -- TRUNCATE devel_queries; -- TRUNCATE devel_times; -- TRUNCATE flood; -- TRUNCATE history; -- TRUNCATE search_dataset; -- TRUNCATE search_index; -- TRUNCATE search_total; -- TRUNCATE sessions; -- TRUNCATE watchdog; scrub } base = ARGV.shift files.each do |file, content| file = File.join(base, file) if File.exists?(file) warn "[skip] '#{file}' already exists" elsif File.exists?(file.downcase) warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'" else unless File.exists?(File.dirname(file)) puts "[add] making directory '#{File.dirname(file)}'" FileUtils.mkdir_p(File.dirname(file)) end puts "[add] writing '#{file}'" File.open(file, "w") { |f| f.write(content) } end end puts "[done] didified!" unless File.exists?("#{base}/drupal") puts "" puts 'WARNING: drupal folder not found! install drupal in folder "drupal" or change the :drupal_path variable.' puts 'WARNING: for example: drush dl drupal --drupal-project-rename="drupal"' end puts "" puts 'After editing your config files just run: "didi deploy:cold" to set things up.' puts 'After that you can do incremental updates with: "didi deploy"' puts 'Or "didi deploy:rebuild" to setup from scratch'