Sha256: df332c1445b2a7ba965af847ca24f63a9edbc14c006d33a1ce38351037147dad

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

module GitWit::Actions::Ssh
  class Home < Thor::Actions::EmptyDirectory
    attr_reader :base, :user, :home

    def initialize(base, user, home, config = {})
      @base, @user, @home = base, user, File.expand_path(home)
      @config = {verbose: true}.merge config
    end

    def invoke!
      invoke_with_conflict_check do
        create
      end
    end

    def revoke!
      say_status :remove, :red
      destroy if !pretend? && exists?
      home
    end

    def exists?
      Dir.exists? home
    end

    protected
    def create
      old_destination = base.destination_root
      Dir.mktmpdir do |dir|
        base.destination_root = dir
        base.chmod ".", 0755
        base.inside "." do
          base.empty_directory ".ssh"
          base.chmod ".ssh", 0700
          base.inside ".ssh" do
            base.create_file "authorized_keys", ""
            base.chmod "authorized_keys", 0600
          end
          base.template "bashrc.tt", ".bashrc"
        end
        `sudo cp -R '#{dir}' '#{home}'`
        `sudo chown -R #{user}:#{user} '#{home}'`
      end
      base.destination_root = old_destination
    end

    def destroy
      `sudo rm -rf '#{home}'`
    end

    def relative_destination
      home
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
git_wit-0.0.6 lib/git_wit/actions/ssh/home.rb
git_wit-0.0.6.pre lib/git_wit/actions/ssh/home.rb
git_wit-0.0.5 lib/git_wit/actions/ssh/home.rb
git_wit-0.0.4.pre2 lib/git_wit/actions/ssh/home.rb
git_wit-0.0.4.pre lib/git_wit/actions/ssh/home.rb