#!/usr/bin/env ruby # frozen_string_literal: true require 'optparse' require 'rg_refresh' require 'yaml' opts = {} optparser = OptionParser.new do |cmd| cmd.banner = "usage: #$0 [options]" cmd.on('-c FILE', '--config=FILE', 'Configuration file') do |v| opts[:config_file] = v end end begin optparser.parse! rescue OptionParser::InvalidOption=>e $stderr.puts e abort optparser.help end abort optparser.help \ unless opts[:config_file] && ARGV.empty? config = YAML.load(File.read(opts[:config_file]), :symbolize_names=>true) begin puts 'Connecting...' $netgear = RgRefresh::Netgear.start(config.fetch(:netgear)) $rg = RgRefresh::PublishWrapper.new(config.fetch(:mqtt)) puts 'Affirming bypass mode (manually power RG *OFF* if necessary)...' $netgear.transition_to(:bypass) sleep 15 $rg.transition_to(:bypass) sleep 15 puts 'Transitioning to re-auth mode (manually power RG *ON* if necessary)...' $rg.transition_to(:reauth) $netgear.transition_to(:reauth) # point of no return puts 'Waiting for re-auth...' sleep 240 puts 'Transitioning to bypass mode (manually power RG *OFF* if necessary)...' $netgear.transition_to(:bypass) sleep 15 $rg.transition_to(:bypass) sleep 15 ensure puts 'Disconnecting...' $rg.finish $netgear.finish end