class Turnstyl::Client
Public Class Methods
home_folder()
click to toggle source
# File lib/turnstyl/client/client.rb, line 6 def self.home_folder Dir.home end
new()
click to toggle source
# File lib/turnstyl/client/client.rb, line 10 def initialize @config_path = File.expand_path(Client.home_folder+"/.turnstylrc") if config_file_missing? puts <<-TEXT Unable to run without a config file. Try something like this in ~/.turnstylrc userlist = [ "githubuser1", "githubuser2", "...", "githubuser99" ] TEXT exit 1 end end
Public Instance Methods
config_changed?()
click to toggle source
# File lib/turnstyl/client/client.rb, line 80 def config_changed? File.mtime(@config_path) > File.mtime(Client.home_folder+"/.ssh/authorized_keys") end
config_file_missing?()
click to toggle source
# File lib/turnstyl/client/client.rb, line 76 def config_file_missing? !File.exist? Client.home_folder+"/.turnstylrc" end
create_backup()
click to toggle source
# File lib/turnstyl/client/client.rb, line 88 def create_backup puts "\nMaking a backup ..." number = Dir.glob(Client.home_folder+'/.ssh/authorized_keys*').count puts number FileUtils.mv(Client.home_folder+"/.ssh/authorized_keys", Client.home_folder+"/.ssh/authorized_keys.bak"+number.to_s) end
run(force)
click to toggle source
# File lib/turnstyl/client/client.rb, line 26 def run(force) if force update_authorized_keys else update_authorized_keys_carefully end end
update_necessary?()
click to toggle source
# File lib/turnstyl/client/client.rb, line 84 def update_necessary? authorized_key_missing? || config_changed? end
Private Instance Methods
display_help()
click to toggle source
# File lib/turnstyl/client/client.rb, line 101 def display_help puts <<-HERE You tried to let turnstyl manage your authorized_keys file, but there is an existing authorized_keys file and you have to decide what you want to do with it. If you're sure you want to overwrite it choose "y" if you want to backup your existing file choose "b" HERE end
load_settings()
click to toggle source
# File lib/turnstyl/client/client.rb, line 97 def load_settings TOML.load_file(@config_path) end