Skip to content

Commit

Permalink
#1 id_rsa key
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 9, 2016
1 parent 0bbe78b commit a9b81d5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
4 changes: 0 additions & 4 deletions 0pdd.rb
Expand Up @@ -24,14 +24,10 @@
require 'sinatra'
require 'sass'
require 'haml'
require 'yaml'

require_relative 'version'
require_relative 'objects/git_repo'

# cfg = File.join(File.dirname(__FILE__), 'config.yml')
# config = File.exist?(cfg) ? YAML.load(File.open(cfg)) : {}

get '/' do
haml :index, layout: :layout
end
Expand Down
33 changes: 33 additions & 0 deletions objects/config.rb
@@ -0,0 +1,33 @@
# encoding: utf-8
#
# Copyright (c) 2016 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'yaml'

#
# Config.
#
class Config
def yaml
cfg = File.join(File.dirname(__FILE__), '../config.yml')
File.exist?(cfg) ? YAML.load(File.open(cfg)) : {}
end
end
1 change: 0 additions & 1 deletion objects/exec.rb
Expand Up @@ -31,7 +31,6 @@ def initialize(arg, *rest)
end

def run
puts @cmd
`#{@cmd}`
status = $CHILD_STATUS.to_i
raise "Exit code (#{status}) is not zero" unless status.zero?
Expand Down
15 changes: 9 additions & 6 deletions objects/git_repo.rb
Expand Up @@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fileutils'
require_relative 'config'
require_relative 'exec'

#
Expand All @@ -32,6 +34,7 @@ def initialize(name:, dir: '/tmp/0pdd')
end

def push
prepare
if File.exist?(@path)
pull
else
Expand All @@ -41,7 +44,6 @@ def push

def clone
Exec.new(
preamble,
'git clone',
'--depth=1',
"git@github.com:#{@name}",
Expand All @@ -51,22 +53,23 @@ def clone

def pull
Exec.new(
preamble,
'git',
"--git-dir=#{@path}/.git",
'pull'
).run
end

def preamble
[
def prepare
FileUtils.mkdir_p '~/.ssh'
priv = '~/.ssh/id_rsa'
IO.write(priv, Config.new.yaml['id_rsa']) unless File.exist?(priv)
Exec.new(
'set -x',
'set -e',
'mkdir -p ~/.ssh',
'echo "Host *" > ~/.ssh/config',
'echo " StrictHostKeyChecking no" >> ~/.ssh/config',
'echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config',
'chmod -R 600 ~/.ssh/*'
].join('; ') + ';'
)
end
end
Empty file added ~/.ssh/id_rsa
Empty file.

0 comments on commit a9b81d5

Please sign in to comment.