class LetsencryptWebfaction::Application::Init

Public Class Methods

new(_) click to toggle source
# File lib/letsencrypt_webfaction/application/init.rb, line 12
def initialize(_); end

Public Instance Methods

run!() click to toggle source
# File lib/letsencrypt_webfaction/application/init.rb, line 14
def run!
  copy_config_file
  create_private_key
  output_next_steps
  # TODO: Create crontab entry
  # TODO: Make sure that configuration file has a "this has been configured" flag
  # TODO: Add a bash binary type thingy
  # TODO: Add an installer command?
end

Private Instance Methods

copy_config_file() click to toggle source
# File lib/letsencrypt_webfaction/application/init.rb, line 26
def copy_config_file
  source = File.expand_path(File.join(__dir__, '../../../templates/letsencrypt_webfaction.toml'))
  if Options.default_options_path.exist?
    puts 'Config file already exists. Skipping copy...'
  else
    FileUtils.cp(source, Dir.home)
    File.chmod(0o600, File.join(Dir.home, 'letsencrypt_webfaction.toml'))
    puts 'Copied configuration file'
  end
end
create_private_key() click to toggle source
# File lib/letsencrypt_webfaction/application/init.rb, line 37
def create_private_key
  # Create config dir.
  FileUtils.mkdir_p(Options.default_config_path)

  key_path = Options.default_config_path.join('account_key.pem')
  if key_path.exist?
    puts 'Account private key already exists. Skipping generation...'
  else
    # Create private key
    # TODO: Make key size configurable.
    private_key = OpenSSL::PKey::RSA.new(4096)
    Options.default_config_path.join('account_key.pem').write(private_key.to_pem)
    puts 'Generated and stored account private key'
  end
end
output_next_steps() click to toggle source
# File lib/letsencrypt_webfaction/application/init.rb, line 53
def output_next_steps
  puts 'Your system is set up. Next, edit the config file: run `nano ~/letsencrypt_webfaction.toml`.'
end