#!/usr/pkg/bin/ruby40

require 'open-uri'
require 'pathname'
require 'certified'

CERT_BUNDLE_URL = 'https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt'

puts "Updating ca-bundle from #{CERT_BUNDLE_URL}"

cert_path = Pathname.new File.expand_path('../../certs', __FILE__)

open(CERT_BUNDLE_URL) do |remote_file|
  File.open(cert_path + 'ca-bundle.crt', 'w+') do |cert_file|
    remote_file.each_line do |line|
      cert_file << line
    end
  end
end

puts "Certificate bundle updated. Remember to do this regularly!"
