Sha256: f30c262c0f1e6f9b3fb958e48455d4609b08c508d88d93050be782f5b5b43326

Contents?: true

Size: 1.04 KB

Versions: 29

Compression:

Stored size: 1.04 KB

Contents

class Bard < Thor
  desc "install-authorized-keys", "!!! INTERNAL USE ONLY !!! run as sudo"
  def install_authorized_keys(source_user, dest_user)
    source = "/home/#{source_user}/.ssh/authorized_keys"
    dest = "/home/#{dest_user}/.ssh/authorized_keys"

    file = File.read(source)
    file.gsub! /gitosis-serve/, "bard delegate"

    File.open(dest, "w") { |f| f.write(file) }
  end

  desc "delegate", "!!! INTERNAL USER ONLY !!!"
  def delegate(key)
    command = ENV['SSH_ORIGINAL_COMMAND']

    case command
    when /^scp -f (\w+)\.sql\.gz$/
      project = $1
      `#{command_for("staging", "cd #{project} && rake db:dump RAILS_ENV=staging && gzip -9f db/data.sql")}`
      command = "scp -f ~/#{project}/db/data.sql.gz"
    end

    exec command_for("staging", command)
  end

  private
    def command_for(user, command)
      %(sudo -H -u #{user} sh -c "cd ~ && #{command}")
    end

    def run_crucial_via_bard(command)
      return if ENV['TESTING']
      run_crucial %(ssh bard@bard.botandrose.com "cd #{project_name} && #{command}")
    end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
bard-0.8.18 lib/bard/ssh_delegation.rb
bard-0.8.17 lib/bard/ssh_delegation.rb
bard-0.8.16 lib/bard/ssh_delegation.rb
bard-0.8.15 lib/bard/ssh_delegation.rb
bard-0.8.14 lib/bard/ssh_delegation.rb
bard-0.8.13 lib/bard/ssh_delegation.rb
bard-0.8.12 lib/bard/ssh_delegation.rb
bard-0.8.11 lib/bard/ssh_delegation.rb
bard-0.8.10 lib/bard/ssh_delegation.rb
bard-0.8.9 lib/bard/ssh_delegation.rb
bard-0.8.8 lib/bard/ssh_delegation.rb
bard-0.8.7 lib/bard/ssh_delegation.rb
bard-0.8.6 lib/bard/ssh_delegation.rb
bard-0.8.5 lib/bard/ssh_delegation.rb
bard-0.8.4 lib/bard/ssh_delegation.rb
bard-0.8.3 lib/bard/ssh_delegation.rb
bard-0.8.2 lib/bard/ssh_delegation.rb
bard-0.8.1 lib/bard/ssh_delegation.rb
bard-0.8.0 lib/bard/ssh_delegation.rb
bard-0.7.9 lib/bard/ssh_delegation.rb