<commit_before>#!/bin/bash

function set_if_conf {
    echo
    echo -n "Should we use DHCP for that interface (Y/n)?";read -n 1 dhcpsw
    if [[ $dhcpsw == "n" || $dhcpsw == "N" ]]; then
        echo
        echo -n "Enter ip: "; read ${intf}_ip;
        echo -n "Enter netmask: "; read ${intf}_mask
        echo -n "Enter default gw: "; read ${intf}_gw
        echo -n "Enter First DNS server: "; read ${intf}_dns1
        echo -n "Enter Second DNS server: "; read ${intf}_dns2
    else
        eval ${intf}_ip="";eval ${intf}_mask="";eval ${intf}_gw="";eval ${intf}_dns1="";eval ${intf}_dns2=""
    fi
    echo
}

function save_if_cfg {
    scrFile="/etc/sysconfig/network-scripts/ifcfg-$device"
    hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
    [ -z $gw ] || echo GATEWAY=$gw >> /etc/sysconfig/network
    echo DEVICE=$device > $scrFile
    echo ONBOOT=yes >> $scrFile
    echo NM_CONTROLLED=no >> $scrFile
    echo HWADDR=$hwaddr >> $scrFile
    echo USERCTL=no >> $scrFile
    if [ $ip ]; then
        echo BOOTPROTO=static >> $scrFile
        echo IPADDR=$ip >> $scrFile
        echo NETMASK=$netmask >> $scrFile
        [ $dns1 ] && echo DNS1=$dns1 >> $scrFile
        [ $dns2 ] && echo DNS2=$dns2 >> $scrFile
    else
        echo BOOTPROTO=dhcp >> $scrFile
    fi
}

function default_settings {
    hostname="fuel-pm"
    domain="local"
    mgmt_if="eth0"
    mgmt_ip="10.0.0.100"
    mgmt_mask="255.255.0.0"
    ext_if="eth1"
    dhcp_start_address="10.0.0.201"
    dhcp_end_address="10.0.0.254"
    mirror_type="default"
}

function apply_settings {
    echo;echo "Applying settings ..."

# Network interfaces settings apply
    for iftype in ext mgmt
    do
        eval device=\$${iftype}_if
        eval ip=\$${iftype}_ip
        eval netmask=\$${iftype}_mask
        eval gw=\$${iftype}_gw
        eval dns1=\$${iftype}_dns1
        eval dns2=\$${iftype}_dns2
        hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
        save_if_cfg
    done

# Cobbler settings apply
    : ${server:=$mgmt_ip}
    : ${domain_name=$domain}
    : ${name_server=$mgmt_ip}
    : ${next_server=$mgmt_ip}
    : ${dhcp_netmask=$mgmt_mask}
    : ${dhcp_gateway=$mgmt_ip}
    : ${cobbler_user="cobbler"}
    : ${cobbler_password="<PASSWORD>"}
    : ${pxetimeout="0"}
    : ${dhcp_interface=$mgmt_if}

# Domain/Hostname apply
    sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname.$domain"'#' /etc/sysconfig/network
    rm -f /var/lib/puppet/ssl/ca/signed/*
    [ -n "$mgmt_ip" -a -n "$ext_ip" ] && sed -i '/nameserver/d' /etc/resolv.conf && echo "nameserver 127.0.0.1;" >> /etc/resolv.conf
    [ -z "$mgmt_ip" ] && echo "prepend domain-name-servers 127.0.0.1;" >> /etc/dhclient-$mgmt_if.conf
    [ -z "$ext_ip" ] && echo "prepend domain-name-servers 127.0.0.1;" >> /etc/dhclient-$ext_if.conf
    [ -z "$mgmt_ip" ] || grep -Eq "^\s*$mgmt_ip\s+$hostname" /etc/hosts || sed -i "/$mgmt_ip/d" /etc/hosts && echo "$mgmt_ip    $hostname.$domain $hostname" >> /etc/hosts
    sed -i '/kernel.hostname/d' /etc/sysctl.conf && echo "kernel.hostname=$hostname" >> /etc/sysctl.conf
    sed -i '/kernel.domainname/d' /etc/sysctl.conf && echo "kernel.domainname=$domain" >> /etc/sysctl.conf
    sed -i '/server/d' /etc/puppet/puppetdb.conf && echo "server = $hostname.$domain" >> /etc/puppet/puppetdb.conf
    service network restart
    service puppetdb restart
    sed -i "s%\(^.*address is:\).*$%\1 `ip address show $ext_if | awk '/inet / {print \$2}' | cut -d/ -f1 -`%" /etc/issue
}

function show_top {
clear
echo "Domain: $domain"
echo "Hostname: $hostname"
echo "PXE range: $dhcp_start_address - $dhcp_end_address"
echo "Mirror set to use: $mirror_type"<commit_msg>[FUEL-582] Added dnsmasq restart after domain change<commit_after>#!/bin/bash

function set_if_conf {
    echo
    echo -n "Should we use DHCP for that interface (Y/n)?";read -n 1 dhcpsw
    if [[ $dhcpsw == "n" || $dhcpsw == "N" ]]; then
        echo
        echo -n "Enter ip: "; read ${intf}_ip;
        echo -n "Enter netmask: "; read ${intf}_mask
        echo -n "Enter default gw: "; read ${intf}_gw
        echo -n "Enter First DNS server: "; read ${intf}_dns1
        echo -n "Enter Second DNS server: "; read ${intf}_dns2
    else
        eval ${intf}_ip="";eval ${intf}_mask="";eval ${intf}_gw="";eval ${intf}_dns1="";eval ${intf}_dns2=""
    fi
    echo
}

function save_if_cfg {
    scrFile="/etc/sysconfig/network-scripts/ifcfg-$device"
    hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
    [ -z $gw ] || echo GATEWAY=$gw >> /etc/sysconfig/network
    echo DEVICE=$device > $scrFile
    echo ONBOOT=yes >> $scrFile
    echo NM_CONTROLLED=no >> $scrFile
    echo HWADDR=$hwaddr >> $scrFile
    echo USERCTL=no >> $scrFile
    if [ $ip ]; then
        echo BOOTPROTO=static >> $scrFile
        echo IPADDR=$ip >> $scrFile
        echo NETMASK=$netmask >> $scrFile
        [ $dns1 ] && echo DNS1=$dns1 >> $scrFile
        [ $dns2 ] && echo DNS2=$dns2 >> $scrFile
    else
        echo BOOTPROTO=dhcp >> $scrFile
    fi
}

function default_settings {
    hostname="fuel-pm"
    domain="local"
    mgmt_if="eth0"
    mgmt_ip="10.0.0.100"
    mgmt_mask="255.255.0.0"
    ext_if="eth1"
    dhcp_start_address="10.0.0.201"
    dhcp_end_address="10.0.0.254"
    mirror_type="default"
}

function apply_settings {
    echo;echo "Applying settings ..."

# Network interfaces settings apply
    for iftype in ext mgmt
    do
        eval device=\$${iftype}_if
        eval ip=\$${iftype}_ip
        eval netmask=\$${iftype}_mask
        eval gw=\$${iftype}_gw
        eval dns1=\$${iftype}_dns1
        eval dns2=\$${iftype}_dns2
        hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
        save_if_cfg
    done

# Cobbler settings apply
    : ${server:=$mgmt_ip}
    : ${domain_name=$domain}
    : ${name_server=$mgmt_ip}
    : ${next_server=$mgmt_ip}
    : ${dhcp_netmask=$mgmt_mask}
    : ${dhcp_gateway=$mgmt_ip}
    : ${cobbler_user="cobbler"}
    : ${cobbler_password="<PASSWORD>"}
    : ${pxetimeout="0"}
    : ${dhcp_interface=$mgmt_if}

# Domain/Hostname apply
    sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname.$domain"'#' /etc/sysconfig/network
    rm -f /var/lib/puppet/ssl/ca/signed/*
    [ -n "$mgmt_ip" -a -n "$ext_ip" ] && sed -i '/nameserver/d' /etc/resolv.conf && echo "nameserver 127.0.0.1;" >> /etc/resolv.conf
    [ -z "$mgmt_ip" ] && echo "prepend domain-name-servers 127.0.0.1;" >> /etc/dhclient-$mgmt_if.conf
    [ -z "$ext_ip" ] && echo "prepend domain-name-servers 127.0.0.1;" >> /etc/dhclient-$ext_if.conf
    [ -z "$mgmt_ip" ] || grep -Eq "^\s*$mgmt_ip\s+$hostname" /etc/hosts || sed -i "/$mgmt_ip/d" /etc/hosts && echo "$mgmt_ip    $hostname.$domain $hostname" >> /etc/hosts
    sed -i '/kernel.hostname/d' /etc/sysctl.conf && echo "kernel.hostname=$hostname" >> /etc/sysctl.conf
    sed -i '/kernel.domainname/d' /etc/sysctl.conf && echo "kernel.domainname=$domain" >> /etc/sysctl.conf
    sed -i '/server/d' /etc/puppet/puppetdb.conf && echo "server = $hostname.$domain" >> /etc/puppet/puppetdb.conf
    service network restart
    service dnsmasq restart
    service puppetdb restart
    sed -i "s%\(^.*address is:\).*$%\1 `ip address show $ext_if | awk '/inet / {print \$2}' | cut -d/ -f1 -`%" /etc/issue
}

function show_top {
clear
echo "Domain: $domain"
echo "Hostname: $hostname"
echo "PXE range: $dhcp_start_address - $dhcp_end_address"
echo "Mirror set to use: $mirror_type"
{'fraction_non_alphanumeric': 0.1817575676756901, 'fraction_numerical': 0.018802507000933458, 'mean_word_length': 2.9411455596426697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, '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': '6564371', 'n_tokens_mistral': 2993, 'n_tokens_neox': 2886, 'n_words': 610}