F #227: Refactor loc-10-network

Deprecate EC2
Introduce one-context-online service
Support NetPlan, NetworkManager
Various fixes
DHCP WIP
pull/244/head
Petr Ospalý 3 years ago committed by GitHub
parent 688c04e14c
commit 914ceae299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,8 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# shellcheck disable=SC1091
if [ -z "${TARGET}" ]; then if [ -z "${TARGET}" ]; then
echo 'Error: env. variable TARGET not set' >&2 echo 'Error: env. variable TARGET not set' >&2
exit 1 exit 1
@ -28,7 +30,7 @@ set +e
### ###
if [ -z "${RELEASE}" ]; then if [ -z "${RELEASE}" ]; then
if git describe --contains $(git rev-parse HEAD) &>/dev/null; then if git describe --contains "$(git rev-parse HEAD)" &>/dev/null; then
RELEASE=1 RELEASE=1
else else
DATE=${DATE:-$(date +%Y%m%d)} DATE=${DATE:-$(date +%Y%m%d)}
@ -90,12 +92,14 @@ _PREUN=$(mktemp)
_POSTUN=$(mktemp) _POSTUN=$(mktemp)
_POSTUP=$(mktemp) _POSTUP=$(mktemp)
# shellcheck disable=SC2064
trap "rm -rf ${UNAME_PATH} ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT trap "rm -rf ${UNAME_PATH} ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT
while IFS= read -r -d $'\0' SRC; do while IFS= read -r -d $'\0' SRC; do
F_TAGS=${SRC##*##} F_TAGS=${SRC##*##}
if [ "x${SRC}" != "x${F_TAGS}" ]; then if [ "x${SRC}" != "x${F_TAGS}" ]; then
for F_TAG in $(echo ${F_TAGS} | sed -e 's/\./ /g'); do # shellcheck disable=SC2001
for F_TAG in $(echo "${F_TAGS}" | sed -e 's/\./ /g'); do
for TAG in ${TAGS}; do for TAG in ${TAGS}; do
if [ "${F_TAG}" = "${TAG}" ]; then if [ "${F_TAG}" = "${TAG}" ]; then
continue 2 # tag matches, continue with next tag continue 2 # tag matches, continue with next tag
@ -111,7 +115,7 @@ while IFS= read -r -d $'\0' SRC; do
cp "src/${SRC}" "${BUILD_DIR}/${DST}" cp "src/${SRC}" "${BUILD_DIR}/${DST}"
done < <(cd src/ && find . -type f -print0) done < <(cd src/ && find . -type f -print0)
for F in $@; do for F in "$@"; do
cp -r "$F" "${BUILD_DIR}/" cp -r "$F" "${BUILD_DIR}/"
done done
@ -123,7 +127,8 @@ umask 0022
# cleanup # cleanup
if [ -z "${OUT}" ]; then if [ -z "${OUT}" ]; then
OUT="out/${FILENAME}" OUT="out/${FILENAME}"
mkdir -p $(dirname "${OUT}") _out_dir=$(dirname "${OUT}")
mkdir -p "${_out_dir}"
rm -rf "${OUT}" rm -rf "${OUT}"
fi fi
@ -144,11 +149,12 @@ if [ "${TYPE}" = 'dir' ]; then
cp -rT "${BUILD_DIR}" "${OUT}" cp -rT "${BUILD_DIR}" "${OUT}"
elif [ "${TYPE}" = 'iso' ]; then elif [ "${TYPE}" = 'iso' ]; then
_out_dir=$(dirname "${OUT}")
mkisofs -J -R -input-charset utf8 \ mkisofs -J -R -input-charset utf8 \
-m '*.iso' \ -m '*.iso' \
-V "${LABEL}" \ -V "${LABEL}" \
-o "${OUT}" \ -o "${OUT}" \
$(dirname "${OUT}") "${_out_dir}"
else else
CONFIG_FILES=$(cd "${BUILD_DIR}" && \ CONFIG_FILES=$(cd "${BUILD_DIR}" && \
@ -159,25 +165,26 @@ else
# concatenate pre/postinstall scripts # concatenate pre/postinstall scripts
if [ -n "${POSTIN}" ]; then if [ -n "${POSTIN}" ]; then
cat ${POSTIN} >"${_POSTIN}" cat "${POSTIN}" >"${_POSTIN}"
fi fi
if [ -n "${PREUN}" ]; then if [ -n "${PREUN}" ]; then
cat ${PREUN} >"${_PREUN}" cat "${PREUN}" >"${_PREUN}"
fi fi
if [ -n "${POSTUN}" ]; then if [ -n "${POSTUN}" ]; then
cat ${POSTUN} >"${_POSTUN}" cat "${POSTUN}" >"${_POSTUN}"
fi fi
if [ -n "${POSTUP}" ]; then if [ -n "${POSTUP}" ]; then
cat ${POSTUP} >"${_POSTUP}" cat "${POSTUP}" >"${_POSTUP}"
fi fi
# set the package version of onesysprep # set the package version of onesysprep
sed -i "s/\<_PACKAGE_VERSION_\>/${VERSION}/" \ sed -i "s/\<_PACKAGE_VERSION_\>/${VERSION}/" \
"${BUILD_DIR}/usr/sbin/onesysprep" "${BUILD_DIR}/usr/sbin/onesysprep"
# shellcheck disable=SC2086
fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \ fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \
--architecture all --license "${LICENSE}" \ --architecture all --license "${LICENSE}" \
--vendor "${VENDOR}" --maintainer "${MAINTAINER}" \ --vendor "${VENDOR}" --maintainer "${MAINTAINER}" \
@ -201,4 +208,4 @@ else
--package "${OUT}" --package "${OUT}"
fi fi
echo $(basename ${OUT}) basename "${OUT}"

@ -1,8 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NETWORK=${NETWORK:-yes} NETWORK=${NETWORK:-yes}
NETWORK_EC2=${NETWORK_EC2:-no} SERVICES=${SERVICES:-one-context-local one-context-online one-context}
SERVICES=${SERVICES:-one-context-local one-context}
rm -f /etc/udev/rules.d/70-persistent-cd.rules rm -f /etc/udev/rules.d/70-persistent-cd.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules rm -f /etc/udev/rules.d/70-persistent-net.rules
@ -65,26 +64,15 @@ fi
# Debian based distros # Debian based distros
if [ -d /etc/network ]; then if [ -d /etc/network ]; then
# Prepare network files # Prepare network files
cp /etc/network/interfaces /etc/network/interfaces.$(date "+%s") cp /etc/network/interfaces "/etc/network/interfaces.$(date '+%s')"
rm -rf /etc/network/interfaces.d rm -rf /etc/network/interfaces.d
rm -rf /etc/netplan/* rm -rf /etc/netplan/*
if [ "${NETWORK_EC2}" = 'yes' ]; then cat > /etc/network/interfaces <<EOT
cat > /etc/network/interfaces <<EOT
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOT
else
cat > /etc/network/interfaces <<EOT
# The loopback network interface # The loopback network interface
auto lo auto lo
iface lo inet loopback iface lo inet loopback
EOT EOT
fi
# Do not reconfigure network interfaces on boot # Do not reconfigure network interfaces on boot
# if [ -f /etc/default/networking ]; then # if [ -f /etc/default/networking ]; then
@ -101,20 +89,6 @@ if [ -d /etc/sysconfig/network-scripts ]; then
\( -name 'ifcfg-*' -o -name 'route-*' \) \ \( -name 'ifcfg-*' -o -name 'route-*' \) \
! -name 'ifcfg-lo' ! -name 'route-lo' \ ! -name 'ifcfg-lo' ! -name 'route-lo' \
-exec rm -f {} \; -exec rm -f {} \;
if [ "${NETWORK_EC2}" = 'yes' ]; then
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOT
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
USERCTL="yes"
PEERDNS="yes"
IPV6INIT="no"
NM_CONTROLLED="no"
PERSISTENT_DHCLIENT="1"
EOT
fi
fi fi
# openSUSE based distros # openSUSE based distros
@ -129,15 +103,6 @@ if [ -d /etc/sysconfig/network ]; then
sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/="/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/="/' /etc/sysconfig/network/config
sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config
if [ "${NETWORK_EC2}" = 'yes' ]; then
cat >/etc/sysconfig/network/ifcfg-eth0 <<EOT
DEVICE=eth0
BOOTPROTO=dhcp4
STARTMODE=auto
USERCONTROL=yes
EOT
fi
fi fi
# FreeBSD based distros # FreeBSD based distros

@ -1,4 +0,0 @@
#!/usr/bin/env bash
NETWORK_EC2=yes
SERVICES='one-context'

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SERVICES=${SERVICES:-one-context one-context-local} SERVICES=${SERVICES:-one-context one-context-online one-context-local}
# Disable services # Disable services
if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then

@ -1,3 +0,0 @@
#!/usr/bin/env bash
SERVICES='one-context'

@ -0,0 +1,3 @@
[main]
no-auto-default=*
dns=none

@ -18,6 +18,11 @@
set -e set -e
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# Umount the directory and remove it # Umount the directory and remove it
cleanup() cleanup()
{ {

@ -20,6 +20,11 @@
set -e set -e
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
GROW_ROOTFS=${GROW_ROOTFS:-YES} GROW_ROOTFS=${GROW_ROOTFS:-YES}
GROW_ROOTFS=${GROW_ROOTFS^^} GROW_ROOTFS=${GROW_ROOTFS^^}
#GROW_FS # list of mountpoints to resize #GROW_FS # list of mountpoints to resize

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
if [ -z "${TIMEZONE}" ]; then if [ -z "${TIMEZONE}" ]; then
exit 0 exit 0
fi fi

@ -16,44 +16,47 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# shellcheck disable=SC1091,SC1090
. /etc/one-context.d/loc-10-network.d/functions . /etc/one-context.d/loc-10-network.d/functions
ACTION="$1" context_type="$1"
OS_ID=$(detect_os) action="$2"
os_id=$(detect_os)
if [ -z "${ACTION}" ] ; then if [ -z "${action}" ] ; then
ACTION="configure" action="configure"
fi fi
if [ -z "${CONTEXT_NETCFG_TYPE}" ] ; then if [ -z "${NETCFG_TYPE}" ] ; then
case "${OS_ID}" in case "${os_id}" in
alpine) alpine)
CONTEXT_NETCFG_TYPE='interfaces' NETCFG_TYPE='interfaces'
;; ;;
altlinux) altlinux)
CONTEXT_NETCFG_TYPE='networkd' NETCFG_TYPE='networkd nm'
;; ;;
debian|ubuntu|devuan) debian|devuan|ubuntu)
CONTEXT_NETCFG_TYPE='interfaces' NETCFG_TYPE='interfaces netplan nm networkd'
;; ;;
fedora|centos|rhel|almalinux|ol|rocky) fedora|centos|rhel|almalinux|ol|rocky)
CONTEXT_NETCFG_TYPE='scripts' NETCFG_TYPE='scripts nm networkd'
;; ;;
opensuse*) opensuse*)
CONTEXT_NETCFG_TYPE='scripts' NETCFG_TYPE='scripts nm networkd'
;; ;;
freebsd) freebsd)
CONTEXT_NETCFG_TYPE='bsd' NETCFG_TYPE='bsd'
;; ;;
*) *)
CONTEXT_NETCFG_TYPE='none' NETCFG_TYPE='none'
;; ;;
esac esac
fi fi
if [ "${CONTEXT_NETCFG_TYPE}" != 'none' ] ; then if [ "${NETCFG_TYPE}" != 'none' ] ; then
_found_valid_netcfg='no' _found_valid_netcfg='no'
for _cfgtype in ${CONTEXT_NETCFG_TYPE} ; do for _cfgtype in ${NETCFG_TYPE} ; do
if [ -e "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}" ] ; then if [ -e "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}" ] ; then
. "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}" . "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}"
else else
@ -67,16 +70,30 @@ if [ "${CONTEXT_NETCFG_TYPE}" != 'none' ] ; then
fi fi
done done
# this is a contextualization guard
case "${required_context_type}" in
''|local|online)
if [ "${required_context_type:-local}" != "${context_type}" ] ; then
# skip this netcfg at this stage
exit 0
fi
;;
*)
echo "ERROR [!]: Unknown required context type: ${required_context_type}" >&2
exit 1
;;
esac
if [ "${_found_valid_netcfg}" = 'no' ] ; then if [ "${_found_valid_netcfg}" = 'no' ] ; then
echo "ERROR [!]: None of the requested network types is supported on: ${OS_ID}" >&2 echo "ERROR [!]: None of the requested network types is supported on: ${os_id}" >&2
exit 1 exit 1
fi fi
else else
# any action is meaningless without functioning network type # any action is meaningless without functioning network type
ACTION='none' action='none'
fi fi
case "$ACTION" in case "$action" in
none) none)
echo "INFO: Network will not be configured" >&2 echo "INFO: Network will not be configured" >&2
;; ;;
@ -88,7 +105,7 @@ case "$ACTION" in
reload_network reload_network
;; ;;
*) *)
echo "ERROR [!]: Unknown ACTION: ${ACTION}" >&2 echo "ERROR [!]: Unknown ACTION: ${action}" >&2
exit 1 exit 1
;; ;;
esac esac

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
get_iface_var() get_iface_var()
{ {
var_name="${UPCASE_DEV}_$1" var_name="${UPCASE_DEV}_$1"

@ -16,10 +16,14 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# shellcheck disable=SC2155
# #
# network module interface # network module interface
# #
export required_context_type='local' # this is the default, the next option is 'online'
is_network_supported() is_network_supported()
{ {
false false
@ -27,25 +31,25 @@ is_network_supported()
configure_network() configure_network()
{ {
echo "ERROR [!]: No 'configure_network' implementation for the network type: ${CONTEXT_NETCFG_TYPE}" >&2 echo "ERROR [!]: No 'configure_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1 exit 1
} }
stop_network() stop_network()
{ {
echo "ERROR [!]: No 'stop_network' implementation for the network type: ${CONTEXT_NETCFG_TYPE}" >&2 echo "ERROR [!]: No 'stop_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1 exit 1
} }
start_network() start_network()
{ {
echo "ERROR [!]: No 'start_network' implementation for the network type: ${CONTEXT_NETCFG_TYPE}" >&2 echo "ERROR [!]: No 'start_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1 exit 1
} }
reload_network() reload_network()
{ {
echo "ERROR [!]: No 'reload_network' implementation for the network type: ${CONTEXT_NETCFG_TYPE}" >&2 echo "ERROR [!]: No 'reload_network' implementation for the network type: ${NETCFG_TYPE}" >&2
exit 1 exit 1
} }
@ -53,6 +57,20 @@ reload_network()
# generic shared functions # generic shared functions
# #
is_true()
(
_value=$(eval echo "\$${1}" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
case "$_value" in
1|true|yes|y)
return 0
;;
esac
return 1
)
# return OS ID # return OS ID
detect_os() detect_os()
( (
@ -66,81 +84,93 @@ detect_os()
fi fi
) )
skip_interface()
{
[ -z "${dev}" ] && return 0
is_true "${dhcp}" && return 1
is_true "${dhcp6}" && return 1
[ -z "${ip}${ip6}" ] && return 0
return 1
}
# args: <iface> <name> # args: <iface> <name>
get_iface_var() get_iface_var()
( (
iface=$(echo "$1" | tr '[:lower:]' '[:upper:]') _iface=$(echo "$1" | tr '[:lower:]' '[:upper:]')
var_name="${iface}_${2}" _var_name="${_iface}_${2}"
eval "echo \"\${${var_name}}\"" eval "echo \"\${${_var_name}}\""
) )
# Gets IP address from a given MAC # Gets IP address from a given MAC
mac2ip() mac2ip()
( (
mac="$1" _mac="$1"
ip_a=$(echo "$mac" | cut -d: -f 3) _ip_a=$(echo "$_mac" | cut -d: -f 3)
ip_b=$(echo "$mac" | cut -d: -f 4) _ip_b=$(echo "$_mac" | cut -d: -f 4)
ip_c=$(echo "$mac" | cut -d: -f 5) _ip_c=$(echo "$_mac" | cut -d: -f 5)
ip_d=$(echo "$mac" | cut -d: -f 6) _ip_d=$(echo "$_mac" | cut -d: -f 6)
echo "0x${ip_a}.0x${ip_b}.0x${ip_c}.0x${ip_d}" echo "0x${_ip_a}.0x${_ip_b}.0x${_ip_c}.0x${_ip_d}"
) )
mask2cidr() mask2cidr()
( (
mask="$1" _mask="$1"
nbits=0 _nbits=0
IFS=. IFS=.
for dec in $mask ; do for _dec in $_mask ; do
case "$dec" in case "$_dec" in
255) nbits=$((nbits + 8)) ;; 255) _nbits=$((_nbits + 8)) ;;
254) nbits=$((nbits + 7)) ; break ;; 254) _nbits=$((_nbits + 7)) ; break ;;
252) nbits=$((nbits + 6)) ; break ;; 252) _nbits=$((_nbits + 6)) ; break ;;
248) nbits=$((nbits + 5)) ; break ;; 248) _nbits=$((_nbits + 5)) ; break ;;
240) nbits=$((nbits + 4)) ; break ;; 240) _nbits=$((_nbits + 4)) ; break ;;
224) nbits=$((nbits + 3)) ; break ;; 224) _nbits=$((_nbits + 3)) ; break ;;
192) nbits=$((nbits + 2)) ; break ;; 192) _nbits=$((_nbits + 2)) ; break ;;
128) nbits=$((nbits + 1)) ; break ;; 128) _nbits=$((_nbits + 1)) ; break ;;
0) break ;; 0) break ;;
*) echo "Error: $dec is not recognised"; exit 1 ;; *) echo "Error: $_dec is not recognised"; exit 1 ;;
esac esac
done done
echo "$nbits" echo "$_nbits"
) )
# Gets the network part of an IP # Gets the network part of an IP
# arg: <iface> # arg: <iface>
get_network() get_network()
( (
network=$(get_iface_var "$1" "NETWORK") _network=$(get_iface_var "$1" "NETWORK")
if [ -z "$network" ]; then if [ -z "$_network" ]; then
ip=$(get_ip "$1") _ip=$(get_ip "$1")
mask=$(get_mask "$1") _mask=$(get_mask "$1")
network=$(awk -v ip="$ip" -v mask="$mask" 'END { _network=$(awk -v ip="$_ip" -v mask="$_mask" 'END {
split(ip, ip_b, "."); split(mask, mask_b, "."); split(ip, ip_b, "."); split(mask, mask_b, ".");
for (i=1; i<=4; ++i) x = x "." and(ip_b[i], mask_b[i]); for (i=1; i<=4; ++i) x = x "." and(ip_b[i], mask_b[i]);
sub(/^./, "", x); print x; }' </dev/null) sub(/^./, "", x); print x; }' </dev/null)
fi fi
echo "$network" echo "$_network"
) )
# Gets the network mask # Gets the network mask
# arg: <iface> # arg: <iface>
get_mask() get_mask()
( (
mask=$(get_iface_var "$1" "MASK") _mask=$(get_iface_var "$1" "MASK")
echo "${mask:-255.255.255.0}" echo "${_mask:-255.255.255.0}"
) )
# Gets device MTU # Gets device MTU
# arg: <iface> # arg: <iface>
get_mtu() get_mtu()
( (
mtu=$(get_iface_var "$1" "MTU") _mtu=$(get_iface_var "$1" "MTU")
echo "${mtu:-1500}" echo "${_mtu:-1500}"
) )
# Gets the network gateway # Gets the network gateway
@ -178,17 +208,20 @@ get_search_domain()
# arg: <iface> # arg: <iface>
get_interface_alias() get_interface_alias()
( (
env | sed -n "s#^\(${1}_ALIAS[0-9]\+\)_MAC=.*#\1#p" | sort # sed on freebsd does not recognize '+' - replacing with asterisk
env | sed -n "s#^\(${1}_ALIAS[0-9][0-9]*\)_MAC=.*#\1#p" | sort
) )
get_context_interfaces() get_context_interfaces()
( (
env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | sort # sed on freebsd does not recognize '+' - replacing with asterisk
env | sed -n 's/^\(ETH[0-9][0-9]*\)_MAC=.*/\1/p' | sort
) )
get_pci_interfaces() get_pci_interfaces()
( (
env | grep -E "^PCI[0-9]+_MAC=" | sed 's/_.*$//' | sort # sed on freebsd does not recognize '+' - replacing with asterisk
env | sed -n 's/^\(PCI[0-9][0-9]*\)_MAC=.*/\1/p' | sort
) )
get_interface_mac() get_interface_mac()
@ -198,9 +231,111 @@ get_interface_mac()
get_dev() get_dev()
( (
list="$1" _list="$1"
mac="$2" _mac="$2"
echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1 echo "$_list" | grep "$_mac" | cut -d' ' -f1 | tail -n1
) )
# arg: <interface/alias>
setup_ipadr_vars()
{
export ip=$(get_ip "$1")
export network=$(get_network "$1")
export mask=$(get_mask "$1")
export cidr=$(mask2cidr "$mask")
export dhcp=$(get_iface_var "$1" "DHCP")
}
# arg: <interface/alias>
setup_ip6adr_vars()
{
export ip6=$(get_iface_var "$1" "IP6")
export ip6_prefix_length=$(get_iface_var "$1" "IP6_PREFIX_LENGTH")
export ip6_ula=$(get_iface_var "$1" "IP6_ULA")
export dhcp6=$(get_iface_var "$1" "DHCP6")
[ -z "$ip6" ] && ip6=$(get_iface_var "$1" "IPV6")
[ -z "$ip6_prefix_length" ] && ip6_prefix_length=64
}
# arg: <interface>
setup_iface_vars()
{
_iface_mac=$(get_interface_mac)
export mac=$(get_iface_var "$1" "MAC")
export dev=$(get_dev "$_iface_mac" "$mac")
export mtu=$(get_mtu "$1")
export gateway=$(get_gateway "$1")
export metric=$(get_iface_var "$1" "METRIC")
export dns=$(get_dns "$1")
export search_domains=$(get_search_domain "$1")
export gateway6=$(get_gateway6 "$1")
setup_ipadr_vars "$1"
setup_ip6adr_vars "$1"
}
# arg: <alias>
setup_alias_vars()
{
export external=$(get_iface_var "$1" "EXTERNAL")
export detach=$(get_iface_var "$1" "DETACH")
}
get_nameservers()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
_dns_variables=$(env | sed -n 's/^\(ETH[0-9][0-9]*_DNS\)=.*/\1/p' | sort)
for _dns in DNS ${_dns_variables} ; do
_value=$(eval "echo \"\${$_dns}\"")
if [ -n "$_value" ] ; then
echo "$_value"
fi
done
)
get_searchdomains()
(
# sed on freebsd does not recognize '+' - replacing with asterisk
_search_domains=$(env | sed -n 's/^\(ETH[0-9][0-9]*_SEARCH_DOMAIN\)=.*/\1/p' | sort)
for _search in SEARCH_DOMAIN ${_search_domains} ; do
_value=$(eval "echo \"\${$_search}\"")
if [ -n "$_value" ] ; then
echo "$_value"
fi
done
)
gen_resolvconf()
{
export all_nameservers=$(get_nameservers)
export all_search_domains=$(get_searchdomains)
[ -z "$all_nameservers" ] && return 0
if [ -L /etc/resolv.conf ]; then
unlink /etc/resolv.conf
else
cat /dev/null > /etc/resolv.conf
fi
for _nameserver in $all_nameservers ; do
echo "nameserver ${_nameserver}" >> /etc/resolv.conf
done
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=\"${all_nameservers}\"/" /etc/sysconfig/network/config
fi
[ -z "$all_search_domains" ] && return 0
echo "search ${all_search_domains}" >> /etc/resolv.conf
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=\"${all_search_domains}\"/" /etc/sysconfig/network/config
fi
}

@ -22,7 +22,7 @@
is_network_supported() is_network_supported()
{ {
case "${OS_ID}" in case "${os_id}" in
freebsd) freebsd)
return 0 return 0
;; ;;
@ -33,7 +33,8 @@ is_network_supported()
configure_network() configure_network()
{ {
gen_network_configuration >/etc/rc.conf.d/network gen_resolvconf
gen_network_configuration > /etc/rc.conf.d/network
} }
stop_network() stop_network()
@ -58,138 +59,166 @@ reload_network()
# helper functions # helper functions
# #
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export dhcp
export ip6
export ip6_prefix_length
export ip6_ula
export dhcp6
export mac
export dev
export mtu
export gateway
export metric
export dns
export search_domains
export gateway6
export external
export detach
export all_nameservers
export all_search_domains
get_interface_mac() get_interface_mac()
( (
macs=$(ifconfig | grep ether | awk '{print $2}') _macs=$(ifconfig | grep ether | awk '{print $2}')
for mac in ${macs} ; do for _mac in ${_macs} ; do
iface=$(ifconfig | grep -B 2 "$mac" | head -n 1 | awk '{print $1}' | cut -d ':' -f 1) _iface=$(ifconfig | grep -B 2 "$_mac" | head -n 1 | awk '{print $1}' | cut -d ':' -f 1)
echo "${iface} ${mac}" echo "${_iface} ${_mac}"
done done
) )
gen_iface_conf() { gen_iface_conf()
echo -n "ifconfig_${DEV}=\"inet ${IP} netmask ${MASK}" {
echo -n "ifconfig_${dev}=\"inet ${ip} netmask ${mask}"
if [ -n "${MTU}" ]; then if [ -n "${mtu}" ]; then
echo -n " mtu ${MTU}" echo -n " mtu ${mtu}"
fi fi
echo "\"" echo "\""
### ###
if [ -n "${GATEWAY}" ]; then if [ -n "${gateway}" ]; then
echo "defaultrouter=\"${GATEWAY}\"" >> /etc/rc.conf.d/routing echo "defaultrouter=\"${gateway}\"" >> /etc/rc.conf.d/routing
fi fi
} }
gen_alias_conf() { gen_dhcp_conf()
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet ${IP} netmask ${MASK}\"" {
ALIAS_NUM=$((ALIAS_NUM + 1)) echo "ifconfig_${dev}=\"DHCP\""
} }
gen_alias6_conf() { gen_alias_conf()
# very first IPv6 can't be alias {
if [ -n "${HAS_IP6}" ]; then echo "ifconfig_${dev}_alias${alias_num}=\"inet ${ip} netmask ${mask}\""
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}\"" alias_num=$((alias_num + 1))
ALIAS_NUM=$((ALIAS_NUM + 1))
else
echo -n "ifconfig_${DEV}_ipv6=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}"
if [ -n "${MTU}" ]; then
echo -n " mtu ${MTU}"
fi
echo " -accept_rtadv\""
fi
if [ -n "${IP6_ULA}" ]; then
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6_ULA} prefixlen 64\""
ALIAS_NUM=$((ALIAS_NUM + 1))
fi
} }
gen_iface6_conf() { gen_iface6_conf()
echo -n "ifconfig_${DEV}_ipv6=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}" {
echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}"
if [ -n "${MTU}" ]; then if [ -n "${mtu}" ]; then
echo -n " mtu ${MTU}" echo -n " mtu ${mtu}"
fi fi
echo " -accept_rtadv\"" echo " -accept_rtadv\""
if [ -n "${IP6_ULA}" ]; then if [ -n "${ip6_ula}" ]; then
echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6_ULA} prefixlen 64\"" echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\""
ALIAS_NUM=$((ALIAS_NUM + 1)) alias_num=$((alias_num + 1))
fi fi
### ###
if [ -n "${GATEWAY6}" ]; then if [ -n "${gateway6}" ]; then
echo "ipv6_defaultrouter=\"${GATEWAY6}\"" >> /etc/rc.conf.d/routing echo "ipv6_defaultrouter=\"${gateway6}\"" >> /etc/rc.conf.d/routing
fi fi
} }
gen_network_configuration() gen_dhcp6_conf()
{ {
# clean routing information # TODO: FreeBSD support for DHCP6 does not seem to be great:
echo -n > /etc/rc.conf.d/routing # https://forums.freebsd.org/threads/ipv6-dhcpv6-client-and-accept_rtadv-vs-rtsold.77421/
# https://forums.freebsd.org/threads/is-there-a-working-dhcpv6-client-for-freebsd.60168/
echo "ERROR [!]: DHCP6 on '${os_id}' is not supported" >&2
return 1
}
INTERFACE_MAC=$(get_interface_mac) gen_alias6_conf()
CONTEXT_INTERFACES=$(get_context_interfaces) {
# very first IPv6 can't be alias
if [ -n "${has_ip6}" ]; then
echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}\""
alias_num=$((alias_num + 1))
else
echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}"
for iface in $CONTEXT_INTERFACES; do if [ -n "${mtu}" ]; then
MAC=$(get_iface_var "$iface" "MAC") echo -n " mtu ${mtu}"
DEV=$(get_dev "$INTERFACE_MAC" "$MAC") fi
IP=$(get_ip "$iface") echo " -accept_rtadv\""
MASK=$(get_mask "$iface") fi
MTU=$(get_mtu "$iface")
GATEWAY=$(get_gateway "$iface")
# TODO: not implemented
#METRIC=$(get_iface_var "$iface" "METRIC")
IP6=$(get_iface_var "$iface" "IP6") if [ -n "${ip6_ula}" ]; then
[ -z "$IP6" ] && IP6=$(get_iface_var "$iface" "IPV6") echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\""
IP6_PREFIX_LENGTH=$(get_iface_var "$iface" "IP6_PREFIX_LENGTH") alias_num=$((alias_num + 1))
IP6_ULA=$(get_iface_var "$iface" "IP6_ULA") fi
GATEWAY6=$(get_gateway6 "$iface") }
[ -z "${IP}${IP6}" ] && continue gen_network_configuration()
[ -z "${DEV}" ] && continue {
HAS_IP6="${IP6}" # clean routing information
cat /dev/null > /etc/rc.conf.d/routing
_context_interfaces=$(get_context_interfaces)
[ -n "${IP}" ] && gen_iface_conf for _iface in $_context_interfaces; do
[ -n "${IP6}" ] && gen_iface6_conf setup_iface_vars "$_iface"
ALIASES=$(get_interface_alias) skip_interface && continue
ALIAS_NUM=0
for nic_alias in $ALIASES; do if is_true "${dhcp}" ; then
IP=$(get_ip "$nic_alias") gen_dhcp_conf
MASK=$(get_mask "$nic_alias") elif [ -n "${ip}" ] ; then
gen_iface_conf
fi
if is_true "${dhcp6}" ; then
gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then
gen_iface6_conf
fi
IP6=$(get_iface_var "$nic_alias" "IP6") has_ip6="${ip6}"
[ -z "$IP6" ] && IP6=$(get_iface_var "$nic_alias" "IPV6") _aliases=$(get_interface_alias)
IP6_PREFIX_LENGTH=$(get_iface_var "$nic_alias" "IP6_PREFIX_LENGTH") alias_num=0
IP6_ULA=$(get_iface_var "$nic_alias" "IP6_ULA")
EXTERNAL=$(get_iface_var "$nic_alias" "EXTERNAL") for _nic_alias in $_aliases; do
EXTERNAL=${EXTERNAL^^} setup_ipadr_vars "$_nic_alias"
DETACH=$(get_iface_var "$nic_alias" "DETACH") setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${DETACH}" ]; then if [ -z "${detach}" ]; then
if [ -z "${EXTERNAL}" ] || [ "$EXTERNAL" = "NO" ]; then if ! is_true "${external}" ; then
[ -n "${IP}" ] && gen_alias_conf [ -n "${ip}" ] && gen_alias_conf
if [ -n "${IP6}" ]; then if [ -n "${ip6}" ]; then
gen_alias6_conf gen_alias6_conf
HAS_IP6="${IP6}" has_ip6="${ip6}"
fi fi
fi fi
fi fi
done done
done done
} }

@ -22,7 +22,7 @@
is_network_supported() is_network_supported()
{ {
case "${OS_ID}" in case "${os_id}" in
alpine) alpine)
return 0 return 0
;; ;;
@ -36,30 +36,32 @@ is_network_supported()
configure_network() configure_network()
{ {
gen_resolvconf
gen_network_configuration > /etc/network/interfaces gen_network_configuration > /etc/network/interfaces
case "${OS_ID}" in case "${os_id}" in
debian|ubuntu|devuan) debian|ubuntu|devuan)
echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces
;; ;;
esac esac
} }
stop_network() { stop_network()
case "${OS_ID}" in {
case "${os_id}" in
alpine) alpine)
service networking stop || true service networking stop || true
# took from find_ifaces in the networking service # took from find_ifaces in the networking service
IFACES=$(\ _ifaces=$(\
awk '$1 == "auto" { awk '$1 == "auto" {
for (i = 2; i <= NF; i = i + 1) printf("%s ", $i) for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)
}' /etc/network/interfaces) }' /etc/network/interfaces)
for i in $IFACES; do for _iface in $_ifaces; do
if [ "${i}" != 'lo' ]; then if [ "${_iface}" != 'lo' ]; then
/sbin/ip link set dev "${i}" down || true /sbin/ip link set dev "${_iface}" down || true
/sbin/ip addr flush dev "${i}" || true /sbin/ip addr flush dev "${_iface}" || true
fi fi
done done
;; ;;
@ -68,12 +70,12 @@ stop_network() {
return 0 return 0
fi fi
IFACES=$(/sbin/ifquery --list -a) _ifaces=$(/sbin/ifquery --list -a)
for i in $IFACES; do for _iface in $_ifaces; do
if [ "${i}" != 'lo' ] ; then if [ "${_iface}" != 'lo' ] ; then
/sbin/ifdown "${i}" /sbin/ifdown "${_iface}"
/sbin/ip addr flush dev "${i}" /sbin/ip addr flush dev "${_iface}"
fi fi
done done
;; ;;
@ -83,8 +85,9 @@ stop_network() {
esac esac
} }
start_network() { start_network()
case "${OS_ID}" in {
case "${os_id}" in
alpine) alpine)
service networking start service networking start
;; ;;
@ -94,10 +97,10 @@ start_network() {
return 0 return 0
fi fi
IFACES=$(/sbin/ifquery --list -a) _ifaces=$(/sbin/ifquery --list -a)
for i in $IFACES; do for _iface in $_ifaces; do
/sbin/ifup "${i}" /sbin/ifup "${_iface}"
done done
;; ;;
*) *)
@ -106,7 +109,8 @@ start_network() {
esac esac
} }
reload_network() { reload_network()
{
stop_network stop_network
start_network start_network
} }
@ -115,128 +119,164 @@ reload_network() {
# helper functions # helper functions
# #
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export dhcp
export ip6
export ip6_prefix_length
export ip6_ula
export dhcp6
export mac
export dev
export mtu
export gateway
export metric
export dns
export search_domains
export gateway6
export external
export detach
export all_nameservers
export all_search_domains
gen_iface_conf() gen_iface_conf()
{ {
cat <<EOT cat <<EOT
iface $DEV inet static iface ${dev} inet static
address $IP address ${ip}
network $NETWORK network ${network}
netmask $MASK netmask ${mask}
EOT EOT
if [ -n "$MTU" ]; then if [ -n "$mtu" ]; then
echo " mtu $MTU" echo " mtu ${mtu}"
fi fi
if [ -n "$GATEWAY" ]; then if [ -n "$gateway" ]; then
echo " gateway $GATEWAY" echo " gateway ${gateway}"
if [ -n "$METRIC" ]; then if [ -n "$metric" ]; then
echo " metric $METRIC" echo " metric ${metric}"
fi fi
fi fi
echo "" echo ""
} }
gen_dhcp_conf()
{
echo "iface ${dev} inet dhcp"
}
gen_alias_conf() gen_alias_conf()
{ {
cat <<EOT cat <<EOT
iface $DEV inet static iface ${dev} inet static
address $IP address ${ip}
network $NETWORK network ${network}
netmask $MASK netmask ${mask}
EOT EOT
echo "" echo ""
} }
gen_alias6_conf() gen_iface6_conf()
{ {
case "${OS_ID}" in case "${os_id}" in
alpine) alpine)
cat <<EOT cat <<EOT
iface $DEV inet6 static iface ${dev} inet6 static
address $IP6 address ${ip6}
netmask ${IP6_PREFIX_LENGTH:-64} netmask ${ip6_prefix_length:-64}
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/autoconf pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/accept_ra pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/accept_ra
EOT EOT
;; ;;
debian|ubuntu|devuan) debian|ubuntu|devuan)
cat <<EOT cat <<EOT
iface $DEV inet6 static iface ${dev} inet6 static
address $IP6 address ${ip6}
netmask ${IP6_PREFIX_LENGTH:-64} netmask ${ip6_prefix_length:-64}
autoconf 0 autoconf 0
accept_ra 0 accept_ra 0
EOT EOT
;; ;;
esac esac
if [ -n "$IP6_ULA" ]; then if [ -n "$mtu" ]; then
echo " mtu ${mtu}"
fi
if [ -n "${gateway6}" ]; then
echo " gateway ${gateway6}"
fi
if [ -n "${ip6_ula}" ]; then
cat <<EOT cat <<EOT
iface $DEV inet6 static iface ${dev} inet6 static
address $IP6_ULA address ${ip6_ula}
netmask 64 netmask 64
EOT EOT
case "${os_id}" in
debian|ubuntu|devuan)
cat <<EOT
autoconf 0
accept_ra 0
EOT
;;
esac
if [ -n "$mtu" ]; then
echo " mtu ${mtu}"
fi
fi fi
echo "" echo ""
} }
gen_iface6_conf() gen_dhcp6_conf()
{ {
case "${OS_ID}" in echo "iface ${dev} inet6 dhcp"
}
gen_alias6_conf()
{
case "${os_id}" in
alpine) alpine)
cat <<EOT cat <<EOT
iface $DEV inet6 static iface ${dev} inet6 static
address $IP6 address ${ip6}
netmask ${IP6_PREFIX_LENGTH:-64} netmask ${ip6_prefix_length:-64}
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/autoconf pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/accept_ra pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/accept_ra
EOT EOT
;; ;;
debian|ubuntu|devuan) debian|ubuntu|devuan)
cat <<EOT cat <<EOT
iface $DEV inet6 static iface ${dev} inet6 static
address $IP6 address ${ip6}
netmask ${IP6_PREFIX_LENGTH:-64} netmask ${ip6_prefix_length:-64}
autoconf 0 autoconf 0
accept_ra 0 accept_ra 0
EOT EOT
;; ;;
esac esac
if [ -n "$MTU" ]; then if [ -n "${ip6_ula}" ]; then
echo " mtu $MTU"
fi
if [ -n "$GATEWAY6" ]; then
echo " gateway $GATEWAY6"
fi
if [ -n "$IP6_ULA" ]; then
cat <<EOT cat <<EOT
iface $DEV inet6 static iface ${dev} inet6 static
address $IP6_ULA address ${ip6_ula}
netmask 64 netmask 64
EOT EOT
case "${OS_ID}" in
debian|ubuntu|devuan)
cat <<EOT
autoconf 0
accept_ra 0
EOT
;;
esac
if [ -n "$MTU" ]; then
echo " mtu $MTU"
fi
fi fi
echo "" echo ""
@ -250,57 +290,40 @@ iface lo inet loopback
EOT EOT
INTERFACE_MAC=$(get_interface_mac) _context_interfaces=$(get_context_interfaces)
CONTEXT_INTERFACES=$(get_context_interfaces)
for iface in $CONTEXT_INTERFACES; do for _iface in $_context_interfaces; do
MAC=$(get_iface_var "$iface" "MAC") setup_iface_vars "$_iface"
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IP=$(get_ip "$iface") skip_interface && continue
NETWORK=$(get_network "$iface")
MASK=$(get_mask "$iface")
MTU=$(get_mtu "$iface")
GATEWAY=$(get_gateway "$iface")
METRIC=$(get_iface_var "$iface" "METRIC")
IP6=$(get_iface_var "$iface" "IP6") echo "auto ${dev}"
[ -z "$IP6" ] && IP6=$(get_iface_var "$iface" "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "$iface" "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "$iface" "IP6_ULA")
GATEWAY6=$(get_gateway6 "$iface")
[ -z "${IP}${IP6}" ] && continue if is_true "${dhcp}" ; then
[ -z "${DEV}" ] && continue gen_dhcp_conf
elif [ -n "${ip}" ] ; then
echo "auto $DEV" gen_iface_conf
fi
[ -n "${IP}" ] && gen_iface_conf
[ -n "${IP6}" ] && gen_iface6_conf
ALIASES=$(get_interface_alias "$iface")
for nic_alias in $ALIASES ; do if is_true "${dhcp6}" ; then
IP=$(get_ip "$nic_alias") gen_dhcp6_conf
NETWORK=$(get_network "$nic_alias") elif [ -n "${ip6}" ] ; then
MASK=$(get_mask "$nic_alias") gen_iface6_conf
fi
IP6=$(get_iface_var "$nic_alias" "IP6") _aliases=$(get_interface_alias "$_iface")
[ -z "$IP6" ] && IP6=$(get_iface_var "$nic_alias" "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "$nic_alias" "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "$nic_alias" "IP6_ULA")
EXTERNAL=$(get_iface_var "$nic_alias" "EXTERNAL") for _nic_alias in $_aliases ; do
EXTERNAL=${EXTERNAL^^} setup_ipadr_vars "$_nic_alias"
DETACH=$(get_iface_var "$nic_alias" "DETACH") setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${DETACH}" ]; then if [ -z "${detach}" ]; then
if [ -z "${EXTERNAL}" ] || [ "${EXTERNAL}" = "NO" ]; then if ! is_true "${external}" ; then
[ -n "${IP}" ] && gen_alias_conf [ -n "${ip}" ] && gen_alias_conf
[ -n "${IP6}" ] && gen_alias6_conf [ -n "${ip6}" ] && gen_alias6_conf
fi fi
fi fi
done done
done done
} }

@ -0,0 +1,220 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
is_network_supported()
{
command -v netplan >/dev/null
return $?
}
configure_network()
{
gen_resolvconf
gen_network_configuration > /etc/netplan/00-opennebula-generated-network.yaml
netplan generate
}
stop_network()
{
service networking stop
}
start_network()
{
service networking start
netplan generate
netplan apply
}
reload_network()
{
netplan generate
netplan apply
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export dhcp
export ip6
export ip6_prefix_length
export ip6_ula
export dhcp6
export mac
export dev
export mtu
export gateway
export metric
export dns
export search_domains
export gateway6
export external
export detach
export all_nameservers
export all_search_domains
gen_addresses()
{
echo " addresses:"
if [ -n "${ip}" ] ; then
gen_addr_conf
fi
if [ -n "${ip6}" ] ; then
gen_addr6_conf
fi
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_addr_conf
[ -n "${ip6}" ] && gen_addr6_conf
fi
fi
done
}
gen_routes()
{
echo " routes:"
if [ -n "${gateway}" ] ; then
cat <<EOT
- to: "0.0.0.0/0"
via: ${gateway}
EOT
if [ -n "${metric}" ] ; then
echo " metric: ${metric}"
fi
fi
if [ -n "${gateway6}" ] ; then
cat <<EOT
- to: "::/0"
via: ${gateway6}
EOT
if [ -n "${metric}" ] ; then
echo " metric: ${metric}"
fi
fi
}
gen_dhcp_conf()
{
cat <<EOT
dhcp4: true
EOT
}
gen_addr_conf()
{
echo " - ${ip}/${cidr}"
}
gen_addr6_conf()
{
echo " - ${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then
echo " - ${ip6_ula}/64"
fi
}
gen_dhcp6_conf()
{
cat <<EOT
dhcp6: true
EOT
}
init_netplan_renderer()
{
if [ -z "${NETCFG_NETPLAN_RENDERER}" ] ; then
if command -v networkctl >/dev/null ; then
NETCFG_NETPLAN_RENDERER='networkd'
elif command -v nmcli >/dev/null ; then
NETCFG_NETPLAN_RENDERER='NetworkManager'
fi
fi
}
gen_network_configuration()
{
init_netplan_renderer
cat <<EOT
network:
version: 2
renderer: ${NETCFG_NETPLAN_RENDERER:-networkd}
EOT
# ethernets key must have at least one interface
_ethernets_written=
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
if [ -z "${_ethernets_written}" ] ; then
echo " ethernets:"
_ethernets_written=yes
fi
echo " ${dev}:"
if [ -n "$mtu" ]; then
echo " mtu: ${mtu}"
fi
if is_true "${dhcp}" ; then
gen_dhcp_conf
fi
if is_true "${dhcp6}" ; then
gen_dhcp6_conf
fi
gen_addresses
gen_routes
done
}

@ -22,35 +22,29 @@
is_network_supported() is_network_supported()
{ {
case "${OS_ID}" in command -v networkctl >/dev/null
altlinux)
return 0 return $?
;;
fedora|centos|rhel|almalinux|ol|rocky)
return 0
;;
opensuse*)
return 0
;;
esac
return 1
} }
configure_network() configure_network()
{ {
gen_resolvconf
gen_network_configuration gen_network_configuration
} }
stop_network() { stop_network()
{
systemctl stop systemd-networkd.service systemctl stop systemd-networkd.service
} }
start_network() { start_network()
{
systemctl start systemd-networkd.service systemctl start systemd-networkd.service
} }
reload_network() { reload_network()
{
systemctl restart systemd-networkd.service systemctl restart systemd-networkd.service
} }
@ -58,41 +52,48 @@ reload_network() {
# helper functions # helper functions
# #
gen_iface_conf() { # TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export dhcp
export ip6
export ip6_prefix_length
export ip6_ula
export dhcp6
export mac
export dev
export mtu
export gateway
export metric
export dns
export search_domains
export gateway6
export external
export detach
export all_nameservers
export all_search_domains
gen_iface_conf()
{
cat <<EOT cat <<EOT
[Network] [Network]
Address=${IP}/${CIDR} Address=${ip}/${cidr}
EOT EOT
ALIASES=$(get_interface_alias "$iface")
for nic_alias in $ALIASES; do
IP=$(get_ip "$nic_alias")
MASK=$(get_mask "$nic_alias")
CIDR=$(mask2cidr "$MASK")
EXTERNAL=$(get_iface_var "$nic_alias" "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
DETACH=$(get_iface_var "$nic_alias" "DETACH")
if [ -z "${DETACH}" ]; then
if [ -z "${EXTERNAL}" ] || [ "${EXTERNAL}" = "NO" ]; then
if [ -n "${IP}" ]; then
echo "Address=$IP/$CIDR"
fi
fi
fi
done
if [ -n "$DNS" ]; then if [ -n "$dns" ]; then
for dns_server in $DNS; do for _domain in $dns; do
echo "DNS=$dns_server" echo "DNS=${_domain}"
done done
fi fi
if [ -n "$SEARCH_DOMAIN" ]; then if [ -n "$search_domains" ]; then
for domain in $SEARCH_DOMAIN; do for _search_domain in $search_domains; do
echo "Domains=$domain" echo "Domains=${_search_domain}"
done done
fi fi
@ -100,55 +101,51 @@ EOT
[Route] [Route]
EOT EOT
if [ -n "$GATEWAY" ]; then if [ -n "$gateway" ]; then
echo "Gateway=$GATEWAY" echo "Gateway=${gateway}"
if [ -n "$METRIC" ]; then if [ -n "$metric" ]; then
echo "Metric=$METRIC" echo "Metric=${metric}"
fi fi
fi fi
echo "" echo ""
} }
gen_iface6_conf() { gen_dhcp_conf()
{
cat <<EOT cat <<EOT
[Network] [Network]
Address=${IP6}/${IP6_PREFIX_LENGTH:-64} DHCP=ipv4
EOT EOT
}
ALIASES=$(get_interface_alias "$iface") gen_alias_conf()
{
for nic_alias in $ALIASES; do cat <<EOT
IP6=$(get_iface_var "$nic_alias" "IP6") [Address]
[ -z "$IP6" ] && IP6=$(get_iface_var "$nic_alias" "IPV6") Address=${ip}/${cidr}
IP6_PREFIX_LENGTH=$(get_iface_var "$nic_alias" "IP6_PREFIX_LENGTH") EOT
IP6_ULA=$(get_iface_var "$nic_alias" "IP6_ULA") }
EXTERNAL=$(get_iface_var "$nic_alias" "EXTERNAL")
EXTERNAL=${EXTERNAL^^}
DETACH=$(get_iface_var "$nic_alias" "DETACH")
if [ -z "${DETACH}" ]; then gen_iface6_conf()
if [ -z "${EXTERNAL}" ] || [ "${EXTERNAL}" = "NO" ]; then {
if [ -n "${IP6}" ]; then cat <<EOT
echo "Address=$IP6/${IP6_PREFIX_LENGTH:-64}" [Network]
fi Address=${ip6}/${ip6_prefix_length:-64}
fi EOT
fi
done
echo "IPv6AcceptRA=false" echo "IPv6AcceptRA=false"
if [ -n "$DNS" ]; then if [ -n "$dns" ]; then
for dns_server in $DNS; do for _domain in $dns; do
echo "DNS=$dns_server" echo "DNS=${_domain}"
done done
fi fi
if [ -n "$SEARCH_DOMAIN" ]; then if [ -n "$search_domains" ]; then
for domain in $SEARCH_DOMAIN; do for _search_domain in $search_domains; do
echo "Domains=$domain" echo "Domains=${_search_domain}"
done done
fi fi
@ -156,64 +153,87 @@ EOT
[Route] [Route]
EOT EOT
if [ -n "$GATEWAY6" ]; then if [ -n "$gateway6" ]; then
echo "Gateway=$GATEWAY6" echo "Gateway=${gateway6}"
fi fi
if [ -n "$IP6_ULA" ]; then if [ -n "$ip6_ula" ]; then
cat <<EOT cat <<EOT
[Network] [Network]
Address=$IP6_ULA/64 Address=${ip6_ula}/64
EOT EOT
fi fi
echo "" echo ""
} }
gen_dhcp6_conf()
{
cat <<EOT
[Network]
DHCP=ipv6
IPv6AcceptRA=true
EOT
}
gen_alias6_conf()
{
cat <<EOT
[Address]
Address=${ip6}/${ip6_prefix_length:-64}
EOT
}
gen_network_configuration() gen_network_configuration()
{ {
INTERFACE_MAC=$(get_interface_mac) _context_interfaces=$(get_context_interfaces)
CONTEXT_INTERFACES=$(get_context_interfaces)
for _iface in $_context_interfaces; do
for iface in $CONTEXT_INTERFACES; do setup_iface_vars "$_iface"
MAC=$(get_iface_var "$iface" "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC") skip_interface && continue
IP=$(get_ip "$iface")
MASK=$(get_mask "$iface")
CIDR=$(mask2cidr "$MASK")
MTU=$(get_mtu "$iface")
GATEWAY=$(get_gateway "$iface")
METRIC=$(get_iface_var "$iface" "METRIC")
DNS=$(get_dns "$iface")
SEARCH_DOMAIN=$(get_search_domain "$iface")
IP6=$(get_iface_var "$iface" "IP6")
IP6_PREFIX_LENGTH=$(get_iface_var "$iface" "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "$iface" "IP6_ULA")
GATEWAY6=$(get_gateway6 "$iface")
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
{ {
cat <<EOT cat <<EOT
[Match] [Match]
Name=$DEV Name=${dev}
EOT EOT
if [ -n "$MTU" ]; then if [ -n "$mtu" ]; then
cat <<EOT cat <<EOT
[Link] [Link]
MTUBytes=$MTU MTUBytes=${mtu}
EOT EOT
fi fi
[ -n "${IP}" ] && gen_iface_conf if is_true "${dhcp}" ; then
[ -n "${IP6}" ] && gen_iface6_conf gen_dhcp_conf
elif [ -n "${ip}" ] ; then
gen_iface_conf
fi
} > "/etc/systemd/network/${DEV}.network" if is_true "${dhcp6}" ; then
gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then
gen_iface6_conf
fi
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases ; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
[ -n "${ip6}" ] && gen_alias6_conf
fi
fi
done
} > "/etc/systemd/network/${dev}.network"
done done
} }

@ -0,0 +1,223 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
#
# network module implementation
#
export required_context_type=online
is_network_supported()
{
command -v nmcli >/dev/null
return $?
}
configure_network()
{
wait_for_nm
gen_resolvconf
gen_network_configuration
# this enables sensible default for 'unmanaged-devices'
mkdir -p /etc/NetworkManager/conf.d
touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
}
stop_network()
{
service NetworkManager stop
}
start_network()
{
service NetworkManager start
}
reload_network()
{
nmcli connection reload
}
#
# helper functions
#
# TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export dhcp
export ip6
export ip6_prefix_length
export ip6_ula
export dhcp6
export mac
export dev
export mtu
export gateway
export metric
export dns
export search_domains
export gateway6
export external
export detach
export all_nameservers
export all_search_domains
wait_for_nm()
{
_timeout=30
while [ "$_timeout" -gt 0 ] ; do
if _nm_networking=$(nmcli networking 2>/dev/null) ; then
break
fi
_timeout=$(( _timeout - 1 ))
sleep 1
done
if [ "${_timeout}" -eq 0 ] ; then
echo "ERROR [!]: NetworkManager is not running" >&2
exit 1
elif [ "${_nm_networking}" = 'enabled' ] ; then
return 0
else
echo "ERROR [!]: NetworkManager is disabled" >&2
exit 1
fi
}
gen_iface_conf()
{
nmcli con mod "${dev}" ipv4.method manual ipv4.addr "${ip}/${cidr}"
if [ -n "$gateway" ]; then
nmcli con mod "${dev}" ipv4.gateway "${gateway}"
fi
if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv4.route-metric "${metric}"
fi
}
gen_dhcp_conf()
{
nmcli con mod "${dev}" ipv4.method auto
}
gen_alias_conf()
{
nmcli con mod "${dev}" +ipv4.addr "${ip}/${cidr}"
}
gen_iface6_conf()
{
nmcli con mod "${dev}" ipv6.method manual \
ipv6.addr "${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then
nmcli con mod "${dev}" +ipv6.addr "${ip6_ula}/64"
fi
if [ -n "$gateway6" ]; then
nmcli con mod "${dev}" ipv6.gateway "${gateway6}"
fi
if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv6.route-metric "${metric}"
fi
}
gen_alias6_conf()
{
nmcli con mod "${dev}" +ipv6.addr "${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then
nmcli con mod "${dev}" +ipv6.addr "${ip6_ula}/64"
fi
}
gen_dhcp6_conf()
{
nmcli con mod "${dev}" ipv6.method dhcp
}
# arg: <interface-connection>
nm_connection_exist()
(
_iface=$(nmcli --field connection.interface-name con show "$1" | awk '{print $2}')
if [ "${_iface}" = "$1" ] ; then
return 0
fi
return 1
)
gen_network_configuration()
{
_context_interfaces=$(get_context_interfaces)
for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"
skip_interface && continue
if ! nm_connection_exist "${dev}" ; then
nmcli con add type ethernet con-name "${dev}" ifname "${dev}"
fi
nmcli con mod "${dev}" connection.autoconnect yes
if [ -n "$mtu" ]; then
nmcli con mod "${dev}" ethernet.mtu "${mtu}"
fi
if is_true "${dhcp}" ; then
gen_dhcp_conf
elif [ -n "${ip}" ] ; then
gen_iface_conf
fi
if is_true "${dhcp6}" ; then
gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then
gen_iface6_conf
fi
_aliases=$(get_interface_alias "$_iface")
for _nic_alias in $_aliases; do
setup_ipadr_vars "$_nic_alias"
setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${detach}" ]; then
if ! is_true "${external}" ; then
[ -n "${ip}" ] && gen_alias_conf
[ -n "${ip6}" ] && gen_alias6_conf
fi
fi
done
done
}

@ -22,32 +22,33 @@
is_network_supported() is_network_supported()
{ {
case "${OS_ID}" in if [ -e /etc/sysconfig/network-scripts/ifup ] || \
fedora|centos|rhel|almalinux|ol|rocky) [ -e /etc/sysconfig/network/ifup ] ;
return 0 then
;; return 0
opensuse*) fi
return 0
;;
esac
return 1 return 1
} }
configure_network() configure_network()
{ {
gen_resolvconf
gen_network_configuration gen_network_configuration
} }
stop_network() { stop_network()
{
service network stop service network stop
} }
start_network() { start_network()
{
service network start service network start
} }
reload_network() { reload_network()
{
service network restart service network restart
} }
@ -55,163 +56,192 @@ reload_network() {
# helper functions # helper functions
# #
gen_iface_conf() { # TODO: remove global variables and get rid off exports
#
# to satisfy shellcheck SC2154:
export os_id
export ip
export network
export mask
export cidr
export dhcp
export ip6
export ip6_prefix_length
export ip6_ula
export dhcp6
export mac
export dev
export mtu
export gateway
export metric
export dns
export search_domains
export gateway6
export external
export detach
export all_nameservers
export all_search_domains
gen_iface_conf()
{
cat <<EOT cat <<EOT
NETMASK="$MASK" BOOTPROTO=none
IPADDR="$IP" NETMASK="${mask}"
IPADDR="${ip}"
EOT EOT
if [ -n "$GATEWAY" ]; then if [ -n "$gateway" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then if [ "$config_path" = "/etc/sysconfig/network" ]; then
echo "default $GATEWAY - $DEV ${METRIC:+metric ${METRIC}}" \ echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \
>> "${CONFIG_PATH}/ifroute-${DEV}" >> "${config_path}/ifroute-${dev}"
else else
echo "default via $GATEWAY dev $DEV ${METRIC:+metric ${METRIC}}" \ echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \
>> "${CONFIG_PATH}/route-${DEV}" >> "${config_path}/route-${dev}"
fi fi
fi fi
if [ -n "$MTU" ]; then if [ -n "$mtu" ]; then
echo "MTU=$MTU" echo "MTU=${mtu}"
fi fi
} }
gen_dhcp_conf()
{
echo "BOOTPROTO=dhcp"
}
gen_alias_conf() { gen_alias_conf() {
cat <<EOT cat <<EOT
IPADDR${ALIAS_NUM}="${IP}" IPADDR${alias_num}="${ip}"
NETMASK${ALIAS_NUM}="${MASK}" NETMASK${alias_num}="${mask}"
EOT EOT
} }
gen_alias6_conf() { gen_iface6_conf()
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then {
echo "IPADDR_A6A${ALIAS_NUM}=$IP6/${IP6_PREFIX_LENGTH:-64}" if [ "$config_path" = "/etc/sysconfig/network" ]; then
else echo "IPADDR_6A=${ip6}/${ip6_prefix_length:-64}"
IPV6ADDR_SECONDARIES="${IPV6ADDR_SECONDARIES} ${IP6}/${IP6_PREFIX_LENGTH:-64}"
fi
if [ -n "$IP6_ULA" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6B${ALIAS_NUM}=$IP6_ULA/64"
else
IPV6ADDR_SECONDARIES="${IPV6ADDR_SECONDARIES} ${IP6_ULA}/64"
fi
fi
}
gen_iface6_conf() {
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6A=$IP6/${IP6_PREFIX_LENGTH:-64}"
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${DEV}" cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.autoconf = 0 net.ipv6.conf.\$SYSCTL_IF.autoconf = 0
net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0 net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0
EOT EOT
else else
cat <<EOT cat <<EOT
IPV6INIT=yes IPV6INIT=yes
IPV6ADDR=$IP6/${IP6_PREFIX_LENGTH:-64} IPV6ADDR=${ip6}/${ip6_prefix_length:-64}
IPV6_AUTOCONF=no IPV6_AUTOCONF=no
EOT EOT
fi fi
if [ -n "$IP6_ULA" ]; then if [ -n "$ip6_ula" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then if [ "$config_path" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6B=$IP6_ULA/64" echo "IPADDR_6B=${ip6_ula}/64"
else else
IPV6ADDR_SECONDARIES="${IPV6ADDR_SECONDARIES} ${IP6_ULA}/64" ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64"
fi fi
fi fi
if [ -n "$GATEWAY6" ]; then if [ -n "$gateway6" ]; then
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then if [ "$config_path" = "/etc/sysconfig/network" ]; then
echo "default $GATEWAY6 - $DEV" >> "/etc/sysconfig/network/ifroute-${DEV}" echo "default ${gateway6} - ${dev}" >> "/etc/sysconfig/network/ifroute-${dev}"
else else
echo "IPV6_DEFAULTGW=$GATEWAY6" echo "IPV6_DEFAULTGW=${gateway6}"
fi fi
fi fi
if [ -n "$MTU" ]; then if [ -n "${mtu}" ]; then
echo "IPV6_MTU=$MTU" echo "IPV6_MTU=${mtu}"
fi
}
gen_dhcp6_conf()
{
cat <<EOT
IPV6INIT=yes
IPV6_AUTOCONF=no
DHCPV6C=yes
EOT
}
gen_alias6_conf()
{
if [ "$config_path" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6A${alias_num}=${ip6}/${ip6_prefix_length:-64}"
else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6}/${ip6_prefix_length:-64}"
fi
if [ -n "$ip6_ula" ]; then
if [ "$config_path" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6B${alias_num}=${ip6_ula}/64"
else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64"
fi
fi fi
} }
gen_network_configuration() gen_network_configuration()
{ {
if [ -d /etc/sysconfig/network-scripts ]; then if [ -d /etc/sysconfig/network-scripts ]; then
CONFIG_PATH=/etc/sysconfig/network-scripts config_path=/etc/sysconfig/network-scripts
elif [ -d /etc/sysconfig/network ]; then elif [ -d /etc/sysconfig/network ]; then
CONFIG_PATH=/etc/sysconfig/network config_path=/etc/sysconfig/network
fi fi
INTERFACE_MAC=$(get_interface_mac) _context_interfaces=$(get_context_interfaces)
CONTEXT_INTERFACES=$(get_context_interfaces)
for iface in $CONTEXT_INTERFACES; do
MAC=$(get_iface_var "$iface" "MAC")
DEV=$(get_dev "$INTERFACE_MAC" "$MAC")
IP=$(get_ip "$iface") for _iface in $_context_interfaces; do
MASK=$(get_mask "$iface") setup_iface_vars "$_iface"
MTU=$(get_mtu "$iface")
GATEWAY=$(get_gateway "$iface")
METRIC=$(get_iface_var "$iface" "METRIC")
IP6=$(get_iface_var "$iface" "IP6") skip_interface && continue
[ -z "$IP6" ] && IP6=$(get_iface_var "$iface" "IPV6")
IP6_PREFIX_LENGTH=$(get_iface_var "$iface" "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "$iface" "IP6_ULA")
GATEWAY6=$(get_gateway6 "$iface")
# cumulative variable # cumulative variable
IPV6ADDR_SECONDARIES='' ipv6addr_secondaries=''
[ -z "${IP}${IP6}" ] && continue
[ -z "${DEV}" ] && continue
{ {
rm -f "/etc/sysconfig/network-scripts/route-${DEV}" rm -f "/etc/sysconfig/network-scripts/route-${dev}"
rm -f "/etc/sysconfig/network/ifroute-${DEV}" rm -f "/etc/sysconfig/network/ifroute-${dev}"
rm -f "/etc/sysconfig/network/ifsysctl-${DEV}" rm -f "/etc/sysconfig/network/ifsysctl-${dev}"
cat <<EOT cat <<EOT
DEVICE=$DEV DEVICE=${dev}
BOOTPROTO=static
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
EOT EOT
if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then if [ "$config_path" = "/etc/sysconfig/network" ]; then
echo "STARTMODE=auto" echo "STARTMODE=auto"
else else
echo "ONBOOT=yes" echo "ONBOOT=yes"
fi fi
[ -n "${IP}" ] && gen_iface_conf if is_true "${dhcp}" ; then
[ -n "${IP6}" ] && gen_iface6_conf gen_dhcp_conf
elif [ -n "${ip}" ] ; then
ALIASES=$(get_interface_alias "$iface") gen_iface_conf
ALIAS_NUM=0 fi
for nic_alias in $ALIASES; do if is_true "${dhcp6}" ; then
IP=$(get_ip "$nic_alias") gen_dhcp6_conf
MASK=$(get_mask "$nic_alias") elif [ -n "${ip6}" ] ; then
gen_iface6_conf
fi
IP6=$(get_iface_var "$nic_alias" "IP6") _aliases=$(get_interface_alias "$_iface")
[ -z "$IP6" ] && IP6=$(get_iface_var "$nic_alias" "IPV6") alias_num=0
IP6_PREFIX_LENGTH=$(get_iface_var "$nic_alias" "IP6_PREFIX_LENGTH")
IP6_ULA=$(get_iface_var "$nic_alias" "IP6_ULA")
EXTERNAL=$(get_iface_var "$nic_alias" "EXTERNAL") for _nic_alias in $_aliases; do
EXTERNAL=${EXTERNAL^^} setup_ipadr_vars "$_nic_alias"
DETACH=$(get_iface_var "$nic_alias" "DETACH") setup_ip6adr_vars "$_nic_alias"
setup_alias_vars "$_nic_alias"
if [ -z "${DETACH}" ]; then if [ -z "${detach}" ]; then
if [ -z "${EXTERNAL}" ] || [ "${EXTERNAL}" = "NO" ]; then if ! is_true "${external}" ; then
[ -n "${IP}" ] && gen_alias_conf [ -n "${ip}" ] && gen_alias_conf
[ -n "${IP6}" ] && gen_alias6_conf [ -n "${ip6}" ] && gen_alias6_conf
if [ -n "${IP}${IP6}" ]; then if [ -n "${ip}${ip6}" ]; then
ALIAS_NUM=$((ALIAS_NUM + 1)) alias_num=$((alias_num + 1))
fi fi
fi fi
fi fi
@ -219,14 +249,13 @@ EOT
# on Red Hats, we need just a single configuration # on Red Hats, we need just a single configuration
# entry with all additional IPv6 addresses # entry with all additional IPv6 addresses
if [ -n "${IPV6ADDR_SECONDARIES}" ]; then if [ -n "${ipv6addr_secondaries}" ]; then
echo "IPV6ADDR_SECONDARIES='${IPV6ADDR_SECONDARIES## }'" echo "IPV6ADDR_SECONDARIES='${ipv6addr_secondaries## }'"
fi fi
} > "${CONFIG_PATH}/ifcfg-${DEV}" } > "${config_path}/ifcfg-${dev}"
# TODO: do we want this here? # TODO: do we want this here?
ifup "${DEV}" ifup "${dev}"
done done
} }

@ -1,63 +0,0 @@
#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
export DNS_VARIABLES="DNS $(env | sed 's/=.*$//' | grep -E '^ETH[0-9]+_DNS$' | sort)"
export SEARCH_VARIABLES="SEARCH_DOMAIN $(env | sed 's/=.*$//' | grep -E '^ETH[0-9]+_SEARCH_DOMAIN$' | sort)"
nameservers=$(
for var in ${DNS_VARIABLES}; do
value=$(eval "echo \"\${$var}\"")
if [ -n "$value" ]; then
echo "$value"
fi
done
)
searchdomains=$(
for var in ${SEARCH_VARIABLES}; do
value=$(eval "echo \"\${$var}\"")
if [ -n "$value" ]; then
echo "$value"
fi
done
)
[ -z "$nameservers" ] && exit 0
if [ -L /etc/resolv.conf ]; then
unlink /etc/resolv.conf
else
echo -n '' > /etc/resolv.conf
fi
for nameserver in $nameservers; do
echo nameserver $nameserver >> /etc/resolv.conf
done
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=\"$nameservers\"/" /etc/sysconfig/network/config
fi
[ -z "$searchdomains" ] && exit 0
echo search $searchdomains >> /etc/resolv.conf
if [ -f /etc/sysconfig/network/config ]; then
sed -i "/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=\"$searchdomains\"/" /etc/sysconfig/network/config
fi

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
get_management_interfaces() { get_management_interfaces() {
env | grep -E "^ETH[0-9]+_VROUTER_MANAGEMENT=YES" | sed 's/_.*$//' | tr 'ETH' 'eth' | sort env | grep -E "^ETH[0-9]+_VROUTER_MANAGEMENT=YES" | sed 's/_.*$//' | tr 'ETH' 'eth' | sort
} }
@ -81,7 +86,7 @@ gen_footer
) > /etc/iptables/rules-save ) > /etc/iptables/rules-save
if [ "$1" == "reconfigure" ]; then if [ "$2" == "reconfigure" ]; then
reload_service reload_service
else else
rc-update add iptables boot rc-update add iptables boot

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
activate_swaps_linux() { activate_swaps_linux() {
SWAP_DRIVES=$(blkid -t TYPE="swap" -o device) SWAP_DRIVES=$(blkid -t TYPE="swap" -o device)
for SWAP in $SWAP_DRIVES ; do for SWAP in $SWAP_DRIVES ; do

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
if [ -z "${VROUTER_ID}${VROUTER_KEEPALIVED_ID}" ]; then if [ -z "${VROUTER_ID}${VROUTER_KEEPALIVED_ID}" ]; then
if [ -f /etc/sysctl.d/01-one.conf ]; then if [ -f /etc/sysctl.d/01-one.conf ]; then
unlink /etc/sysctl.d/01-one.conf unlink /etc/sysctl.d/01-one.conf

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
get_context_interfaces() { get_context_interfaces() {
env | grep -E "^ETH[0-9]+_VROUTER_IP=" | sed 's/_.*$//' | sort env | grep -E "^ETH[0-9]+_VROUTER_IP=" | sed 's/_.*$//' | sort
} }
@ -181,7 +186,7 @@ gen_instances
) > /etc/keepalived/keepalived.conf ) > /etc/keepalived/keepalived.conf
if [ "$1" == "reconfigure" ]; then if [ "$2" == "reconfigure" ]; then
reload_service reload_service
else else
rc-update add keepalived boot rc-update add keepalived boot

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
ENV_FILE=/var/run/one-context/one_env ENV_FILE=/var/run/one-context/one_env
MOUNT_DIR="${MOUNT_DIR:-/mnt}" MOUNT_DIR="${MOUNT_DIR:-/mnt}"
TOKEN_FILE="${MOUNT_DIR}/token.txt" TOKEN_FILE="${MOUNT_DIR}/token.txt"

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# defaults # defaults
USERNAME=${USERNAME:-root} USERNAME=${USERNAME:-root}
USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}} USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}}

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
[ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0 [ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0
if [ -z "${USERNAME}" ] if [ -z "${USERNAME}" ]

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
if ssh-keygen -A; then if ssh-keygen -A; then
if type restorecon >/dev/null 2>&1; then if type restorecon >/dev/null 2>&1; then

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
# Linux # Linux
for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do
TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}" TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}"

@ -16,6 +16,11 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# THIS IS A CONTEXTUALIZATION GUARD
if [ "$1" != 'local' ] ; then
exit 0
fi
_pam_file="/etc/pam.d/login" _pam_file="/etc/pam.d/login"
if [ ! -f "${_pam_file}" ]; then if [ ! -f "${_pam_file}" ]; then
exit 0 exit 0

@ -1,8 +1,8 @@
[Unit] [Unit]
Description=OpenNebula pre-networking contextualization script Description=OpenNebula pre-networking contextualization script
DefaultDependencies=no DefaultDependencies=no
Before=network-pre.target
Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target
Before=network-pre.target
After=local-fs.target systemd-udev-settle.service syslog.target After=local-fs.target systemd-udev-settle.service syslog.target
ConditionPathExists=!/var/run/one-context/context.sh.local ConditionPathExists=!/var/run/one-context/context.sh.local

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=OpenNebula pre-networking contextualization script Description=OpenNebula pre-networking contextualization script
Before=network-pre.target
Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target
Before=network-pre.target
After=local-fs.target systemd-udev-settle.service syslog.target After=local-fs.target systemd-udev-settle.service syslog.target
ConditionPathExists=!/var/run/one-context/context.sh.local ConditionPathExists=!/var/run/one-context/context.sh.local

@ -0,0 +1,17 @@
[Unit]
Description=OpenNebula early-networking contextualization script
Wants=one-context-local.service
Wants=NetworkManager.service
After=one-context-local.service
After=NetworkManager.service
Before=network-online.target
Before=NetworkManager-wait-online.service
ConditionPathExists=!/var/run/one-context/context.sh.online
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/one-contextd online
[Install]
WantedBy=network-online.target

@ -18,8 +18,8 @@
set -e set -e
TYPE="${1:-all}" # local, network, all TYPE="${1:-all}" # local, online, network, all
COMMAND="${2}" # reconfigure? COMMAND="${2}" # force, reconfigure?
SCRIPTS_DIR="${SCRIPTS_DIR:-/etc/one-context.d}" SCRIPTS_DIR="${SCRIPTS_DIR:-/etc/one-context.d}"
RUNTIME_DIR="${RUNTIME_DIR:-/var/run/one-context}" RUNTIME_DIR="${RUNTIME_DIR:-/var/run/one-context}"
@ -93,38 +93,36 @@ function export_rc_vars
} }
function execute_scripts { function execute_scripts {
local _type=$1 local _type="$1"
local _command=$2 local _command="$2"
# choose # choose
if [ "${_type}" = 'local' ]; then case "${_type}" in
local _scripts=$(find "${SCRIPTS_DIR}" \ local|online)
-maxdepth 1 -mindepth 1 \ local _scripts=$(find "${SCRIPTS_DIR}" \
-name 'loc-*' \ -maxdepth 1 -mindepth 1 -type f \
2>/dev/null) -name 'loc-*' \
elif [ "${_type}" = 'network' ]; then 2>/dev/null | sort)
local _scripts=$(find "${SCRIPTS_DIR}" \ ;;
-maxdepth 1 -mindepth 1 \ network)
\! \( -name 'net-*' -o -name 'loc-*' \) \ local _scripts=$(find "${SCRIPTS_DIR}" \
-o -name 'net-*' \ -maxdepth 1 -mindepth 1 -type f \
2>/dev/null) \! \( -name 'net-*' -o -name 'loc-*' \) \
fi -o -name 'net-*' \
2>/dev/null | sort)
;;
esac
export MOUNT_DIR export MOUNT_DIR
export RUNTIME_DIR export RUNTIME_DIR
log info "Processing ${_type} scripts" log info "Processing ${_type} scripts"
for _script in ${_scripts}; do for _script in ${_scripts}; do
if [ -d "${_script}" ] ; then
# skip loc-10-network.d and similar
continue
fi
local _name=$(basename "${_script}") local _name=$(basename "${_script}")
# run script and catch output and exit code # run script and catch output and exit code
log debug "Script ${_name}: Starting ..." log debug "Script ${_name}: Starting ..."
_out=$("${_script}" "${_command}" 2>&1) _out=$("${_script}" "${_type}" "${_command}" 2>&1)
local _rtn=$? local _rtn=$?
# log on any output # log on any output
@ -346,7 +344,7 @@ function cleanup {
##### #####
if ! [[ ${TYPE} =~ ^(local|network|all)$ ]]; then if ! [[ ${TYPE} =~ ^(local|online|network|all)$ ]]; then
log err "Error: Invalid or missing execution type ${TYPE}" 2 log err "Error: Invalid or missing execution type ${TYPE}" 2
exit 1 exit 1
fi fi
@ -367,6 +365,7 @@ get_new_context
if [ "${TYPE}" = 'all' ]; then if [ "${TYPE}" = 'all' ]; then
run_context 'local' "${COMMAND}" run_context 'local' "${COMMAND}"
run_context 'online' "${COMMAND}"
run_context 'network' "${COMMAND}" run_context 'network' "${COMMAND}"
else else
run_context "${TYPE}" "${COMMAND}" run_context "${TYPE}" "${COMMAND}"

@ -37,7 +37,7 @@ case "${TARGET}" in
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-.el6} RELSUFFIX=${RELSUFFIX:-.el6}
TYPE=${TYPE:-rpm} TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm sysv one network-scripts} TAGS=${TAGS:-linux rpm sysv one network-scripts}
DEPENDS=${DEPENDS:-util-linux-ng bash curl bind-utils cloud-utils-growpart dracut-modules-growroot parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent gawk} DEPENDS=${DEPENDS:-util-linux-ng bash curl bind-utils cloud-utils-growpart dracut-modules-growroot parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init} REPLACES=${REPLACES:-cloud-init}
@ -48,27 +48,11 @@ case "${TARGET}" in
POSTUP=${POSTUP:-pkg/postupgrade} POSTUP=${POSTUP:-pkg/postupgrade}
;; ;;
'el6_ec2')
NAME=${NAME:-one-context-ec2}
RELSUFFIX=${RELSUFFIX:-.el6}
TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm sysv ec2 network-scripts}
DEPENDS=${DEPENDS:-util-linux-ng bash curl bind-utils cloud-utils-growpart dracut-modules-growroot parted ruby rubygem-json sudo shadow-utils openssh-server gawk}
PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init}
CONFLICTS=${CONFLICTS:-${REPLACES} one-context}
POSTIN=${POSTINST:-pkg/postinstall.ec2 pkg/postinstall}
PREUN=${PREUN:-pkg/preuninstall.ec2 pkg/preuninstall}
POSTUN=${POSTUN:-pkg/postuninstall}
POSTUP=${POSTUP:-pkg/postupgrade}
;;
'el7') 'el7')
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-.el7} RELSUFFIX=${RELSUFFIX:-.el7}
TYPE=${TYPE:-rpm} TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd one network-scripts} TAGS=${TAGS:-linux rpm systemd one network-scripts}
DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent gawk} DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init} REPLACES=${REPLACES:-cloud-init}
@ -79,26 +63,11 @@ case "${TARGET}" in
POSTUP=${POSTUP:-pkg/postupgrade} POSTUP=${POSTUP:-pkg/postupgrade}
;; ;;
'el7_ec2')
NAME=${NAME:-one-context-ec2}
RELSUFFIX=${RELSUFFIX:-.el7}
TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd ec2 network-scripts}
DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server gawk}
PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init}
CONFLICTS=${CONFLICTS:-${REPLACES} one-context}
POSTIN=${POSTINST:-pkg/postinstall.ec2 pkg/postinstall}
PREUN=${PREUN:-pkg/preuninstall.ec2 pkg/preuninstall}
POSTUN=${POSTUN:-pkg/postuninstall}
POSTUP=${POSTUP:-pkg/postupgrade}
;;
'el8') 'el8')
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-.el8} RELSUFFIX=${RELSUFFIX:-.el8}
TYPE=${TYPE:-rpm} TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd one network-scripts} TAGS=${TAGS:-linux rpm systemd one network-scripts}
DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent network-scripts gawk} DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent network-scripts gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init} REPLACES=${REPLACES:-cloud-init}
@ -109,26 +78,11 @@ case "${TARGET}" in
POSTUP=${POSTUP:-pkg/postupgrade} POSTUP=${POSTUP:-pkg/postupgrade}
;; ;;
'el8_ec2')
NAME=${NAME:-one-context-ec2}
RELSUFFIX=${RELSUFFIX:-.el8}
TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd ec2 network-scripts}
DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server network-scripts gawk}
PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init}
CONFLICTS=${CONFLICTS:-${REPLACES} one-context}
POSTIN=${POSTINST:-pkg/postinstall.ec2 pkg/postinstall}
PREUN=${PREUN:-pkg/preuninstall.ec2 pkg/preuninstall}
POSTUN=${POSTUN:-pkg/postuninstall}
POSTUP=${POSTUP:-pkg/postupgrade}
;;
'alt') 'alt')
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-alt} RELSUFFIX=${RELSUFFIX:-alt}
TYPE=${TYPE:-rpm} TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd one networkd} TAGS=${TAGS:-linux rpm systemd one networkd}
DEPENDS=${DEPENDS:-bind-utils btrfs-progs cloud-utils-growpart curl e2fsprogs iproute2 openssl parted passwd qemu-guest-agent open-vm-tools ruby-json-pure sudo systemd-services wget which xfsprogs gawk} DEPENDS=${DEPENDS:-bind-utils btrfs-progs cloud-utils-growpart curl e2fsprogs iproute2 openssl parted passwd qemu-guest-agent open-vm-tools ruby-json-pure sudo systemd-services wget which xfsprogs gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init} REPLACES=${REPLACES:-cloud-init}
@ -144,7 +98,7 @@ case "${TARGET}" in
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-.suse} RELSUFFIX=${RELSUFFIX:-.suse}
TYPE=${TYPE:-rpm} TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd one network-scripts} TAGS=${TAGS:-linux rpm systemd one network-scripts}
DEPENDS=${DEPENDS:-util-linux bash curl bind-utils growpart parted parted ruby sudo shadow openssh open-vm-tools qemu-guest-agent gawk} # rubygem-json} DEPENDS=${DEPENDS:-util-linux bash curl bind-utils growpart parted parted ruby sudo shadow openssh open-vm-tools qemu-guest-agent gawk} # rubygem-json}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init cloud-init-config-suse} REPLACES=${REPLACES:-cloud-init cloud-init-config-suse}
@ -155,27 +109,11 @@ case "${TARGET}" in
POSTUP=${POSTUP:-pkg/postupgrade} POSTUP=${POSTUP:-pkg/postupgrade}
;; ;;
'suse_ec2')
NAME=${NAME:-one-context-ec2}
RELSUFFIX=${RELSUFFIX:-.suse}
TYPE=${TYPE:-rpm}
TAGS=${TAGS:-rpm systemd ec2 network-scripts}
DEPENDS=${DEPENDS:-util-linux bash curl bind-utils growpart parted ruby sudo shadow openssh gawk} # rubygem-json}
PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init cloud-init-config-suse}
CONFLICTS=${CONFLICTS:-${REPLACES} one-context}
POSTIN=${POSTINST:-pkg/postinstall.ec2 pkg/postinstall}
PREUN=${PREUN:-pkg/preuninstall.ec2 pkg/preuninstall}
POSTUN=${POSTUN:-pkg/postuninstall}
POSTUP=${POSTUP:-pkg/postupgrade}
;;
'deb') 'deb')
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-} RELSUFFIX=${RELSUFFIX:-}
TYPE=${TYPE:-deb} TYPE=${TYPE:-deb}
TAGS=${TAGS:-deb sysv systemd upstart one} TAGS=${TAGS:-linux deb sysv systemd upstart one}
DEPENDS=${DEPENDS:-util-linux bash curl bind9-host cloud-utils parted ruby ifupdown|ifupdown2 acpid sudo passwd dbus openssh-server open-vm-tools qemu-guest-agent gawk} DEPENDS=${DEPENDS:-util-linux bash curl bind9-host cloud-utils parted ruby ifupdown|ifupdown2 acpid sudo passwd dbus openssh-server open-vm-tools qemu-guest-agent gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init} REPLACES=${REPLACES:-cloud-init}
@ -186,26 +124,11 @@ case "${TARGET}" in
POSTUP=${POSTUP:-pkg/postupgrade} POSTUP=${POSTUP:-pkg/postupgrade}
;; ;;
'deb_ec2')
NAME=${NAME:-one-context-ec2}
RELSUFFIX=${RELSUFFIX:-}
TYPE=${TYPE:-deb}
TAGS=${TAGS:-deb sysv systemd upstart ec2}
DEPENDS=${DEPENDS:-util-linux bash curl bind9-host cloud-utils parted ruby ifupdown|ifupdown2 sudo passwd dbus openssh-server resolvconf gawk}
PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-cloud-init}
CONFLICTS=${CONFLICTS:-${REPLACES} one-context}
POSTIN=${POSTINST:-pkg/postinstall.ec2 pkg/postinstall}
PREUN=${PREUN:-pkg/preuninstall.ec2 pkg/preuninstall}
POSTUN=${POSTUN:-pkg/postuninstall}
POSTUP=${POSTUP:-pkg/postupgrade}
;;
'alpine') 'alpine')
NAME=${NAME:-one-context} NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-} RELSUFFIX=${RELSUFFIX:-}
TYPE=${TYPE:-apk} TYPE=${TYPE:-apk}
TAGS=${TAGS:-apk one} TAGS=${TAGS:-linux apk one}
DEPENDS=${DEPENDS:-util-linux bash curl udev sfdisk parted e2fsprogs-extra sudo shadow ruby ruby-json bind-tools openssh open-vm-tools qemu-guest-agent gawk} DEPENDS=${DEPENDS:-util-linux bash curl udev sfdisk parted e2fsprogs-extra sudo shadow ruby ruby-json bind-tools openssh open-vm-tools qemu-guest-agent gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-} #not respected REPLACES=${REPLACES:-} #not respected
@ -216,21 +139,6 @@ case "${TARGET}" in
POSTUP=${POSTUP:-} # FPM 1.9.3 bug: https://github.com/jordansissel/fpm/blob/v1.9.3/lib/fpm/package/apk.rb#L149 POSTUP=${POSTUP:-} # FPM 1.9.3 bug: https://github.com/jordansissel/fpm/blob/v1.9.3/lib/fpm/package/apk.rb#L149
;; ;;
'alpine_ec2')
NAME=${NAME:-one-context-ec2}
RELSUFFIX=${RELSUFFIX:-}
TYPE=${TYPE:-apk}
TAGS=${TAGS:-apk ec2}
DEPENDS=${DEPENDS:-util-linux bash curl udev sfdisk parted e2fsprogs-extra sudo shadow ruby ruby-json bind-tools openssh gawk}
PROVIDES=${PROVIDES:-}
REPLACES=${REPLACES:-} #not respected
CONFLICTS=${CONFLICTS:-one-context}
POSTIN=${POSTINST:-pkg/postinstall.ec2 pkg/postinstall}
PREUN=${PREUN:-pkg/preuninstall.ec2 pkg/preuninstall}
POSTUN=${POSTUN:-pkg/postuninstall}
POSTUP=${POSTUP:-} # FPM 1.9.3 bug: https://github.com/jordansissel/fpm/blob/v1.9.3/lib/fpm/package/apk.rb#L149
;;
'iso') 'iso')
NAME=${NAME:-one-context-linux} NAME=${NAME:-one-context-linux}
TYPE=${TYPE:-iso} TYPE=${TYPE:-iso}
@ -241,7 +149,7 @@ case "${TARGET}" in
RELSUFFIX=${RELSUFFIX:-} RELSUFFIX=${RELSUFFIX:-}
TYPE=${TYPE:-pacman} TYPE=${TYPE:-pacman}
EXT=${EXT:-pkg.tar.xz} EXT=${EXT:-pkg.tar.xz}
TAGS=${TAGS:-arch systemd one networkd} TAGS=${TAGS:-linux arch systemd one networkd}
# mkinitcpio-growrootfs ruby-json # mkinitcpio-growrootfs ruby-json
DEPENDS=${DEPENDS:-filesystem util-linux bash curl bind-tools ruby sudo shadow open-vm-tools qemu-guest-agent gawk} DEPENDS=${DEPENDS:-filesystem util-linux bash curl bind-tools ruby sudo shadow open-vm-tools qemu-guest-agent gawk}
PROVIDES=${PROVIDES:-} PROVIDES=${PROVIDES:-}

Loading…
Cancel
Save