<commit_before>#default_run_options[:pty] = true

#Relies on :password and :aws_private_key_path being set in the deployer .caprc file.

set :application, "rivulet"
set :repository,  "https://github.com/jplewicke/rivulet"

# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/var/www/#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
set :scm, :git

#role :app, "www.tryrivulet.com"
#role :web, "www.tryrivulet.com"
#role :db,  "www.tryrivulet.com", :primary => true

#set :application, "yyyyy.vamosa.com"
#set :domain, "yyyyy.vamosa.com"
set :ami_name, "ami-c9bc58a0"

#change to alestic maverick
set :ami_name, "ami-1a837773" 
#change to alestic lucid
#set :ami_name, "ami-a403f7cd"
set :image_type, "m1.small"



default_run_options[:pty] = false


namespace :ec2 do
  
  set :new_user, "deploy"
  
  set :superuser, "ubuntu"
  
  desc "Setup server"
  task :setup_server do
    create_ec2_server
    wait_spinup
    bootstrap_deploy_user
    #setup_env
    #shutdown_ami
    #test_sudo
  end
  
  desc "sudo_testing"
  task :test_sudo do
    #set :user, "ubuntu"
    
    #ssh_options[:keys] = aws_private_key_path
    puts user
    
    run "pwd"
  end
  
  desc "spinup a server"
  task :create_ec2_server do
    set :ami, `ec2-run-instances -k #{aws_private_key_name} -t #{image_type} #{ami_name} | awk '$1 ~ /INSTANCE/ {printf $2}'`
    puts ami
  end
  
  desc "wait for server to spinup and grab the host-name"
  task :wait_spinup do
    set :hostname, "pending"
    dly = 5.0
    
    while hostname == "pending" do
      sleep dly 
      set :hostname, `ec2-describe-instances #{ami} | awk '$1 ~ /INST/ {printf $4}'`
      dly *= 1.5
      
      
      
      puts hostname
    end
    
    server hostname, :web, :app, :db
    puts hostname
  end
  
  desc "uploads id_rsa.pub to the EC2 instance's deploy users authorized_keys2 file"
  task :bootstrap_deploy_user do
    #old_key_loc = ssh_options[:keys]
    #ssh_options[:keys] = aws_private_key_path
    sleep 10.0
    set :user, superuser
    puts user
    puts password
    
    #Add server to known hosts.
    ssh_creds = "-i #{aws_private_key_path} #{superuser}@#{hostname} \"sudo "
    
    puts "ssh -oStrictHostKeyChecking=no #{ssh_creds} pwd\""
    system  "ssh -oStrictHostKeyChecking=no #{ssh_creds} pwd\""
    system "ssh #{ssh_creds} groupadd admin\""
    
    puts "ssh #{ssh_creds} useradd -d /home/#{new_user} -s /bin/bash -m #{new_user}\""
    system "ssh #{ssh_creds} useradd -d /home/#{new_user} -s /bin/bash -m #{new_user}\""
    puts "ssh #{ssh_creds} echo #{new_user}:#{password} | sudo chpasswd\""
    system "ssh #{ssh_creds} echo #{new_user}:#{password} | sudo chpasswd\""
    system "ssh #{ssh_creds} usermod -a -G admin #{new_user}\""
    system "ssh #{ssh_creds} mkdir /home/#{new_user}/.ssh\""
    for key in ssh_options[:keys]
      system "cat  #{key}.pub | ssh #{ssh_creds} cat >> /home/#{new_user}/.ssh/authorized_keys2\""
    end
    system "ssh #{ssh_creds} chown -R #{new_user}:#{new_user} /home/#{new_user}/.ssh\""
    #system "scp -i #{aws_private_key_path} config/deploy_sudoers #{superuser}@#{hostname}:/etc/sudoers"
    set :user, new_user<commit_msg>Permissions for deploy user worked out.<commit_after>#default_run_options[:pty] = true

#Relies on :password and :aws_private_key_path being set in the deployer .caprc file.

set :application, "rivulet"
set :repository,  "https://github.com/jplewicke/rivulet"

# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/var/www/#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
set :scm, :git

#role :app, "www.tryrivulet.com"
#role :web, "www.tryrivulet.com"
#role :db,  "www.tryrivulet.com", :primary => true

#set :application, "yyyyy.vamosa.com"
#set :domain, "yyyyy.vamosa.com"
set :ami_name, "ami-c9bc58a0"

#change to alestic maverick
set :ami_name, "ami-1a837773" 
#change to alestic lucid
#set :ami_name, "ami-a403f7cd"
set :image_type, "m1.small"



default_run_options[:pty] = false


namespace :ec2 do
  
  set :new_user, "deploy"
  
  set :superuser, "ubuntu"
  
  desc "Setup server"
  task :setup_server do
    create_ec2_server
    wait_spinup
    bootstrap_deploy_user
    #setup_env
    #shutdown_ami
    #test_sudo
  end
  
  desc "sudo_testing"
  task :test_sudo do
    #set :user, "ubuntu"
    
    #ssh_options[:keys] = aws_private_key_path
    puts user
    
    run "pwd"
  end
  
  desc "spinup a server"
  task :create_ec2_server do
    set :ami, `ec2-run-instances -k #{aws_private_key_name} -t #{image_type} #{ami_name} | awk '$1 ~ /INSTANCE/ {printf $2}'`
    puts ami
  end
  
  desc "wait for server to spinup and grab the host-name"
  task :wait_spinup do
    set :hostname, "pending"
    dly = 5.0
    
    while hostname == "pending" do
      sleep dly 
      set :hostname, `ec2-describe-instances #{ami} | awk '$1 ~ /INST/ {printf $4}'`
      dly *= 1.5
      
      
      
      puts hostname
    end
    
    server hostname, :web, :app, :db
    puts hostname
  end
  
  desc "uploads id_rsa.pub to the EC2 instance's deploy users authorized_keys2 file"
  task :bootstrap_deploy_user do
    #old_key_loc = ssh_options[:keys]
    #ssh_options[:keys] = aws_private_key_path
    sleep 10.0
    set :user, superuser
    puts user
    puts password
    
    #Add server to known hosts.
    ssh_creds = "-i #{aws_private_key_path} #{superuser}@#{hostname} \"sudo "
    
    puts "ssh -oStrictHostKeyChecking=no #{ssh_creds} pwd\""
    system  "ssh -oStrictHostKeyChecking=no #{ssh_creds} pwd\""
    system "ssh #{ssh_creds} groupadd admin\""
    
    puts "ssh #{ssh_creds} useradd -d /home/#{new_user} -s /bin/bash -m #{new_user}\""
    system "ssh #{ssh_creds} useradd -d /home/#{new_user} -s /bin/bash -m #{new_user}\""
    puts "ssh #{ssh_creds} echo #{new_user}:#{password} | sudo chpasswd\""
    system "ssh #{ssh_creds} echo #{new_user}:#{password} | sudo chpasswd\""
    system "ssh #{ssh_creds} usermod -a -G admin #{new_user}\""
    system "ssh #{ssh_creds} mkdir /home/#{new_user}/.ssh\""
    system "ssh #{ssh_creds} chown -R #{new_user}:#{new_user} /home/#{new_user}/.ssh\""
    system "ssh #{ssh_creds} chmod -R go+w /home/#{new_user}/.ssh\""
    for key in ssh_options[:keys]
      system "ssh #{ssh_creds} ls -haltr /home/#{new_user}/.ssh/{,authorized_keys}\""
      puts "cat  #{key}.pub | ssh #{ssh_creds} cat >> /home/#{new_user}/.ssh/authorized_keys\""
      system "cat  #{key}.pub | ssh #{ssh_creds} cat >> /home/#{new_user}/.ssh/authorized_keys\""
    end
        system "ssh #{ssh_creds} ls -haltr /home/#{new_user}/.ssh/{,authorized_keys}\""
    system "ssh #{ssh_creds} chmod 700 /home/#{new_user}/.ssh\""    
    system "ssh #{ssh_creds} chmod 600 /home/#{new_user}/.ssh/authorized_keys\""
    system "ssh #{ssh_creds} chown -R #{new_user}:#{new_user} /home/#{new_user}/.ssh\""
          system "ssh #{ssh_creds} ls -haltr /home/#{new_user}/.ssh/{,authorized_keys}\""
    #system "scp -i #{aws_private_key_path} config/deploy_sudoers #{superuser}@#{hostname}:/etc/sudoers"
    set :user, new_user
{'fraction_non_alphanumeric': 0.1424119241192412, 'fraction_numerical': 0.01016260162601626, 'mean_word_length': 3.341764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '299400', 'n_tokens_mistral': 2926, 'n_tokens_neox': 2798, 'n_words': 727}