added network module
This commit is contained in:
@@ -65,6 +65,32 @@ CALCLEVEL=""
|
||||
# Doit on forcer l'effacement du disque ?
|
||||
FORCEBLANK=false
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ------------------------------ Section réseau --------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
IPV4_IFACES="eth0 eth1 eth2"
|
||||
|
||||
NET4_MODE_eth0="static"
|
||||
NET4_IP_eth0="192.168.1.221/24"
|
||||
NET4_GW_eth0="192.168.1.231"
|
||||
NET4_NS_eth0="192.168.1.206 192.168.1.205"
|
||||
NET4_NS_SEARCH_eth0=$REALM
|
||||
|
||||
NET4_MODE_eth1="static"
|
||||
NET4_IP_eth1="192.168.1.221/24"
|
||||
|
||||
NET4_MODE_eth2="static"
|
||||
NET4_IP_eth2="10.0.254.221/16"
|
||||
|
||||
NET6_MODE_eth0="static"
|
||||
NET6_IP_eth0="2a03:7220:8081:b401::dd/64"
|
||||
NET6_GW_eth0="2a03:7220:8081:b401::e7"
|
||||
NET6_NS_eth0="2a03:7220:8081:b401::ce 2a03:7220:8081:b301::cd"
|
||||
NET6_NS_SEARCH_eth0=$REALM
|
||||
|
||||
NET6_MODE_eth1="static"
|
||||
NET6_IP_eth1="2a03:7220:8081:b34a::dd/64"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ------------------------- Section machine virtuelle --------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
159
modules/conf_network.sh
Normal file
159
modules/conf_network.sh
Normal file
@@ -0,0 +1,159 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Configure network
|
||||
# This file is part of the init.sh project
|
||||
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# ------------------------------------------------------------------------------
|
||||
# This file is distributed under 3-clause BSD license.
|
||||
# The complete license agreement can be obtained at:
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
# ------------------------------------------------------------------------------
|
||||
# Variables:
|
||||
# * IPV4_IFACES: list of the interfaces with IPv4 configuration
|
||||
# * IPV6_IFACES: list of the interfaces with IPv6 configuration
|
||||
# * NET{4,6}_MODE_$iface: mode of configuration for $iface: static, manual or dhcp
|
||||
# - In static mode only:
|
||||
# * NET{4,6}_IP_$iface: IP address of the interface $iface
|
||||
# * NET{4,6}_GW_$iface: Gateway of the interface $iface
|
||||
# * NET{4,6}_NS_$iface: Name servers of the interface $iface
|
||||
# * NET{4,6}_NS_SEARCH_$iface: Domain name research the interface $iface
|
||||
# - In manual mode only
|
||||
# * NET{4,6}_MANUAL_FILE_$iface: filename for manual configuration of $iface
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
export VER_conf_syslog="0.0.1"
|
||||
|
||||
conf_network()
|
||||
{
|
||||
local if_file="/etc/network/interfaces"
|
||||
backup_dist $if_file
|
||||
|
||||
# The interfaces header contain loopback interface declaration
|
||||
install_file interfaces.head $if_file
|
||||
|
||||
# First configure IPv4 ifaces
|
||||
local iface=
|
||||
for iface in $IPV4_IFACES; then
|
||||
echo -e "\n# --------------------------------\n" >> $if_file
|
||||
if [[ $(eval echo \$NET4_MODE_$iface) == manual ]]; then
|
||||
prnt I "Configuring IPv4 network interface $iface in static mode..."
|
||||
echo "auto $iface" >> $if_file
|
||||
echo "iface $iface inet static" >> $if_file
|
||||
echo -e "\taddress $(eval echo \$NET4_IP_$iface)" >> $if_file
|
||||
if [[ -n $(eval echo \$NET4_GW_$iface) ]]; then
|
||||
echo -e "\tgateway $(eval echo \$NET4_GW_$iface)" >> $if_file
|
||||
fi
|
||||
if [[ -n $(eval echo \$NET4_NS_$iface) ]]; then
|
||||
echo -e "\tdns_nameservers $(eval echo \$NET4_NS_$iface)" >> $if_file
|
||||
fi
|
||||
if [[ -n $(eval echo \$NET4_NS_SEARCH_$iface) ]]; then
|
||||
echo -e "\tdns_search $(eval echo \$NET4_NS_SEARCH_$iface)" >> $if_file
|
||||
fi
|
||||
elif [[ $(eval echo \$NET4_MODE_$iface) == dhcp ]]
|
||||
prnt I "Configuring IPv4 network interface $iface in DHCP mode..."
|
||||
echo "auto $iface" >> $if_file
|
||||
echo "iface $iface inet dhcp" >> $if_file
|
||||
elif [[ $(eval echo \$NET4_MODE_$iface) == manual ]]; then
|
||||
local fname=$(eval echo \$NET4_MANUAL_FILE_$iface)
|
||||
appendfile $fname $if_file
|
||||
unset fname
|
||||
fi
|
||||
done
|
||||
|
||||
for iface in $IPV6_IFACES; then
|
||||
echo -e "\n# --------------------------------\n" >> $if_file
|
||||
if [[ $(eval echo \$NET6_MODE_$iface) == manual ]]; then
|
||||
prnt I "Configuring IPv6 network interface $iface in static mode..."
|
||||
echo "auto $iface" >> $if_file
|
||||
echo "iface $iface inet6 static" >> $if_file
|
||||
echo -e "\taddress $(eval echo \$NET6_IP_$iface)" >> $if_file
|
||||
if [[ -n $(eval echo \$NET6_GW_$iface) ]]; then
|
||||
echo -e "\tgateway $(eval echo \$NET6_GW_$iface)" >> $if_file
|
||||
fi
|
||||
if [[ -n $(eval echo \$NET6_NS_$iface) ]]; then
|
||||
echo -e "\tdns_nameservers $(eval echo \$NET6_NS_$iface)" >> $if_file
|
||||
fi
|
||||
if [[ -n $(eval echo \$NET6_NS_SEARCH_$iface) ]]; then
|
||||
echo -e "\tdns_search $(eval echo \$NET6_NS_SEARCH_$iface)" >> $if_file
|
||||
fi
|
||||
elif [[ $(eval echo \$NET6_MODE_$iface) == dhcp ]]
|
||||
prnt I "Configuring IPv6 network interface $iface in DHCP mode..."
|
||||
echo "auto $iface" >> $if_file
|
||||
echo "iface $iface inet6 dhcp" >> $if_file
|
||||
fi
|
||||
elif [[ $(eval echo \$NET6_MODE_$iface) == manual ]]; then
|
||||
local fname=$(eval echo \$NET6_MANUAL_FILE_$iface)
|
||||
appendfile $fname $if_file
|
||||
unset fname
|
||||
fi
|
||||
done
|
||||
|
||||
unset iface if_file
|
||||
}
|
||||
|
||||
precheck_conf_network()
|
||||
{
|
||||
file_exists interfaces.head
|
||||
if [[ -z $IPV4_IFACES ]]; then
|
||||
prnt W "No IPv4 interfaces to configure."
|
||||
else
|
||||
for iface in $IPV4_IFACES; do
|
||||
if [[ -z $(eval echo \$NET4_MODE_$iface) ]]; then
|
||||
prnt E "Interfaces $iface have no mode set!"
|
||||
else
|
||||
case $(eval echo \$NET4_MODE_$iface) in
|
||||
"static")
|
||||
if [[ -z $(eval echo \$NET4_IP_$iface) ]]; then
|
||||
prnt E "No IPv4 have been assigned to static interface $iface!"
|
||||
fi
|
||||
prnt I "Interface $iface will have $(eval echo \$NET4_IP_$iface) static IPv4 address."
|
||||
;;
|
||||
"dhcp")
|
||||
prnt I "Interface $iface will use DHCP."
|
||||
;;
|
||||
"manual")
|
||||
file_exists $(eval echo \$NET4_MANUAL_FILE_$iface)
|
||||
prnt I "Interface $iface will use manual IPv4 configuration in a file."
|
||||
;;
|
||||
*)
|
||||
prnt E "Interfaces mode \"$(eval echo \$NET4_MODE_$iface)\" unsuported!"
|
||||
die 175
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [[ -z $IPV4_IFACES ]]; then
|
||||
prnt W "No IPv6 interfaces to configure."
|
||||
else
|
||||
for iface in $IPV6_IFACES; do
|
||||
if [[ -z $(eval echo \$NET6_MODE_$iface) ]]; then
|
||||
prnt E "Interfaces $iface have no mode set!"
|
||||
else
|
||||
case $(eval echo \$NET6_MODE_$iface) in
|
||||
"static")
|
||||
if [[ -z $(eval echo \$NET6_IP_$iface) ]]; then
|
||||
prnt E "No IPv6 have been assigned to static interface $iface!"
|
||||
fi
|
||||
prnt I "Interface $iface will have $(eval echo \$NET6_IP_$iface) static IPv6 address."
|
||||
;;
|
||||
"dhcp")
|
||||
prnt I "Interface $iface will use DHCPv6."
|
||||
;;
|
||||
"manual")
|
||||
file_exists $(eval echo \$NET6_MANUAL_FILE_$iface)
|
||||
prnt I "Interface $iface will use manual IPv6 configuration in a file."
|
||||
;;
|
||||
*)
|
||||
prnt E "Interfaces mode \"$(eval echo \$NET6_MODE_$iface)\" unsuported!"
|
||||
die 175
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
export -f conf_network
|
||||
export -f precheck_conf_network
|
||||
|
||||
# EOF
|
||||
8
repo/common/interfaces.head
Normal file
8
repo/common/interfaces.head
Normal file
@@ -0,0 +1,8 @@
|
||||
# This file describes the network interfaces available on your system
|
||||
# and how to activate them. For more information, see interfaces(5).
|
||||
|
||||
source /etc/network/interfaces.d/*
|
||||
|
||||
# The loopback network interface
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
Reference in New Issue
Block a user