<commit_before>#!/usr/bin/env ruby

require 'json'
require 'mrdialog'
require 'yaml'

require File.join(ENV['RBDIR'].nil? ? '/usr/lib/redborder' : ENV['RBDIR'],'lib/rb_wiz_lib')

RBETC = ENV['RBETC'].nil? ? '/etc/redborder' : ENV['RBETC']

CONFFILE = "#{RBETC}/rb_init_conf.yml"
DIALOGRC = "#{RBETC}/dialogrc"
if File.exist?(DIALOGRC)
    ENV['DIALOGRC'] = DIALOGRC
end

puts "\033]0;redborder - setup wizard\007"

general_conf = {
    "hostname" => "",
    "cdomain" => "",
    "cloud" => false, 
    "network" => {
        "interfaces" => [],
        "dns" => []
        },
    "serf" => {
        "multicast" => true,
        "sync_net" => "",
        "encrypt_key" => ""
        },
    "mode" => "full" # default mode
    }

# general_conf will dump its contents as yaml conf into rb_init_conf.yml

# TODO: intro to the wizard, define color set, etc.


def cancel_wizard() 

    dialog = MRDialog.new
    dialog.clear = true
    dialog.title = "SETUP wizard cancelled"

    text = <<EOF
The setup has been cancelled or stopped.

If you want to complete the setup wizard, please execute it again.

EOF
    result = dialog.msgbox(text, 10, 41)
    exit(1)

end

# Conf for network

#text = <<EOF
#Do you want to configure network in your system?
#
#EOF

#dialog = MRDialog.new
#dialog.clear = true
#dialog.title = "CONFIGURE NETWORK"
#yesno = dialog.yesno(text,0,0)

#if yesno # yesno is "yes" -> true
    # configure network
    netconf = NetConf.new
    netconf.doit # launch wizard
    cancel_wizard if netconf.cancel
    general_conf["network"]["interfaces"] = netconf.conf
#else
#    cancel_wizard
#end

# Conf for hostname

# configure hostname and domain name
hostconf = HostConf.new
hostconf.doit # launch wizard
cancel_wizard if hostconf.cancel
general_conf["hostname"] = hostconf.conf[:hostname]
general_conf["cdomain"] = hostconf.conf[:domainname]

# Conf for DNS

# configure dns and hostname
dnsconf = DNSConf.new
dnsconf.doit # launch wizard
cancel_wizard if dnsconf.cancel
general_conf["network"]["dns"] = dnsconf.conf

text = <<EOF
 
Next, you must configure settings for serf service.

Serf service is the service that create the cluster
and coordinate nodes between them, interchange certificates
and decide which will be the first master in the cluster
formation.

You will need to provide three parameters for this configuration:
the synchronism network, the unicast/multicast mode and
a secret key for encryption of serf network traffic.
 
EOF

dialog = MRDialog.new
dialog.clear = true
dialog.title = "Configure Cluster Service (Serf)"
dialog.msgbox(text,0, 0)

# Conf synchronization network

syncconf = SerfSyncConf.new
syncconf.doit # launch wizard
cancel_wizard if syncconf.cancel
general_conf["serf"]["sync_net"] = syncconf.conf

# Select multicast or unicast

mcastconf = SerfMcastConf.new
mcastconf.doit # launch wizard
cancel_wizard if mcastconf.cancel
general_conf["serf"]["multicast"] = mcastconf.conf

# Password for serf

cryptconf = SerfCryptConf.new
cryptconf.doit # launch wizard
cancel_wizard if cryptconf.cancel
general_conf["serf"]["encrypt_key"] = cryptconf.conf

File.open(CONFFILE, 'w') {|f| f.write general_conf.to_yaml } #Store

## vim:ts=4:sw=4:expandtab:ai:nowrap:formatoptions=croqln:
<commit_msg>fix env vars use<commit_after>#!/usr/bin/env ruby

require 'json'
require 'mrdialog'
require 'yaml'
require "#{ENV['RBLIB']}/rb_wiz_lib"

CONFFILE = "#{ENV['RBETC']}/rb_init_conf.yml"
DIALOGRC = "#{ENV['RBETC']}/dialogrc"
if File.exist?(DIALOGRC)
    ENV['DIALOGRC'] = DIALOGRC
end

puts "\033]0;redborder - setup wizard\007"

general_conf = {
    "hostname" => "",
    "cdomain" => "",
    "cloud" => false, 
    "network" => {
        "interfaces" => [],
        "dns" => []
        },
    "serf" => {
        "multicast" => true,
        "sync_net" => "",
        "encrypt_key" => ""
        },
    "mode" => "full" # default mode
    }

# general_conf will dump its contents as yaml conf into rb_init_conf.yml

# TODO: intro to the wizard, define color set, etc.


def cancel_wizard() 

    dialog = MRDialog.new
    dialog.clear = true
    dialog.title = "SETUP wizard cancelled"

    text = <<EOF
The setup has been cancelled or stopped.

If you want to complete the setup wizard, please execute it again.

EOF
    result = dialog.msgbox(text, 10, 41)
    exit(1)

end

# Conf for network

#text = <<EOF
#Do you want to configure network in your system?
#
#EOF

#dialog = MRDialog.new
#dialog.clear = true
#dialog.title = "CONFIGURE NETWORK"
#yesno = dialog.yesno(text,0,0)

#if yesno # yesno is "yes" -> true
    # configure network
    netconf = NetConf.new
    netconf.doit # launch wizard
    cancel_wizard if netconf.cancel
    general_conf["network"]["interfaces"] = netconf.conf
#else
#    cancel_wizard
#end

# Conf for hostname

# configure hostname and domain name
hostconf = HostConf.new
hostconf.doit # launch wizard
cancel_wizard if hostconf.cancel
general_conf["hostname"] = hostconf.conf[:hostname]
general_conf["cdomain"] = hostconf.conf[:domainname]

# Conf for DNS

# configure dns and hostname
dnsconf = DNSConf.new
dnsconf.doit # launch wizard
cancel_wizard if dnsconf.cancel
general_conf["network"]["dns"] = dnsconf.conf

text = <<EOF
 
Next, you must configure settings for serf service.

Serf service is the service that create the cluster
and coordinate nodes between them, interchange certificates
and decide which will be the first master in the cluster
formation.

You will need to provide three parameters for this configuration:
the synchronism network, the unicast/multicast mode and
a secret key for encryption of serf network traffic.
 
EOF

dialog = MRDialog.new
dialog.clear = true
dialog.title = "Configure Cluster Service (Serf)"
dialog.msgbox(text,0, 0)

# Conf synchronization network

syncconf = SerfSyncConf.new
syncconf.doit # launch wizard
cancel_wizard if syncconf.cancel
general_conf["serf"]["sync_net"] = syncconf.conf

# Select multicast or unicast

mcastconf = SerfMcastConf.new
mcastconf.doit # launch wizard
cancel_wizard if mcastconf.cancel
general_conf["serf"]["multicast"] = mcastconf.conf

# Password for serf

cryptconf = SerfCryptConf.new
cryptconf.doit # launch wizard
cancel_wizard if cryptconf.cancel
general_conf["serf"]["encrypt_key"] = cryptconf.conf

File.open(CONFFILE, 'w') {|f| f.write general_conf.to_yaml } #Store

# TODO: execute rb_init_conf.sh into a progress dialog

#exec("#{ENV['RBBIN']}/rb_init_conf.sh")

## vim:ts=4:sw=4:expandtab:ai:nowrap:formatoptions=croqln:

{'fraction_non_alphanumeric': 0.11737523105360444, 'fraction_numerical': 0.005545286506469501, 'mean_word_length': 4.1166272655634355, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4310928', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2217, 'n_words': 621}