From 914ceae299d642328056ff29691ca82c4656906c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ospal=C3=BD?= Date: Fri, 23 Jul 2021 16:59:22 +0200 Subject: [PATCH] F #227: Refactor loc-10-network Deprecate EC2 Introduce one-context-online service Support NetPlan, NetworkManager Various fixes DHCP WIP --- generate.sh | 27 +- pkg/postinstall | 41 +-- pkg/postinstall.ec2 | 4 - pkg/preuninstall | 2 +- pkg/preuninstall.ec2 | 3 - .../conf.d/opennebula.conf##linux.one | 3 + src/etc/one-context.d/loc-04-run-dir | 5 + src/etc/one-context.d/loc-05-grow-rootfs | 5 + src/etc/one-context.d/loc-09-timezone | 5 + src/etc/one-context.d/loc-10-network | 57 ++-- src/etc/one-context.d/loc-10-network-pci##one | 5 + .../one-context.d/loc-10-network.d/functions | 221 ++++++++++++--- .../one-context.d/loc-10-network.d/netcfg-bsd | 199 +++++++------ .../loc-10-network.d/netcfg-interfaces | 267 ++++++++++-------- .../loc-10-network.d/netcfg-netplan | 220 +++++++++++++++ .../loc-10-network.d/netcfg-networkd | 242 ++++++++-------- .../one-context.d/loc-10-network.d/netcfg-nm | 223 +++++++++++++++ .../loc-10-network.d/netcfg-scripts | 247 +++++++++------- src/etc/one-context.d/loc-11-dns##one | 63 ----- src/etc/one-context.d/loc-12-firewall##vr | 7 +- src/etc/one-context.d/loc-14-mount-swap##one | 5 + src/etc/one-context.d/loc-15-ip_forward##vr | 5 + src/etc/one-context.d/loc-15-keepalived##vr | 7 +- src/etc/one-context.d/loc-16-gen-env | 5 + .../loc-20-set-username-password | 5 + src/etc/one-context.d/loc-22-ssh_public_key | 5 + .../one-context.d/loc-24-ssh_host_key##deb | 5 + src/etc/one-context.d/loc-30-console##one | 5 + src/etc/one-context.d/loc-35-securetty | 5 + ...one-context-local.service##deb.systemd.one | 2 +- ...one-context-local.service##rpm.systemd.one | 2 +- .../one-context-online.service##systemd.one | 17 ++ src/usr/sbin/one-contextd | 45 ++- targets.sh | 108 +------ 34 files changed, 1331 insertions(+), 736 deletions(-) delete mode 100755 pkg/postinstall.ec2 delete mode 100755 pkg/preuninstall.ec2 create mode 100644 src/etc/NetworkManager/conf.d/opennebula.conf##linux.one create mode 100644 src/etc/one-context.d/loc-10-network.d/netcfg-netplan create mode 100644 src/etc/one-context.d/loc-10-network.d/netcfg-nm delete mode 100755 src/etc/one-context.d/loc-11-dns##one create mode 100644 src/usr/lib/systemd/system/one-context-online.service##systemd.one diff --git a/generate.sh b/generate.sh index 5dc2eb9..6aaf43b 100755 --- a/generate.sh +++ b/generate.sh @@ -16,6 +16,8 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# shellcheck disable=SC1091 + if [ -z "${TARGET}" ]; then echo 'Error: env. variable TARGET not set' >&2 exit 1 @@ -28,7 +30,7 @@ set +e ### 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 else DATE=${DATE:-$(date +%Y%m%d)} @@ -90,12 +92,14 @@ _PREUN=$(mktemp) _POSTUN=$(mktemp) _POSTUP=$(mktemp) +# shellcheck disable=SC2064 trap "rm -rf ${UNAME_PATH} ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT while IFS= read -r -d $'\0' SRC; do F_TAGS=${SRC##*##} 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 if [ "${F_TAG}" = "${TAG}" ]; then 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}" done < <(cd src/ && find . -type f -print0) -for F in $@; do +for F in "$@"; do cp -r "$F" "${BUILD_DIR}/" done @@ -123,7 +127,8 @@ umask 0022 # cleanup if [ -z "${OUT}" ]; then OUT="out/${FILENAME}" - mkdir -p $(dirname "${OUT}") + _out_dir=$(dirname "${OUT}") + mkdir -p "${_out_dir}" rm -rf "${OUT}" fi @@ -144,11 +149,12 @@ if [ "${TYPE}" = 'dir' ]; then cp -rT "${BUILD_DIR}" "${OUT}" elif [ "${TYPE}" = 'iso' ]; then + _out_dir=$(dirname "${OUT}") mkisofs -J -R -input-charset utf8 \ -m '*.iso' \ -V "${LABEL}" \ -o "${OUT}" \ - $(dirname "${OUT}") + "${_out_dir}" else CONFIG_FILES=$(cd "${BUILD_DIR}" && \ @@ -159,25 +165,26 @@ else # concatenate pre/postinstall scripts if [ -n "${POSTIN}" ]; then - cat ${POSTIN} >"${_POSTIN}" + cat "${POSTIN}" >"${_POSTIN}" fi if [ -n "${PREUN}" ]; then - cat ${PREUN} >"${_PREUN}" + cat "${PREUN}" >"${_PREUN}" fi if [ -n "${POSTUN}" ]; then - cat ${POSTUN} >"${_POSTUN}" + cat "${POSTUN}" >"${_POSTUN}" fi if [ -n "${POSTUP}" ]; then - cat ${POSTUP} >"${_POSTUP}" + cat "${POSTUP}" >"${_POSTUP}" fi # set the package version of onesysprep sed -i "s/\<_PACKAGE_VERSION_\>/${VERSION}/" \ "${BUILD_DIR}/usr/sbin/onesysprep" + # shellcheck disable=SC2086 fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \ --architecture all --license "${LICENSE}" \ --vendor "${VENDOR}" --maintainer "${MAINTAINER}" \ @@ -201,4 +208,4 @@ else --package "${OUT}" fi -echo $(basename ${OUT}) +basename "${OUT}" diff --git a/pkg/postinstall b/pkg/postinstall index fce52ae..f583d7c 100755 --- a/pkg/postinstall +++ b/pkg/postinstall @@ -1,8 +1,7 @@ #!/usr/bin/env bash NETWORK=${NETWORK:-yes} -NETWORK_EC2=${NETWORK_EC2:-no} -SERVICES=${SERVICES:-one-context-local one-context} +SERVICES=${SERVICES:-one-context-local one-context-online one-context} rm -f /etc/udev/rules.d/70-persistent-cd.rules rm -f /etc/udev/rules.d/70-persistent-net.rules @@ -65,26 +64,15 @@ fi # Debian based distros if [ -d /etc/network ]; then # 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/netplan/* - if [ "${NETWORK_EC2}" = 'yes' ]; then - cat > /etc/network/interfaces < /etc/network/interfaces < /etc/network/interfaces </etc/sysconfig/network-scripts/ifcfg-eth0 </etc/sysconfig/network/ifcfg-eth0 </dev/null 2>&1 && [ -d /etc/systemd ]; then diff --git a/pkg/preuninstall.ec2 b/pkg/preuninstall.ec2 deleted file mode 100755 index a824d52..0000000 --- a/pkg/preuninstall.ec2 +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -SERVICES='one-context' diff --git a/src/etc/NetworkManager/conf.d/opennebula.conf##linux.one b/src/etc/NetworkManager/conf.d/opennebula.conf##linux.one new file mode 100644 index 0000000..a64b9d6 --- /dev/null +++ b/src/etc/NetworkManager/conf.d/opennebula.conf##linux.one @@ -0,0 +1,3 @@ +[main] +no-auto-default=* +dns=none diff --git a/src/etc/one-context.d/loc-04-run-dir b/src/etc/one-context.d/loc-04-run-dir index e78a209..de1a8b5 100755 --- a/src/etc/one-context.d/loc-04-run-dir +++ b/src/etc/one-context.d/loc-04-run-dir @@ -18,6 +18,11 @@ set -e +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + # Umount the directory and remove it cleanup() { diff --git a/src/etc/one-context.d/loc-05-grow-rootfs b/src/etc/one-context.d/loc-05-grow-rootfs index 748563d..7b5aff5 100755 --- a/src/etc/one-context.d/loc-05-grow-rootfs +++ b/src/etc/one-context.d/loc-05-grow-rootfs @@ -20,6 +20,11 @@ set -e +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + GROW_ROOTFS=${GROW_ROOTFS:-YES} GROW_ROOTFS=${GROW_ROOTFS^^} #GROW_FS # list of mountpoints to resize diff --git a/src/etc/one-context.d/loc-09-timezone b/src/etc/one-context.d/loc-09-timezone index b6b9e65..c3b817f 100755 --- a/src/etc/one-context.d/loc-09-timezone +++ b/src/etc/one-context.d/loc-09-timezone @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + if [ -z "${TIMEZONE}" ]; then exit 0 fi diff --git a/src/etc/one-context.d/loc-10-network b/src/etc/one-context.d/loc-10-network index d8fe937..21be4a7 100755 --- a/src/etc/one-context.d/loc-10-network +++ b/src/etc/one-context.d/loc-10-network @@ -16,44 +16,47 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# shellcheck disable=SC1091,SC1090 + . /etc/one-context.d/loc-10-network.d/functions -ACTION="$1" -OS_ID=$(detect_os) +context_type="$1" +action="$2" +os_id=$(detect_os) -if [ -z "${ACTION}" ] ; then - ACTION="configure" +if [ -z "${action}" ] ; then + action="configure" fi -if [ -z "${CONTEXT_NETCFG_TYPE}" ] ; then - case "${OS_ID}" in +if [ -z "${NETCFG_TYPE}" ] ; then + case "${os_id}" in alpine) - CONTEXT_NETCFG_TYPE='interfaces' + NETCFG_TYPE='interfaces' ;; altlinux) - CONTEXT_NETCFG_TYPE='networkd' + NETCFG_TYPE='networkd nm' ;; - debian|ubuntu|devuan) - CONTEXT_NETCFG_TYPE='interfaces' + debian|devuan|ubuntu) + NETCFG_TYPE='interfaces netplan nm networkd' ;; fedora|centos|rhel|almalinux|ol|rocky) - CONTEXT_NETCFG_TYPE='scripts' + NETCFG_TYPE='scripts nm networkd' ;; opensuse*) - CONTEXT_NETCFG_TYPE='scripts' + NETCFG_TYPE='scripts nm networkd' ;; freebsd) - CONTEXT_NETCFG_TYPE='bsd' + NETCFG_TYPE='bsd' ;; *) - CONTEXT_NETCFG_TYPE='none' + NETCFG_TYPE='none' ;; esac fi -if [ "${CONTEXT_NETCFG_TYPE}" != 'none' ] ; then +if [ "${NETCFG_TYPE}" != 'none' ] ; then _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 . "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}" else @@ -67,16 +70,30 @@ if [ "${CONTEXT_NETCFG_TYPE}" != 'none' ] ; then fi 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 - 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 fi else # any action is meaningless without functioning network type - ACTION='none' + action='none' fi -case "$ACTION" in +case "$action" in none) echo "INFO: Network will not be configured" >&2 ;; @@ -88,7 +105,7 @@ case "$ACTION" in reload_network ;; *) - echo "ERROR [!]: Unknown ACTION: ${ACTION}" >&2 + echo "ERROR [!]: Unknown ACTION: ${action}" >&2 exit 1 ;; esac diff --git a/src/etc/one-context.d/loc-10-network-pci##one b/src/etc/one-context.d/loc-10-network-pci##one index 096c57c..d88269f 100755 --- a/src/etc/one-context.d/loc-10-network-pci##one +++ b/src/etc/one-context.d/loc-10-network-pci##one @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + get_iface_var() { var_name="${UPCASE_DEV}_$1" diff --git a/src/etc/one-context.d/loc-10-network.d/functions b/src/etc/one-context.d/loc-10-network.d/functions index 53133e2..e6ae59c 100644 --- a/src/etc/one-context.d/loc-10-network.d/functions +++ b/src/etc/one-context.d/loc-10-network.d/functions @@ -16,10 +16,14 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# shellcheck disable=SC2155 + # # network module interface # +export required_context_type='local' # this is the default, the next option is 'online' + is_network_supported() { false @@ -27,25 +31,25 @@ is_network_supported() 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 } 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 } 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 } 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 } @@ -53,6 +57,20 @@ reload_network() # 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 detect_os() ( @@ -66,81 +84,93 @@ detect_os() 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: get_iface_var() ( - iface=$(echo "$1" | tr '[:lower:]' '[:upper:]') - var_name="${iface}_${2}" - eval "echo \"\${${var_name}}\"" + _iface=$(echo "$1" | tr '[:lower:]' '[:upper:]') + _var_name="${_iface}_${2}" + eval "echo \"\${${_var_name}}\"" ) # Gets IP address from a given MAC mac2ip() ( - mac="$1" + _mac="$1" - ip_a=$(echo "$mac" | cut -d: -f 3) - ip_b=$(echo "$mac" | cut -d: -f 4) - ip_c=$(echo "$mac" | cut -d: -f 5) - ip_d=$(echo "$mac" | cut -d: -f 6) + _ip_a=$(echo "$_mac" | cut -d: -f 3) + _ip_b=$(echo "$_mac" | cut -d: -f 4) + _ip_c=$(echo "$_mac" | cut -d: -f 5) + _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() ( - mask="$1" - nbits=0 + _mask="$1" + _nbits=0 IFS=. - for dec in $mask ; do - case "$dec" in - 255) nbits=$((nbits + 8)) ;; - 254) nbits=$((nbits + 7)) ; break ;; - 252) nbits=$((nbits + 6)) ; break ;; - 248) nbits=$((nbits + 5)) ; break ;; - 240) nbits=$((nbits + 4)) ; break ;; - 224) nbits=$((nbits + 3)) ; break ;; - 192) nbits=$((nbits + 2)) ; break ;; - 128) nbits=$((nbits + 1)) ; break ;; + for _dec in $_mask ; do + case "$_dec" in + 255) _nbits=$((_nbits + 8)) ;; + 254) _nbits=$((_nbits + 7)) ; break ;; + 252) _nbits=$((_nbits + 6)) ; break ;; + 248) _nbits=$((_nbits + 5)) ; break ;; + 240) _nbits=$((_nbits + 4)) ; break ;; + 224) _nbits=$((_nbits + 3)) ; break ;; + 192) _nbits=$((_nbits + 2)) ; break ;; + 128) _nbits=$((_nbits + 1)) ; break ;; 0) break ;; - *) echo "Error: $dec is not recognised"; exit 1 ;; + *) echo "Error: $_dec is not recognised"; exit 1 ;; esac done - echo "$nbits" + echo "$_nbits" ) # Gets the network part of an IP # arg: get_network() ( - network=$(get_iface_var "$1" "NETWORK") + _network=$(get_iface_var "$1" "NETWORK") - if [ -z "$network" ]; then - ip=$(get_ip "$1") - mask=$(get_mask "$1") - network=$(awk -v ip="$ip" -v mask="$mask" 'END { + if [ -z "$_network" ]; then + _ip=$(get_ip "$1") + _mask=$(get_mask "$1") + _network=$(awk -v ip="$_ip" -v mask="$_mask" 'END { split(ip, ip_b, "."); split(mask, mask_b, "."); for (i=1; i<=4; ++i) x = x "." and(ip_b[i], mask_b[i]); sub(/^./, "", x); print x; }' get_mask() ( - mask=$(get_iface_var "$1" "MASK") - echo "${mask:-255.255.255.0}" + _mask=$(get_iface_var "$1" "MASK") + echo "${_mask:-255.255.255.0}" ) # Gets device MTU # arg: get_mtu() ( - mtu=$(get_iface_var "$1" "MTU") - echo "${mtu:-1500}" + _mtu=$(get_iface_var "$1" "MTU") + echo "${_mtu:-1500}" ) # Gets the network gateway @@ -178,17 +208,20 @@ get_search_domain() # arg: 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() ( - 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() ( - 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() @@ -198,9 +231,111 @@ get_interface_mac() get_dev() ( - list="$1" - mac="$2" + _list="$1" + _mac="$2" - echo "$list" | grep "$mac" | cut -d' ' -f1 | tail -n1 + echo "$_list" | grep "$_mac" | cut -d' ' -f1 | tail -n1 ) +# arg: +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: +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: +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: +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 +} diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-bsd b/src/etc/one-context.d/loc-10-network.d/netcfg-bsd index 805aef6..13f80b6 100644 --- a/src/etc/one-context.d/loc-10-network.d/netcfg-bsd +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-bsd @@ -22,7 +22,7 @@ is_network_supported() { - case "${OS_ID}" in + case "${os_id}" in freebsd) return 0 ;; @@ -33,7 +33,8 @@ is_network_supported() configure_network() { - gen_network_configuration >/etc/rc.conf.d/network + gen_resolvconf + gen_network_configuration > /etc/rc.conf.d/network } stop_network() @@ -58,138 +59,166 @@ reload_network() # 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() ( - macs=$(ifconfig | grep ether | awk '{print $2}') + _macs=$(ifconfig | grep ether | awk '{print $2}') - for mac in ${macs} ; do - iface=$(ifconfig | grep -B 2 "$mac" | head -n 1 | awk '{print $1}' | cut -d ':' -f 1) - echo "${iface} ${mac}" + for _mac in ${_macs} ; do + _iface=$(ifconfig | grep -B 2 "$_mac" | head -n 1 | awk '{print $1}' | cut -d ':' -f 1) + echo "${_iface} ${_mac}" done ) -gen_iface_conf() { - echo -n "ifconfig_${DEV}=\"inet ${IP} netmask ${MASK}" +gen_iface_conf() +{ + echo -n "ifconfig_${dev}=\"inet ${ip} netmask ${mask}" - if [ -n "${MTU}" ]; then - echo -n " mtu ${MTU}" + if [ -n "${mtu}" ]; then + echo -n " mtu ${mtu}" fi echo "\"" ### - if [ -n "${GATEWAY}" ]; then - echo "defaultrouter=\"${GATEWAY}\"" >> /etc/rc.conf.d/routing + if [ -n "${gateway}" ]; then + echo "defaultrouter=\"${gateway}\"" >> /etc/rc.conf.d/routing fi } -gen_alias_conf() { - echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet ${IP} netmask ${MASK}\"" - ALIAS_NUM=$((ALIAS_NUM + 1)) +gen_dhcp_conf() +{ + echo "ifconfig_${dev}=\"DHCP\"" } -gen_alias6_conf() { - # 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}" - - 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_alias_conf() +{ + echo "ifconfig_${dev}_alias${alias_num}=\"inet ${ip} netmask ${mask}\"" + alias_num=$((alias_num + 1)) } -gen_iface6_conf() { - echo -n "ifconfig_${DEV}_ipv6=\"inet6 ${IP6} prefixlen ${IP6_PREFIX_LENGTH:-64}" +gen_iface6_conf() +{ + echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}" - if [ -n "${MTU}" ]; then - echo -n " mtu ${MTU}" + if [ -n "${mtu}" ]; then + echo -n " mtu ${mtu}" fi echo " -accept_rtadv\"" - if [ -n "${IP6_ULA}" ]; then - echo "ifconfig_${DEV}_alias${ALIAS_NUM}=\"inet6 ${IP6_ULA} prefixlen 64\"" - ALIAS_NUM=$((ALIAS_NUM + 1)) + if [ -n "${ip6_ula}" ]; then + echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\"" + alias_num=$((alias_num + 1)) fi ### - if [ -n "${GATEWAY6}" ]; then - echo "ipv6_defaultrouter=\"${GATEWAY6}\"" >> /etc/rc.conf.d/routing + if [ -n "${gateway6}" ]; then + echo "ipv6_defaultrouter=\"${gateway6}\"" >> /etc/rc.conf.d/routing fi } -gen_network_configuration() +gen_dhcp6_conf() { - # clean routing information - echo -n > /etc/rc.conf.d/routing + # TODO: FreeBSD support for DHCP6 does not seem to be great: + # 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) - CONTEXT_INTERFACES=$(get_context_interfaces) +gen_alias6_conf() +{ + # 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 - MAC=$(get_iface_var "$iface" "MAC") - DEV=$(get_dev "$INTERFACE_MAC" "$MAC") + if [ -n "${mtu}" ]; then + echo -n " mtu ${mtu}" + fi - IP=$(get_ip "$iface") - MASK=$(get_mask "$iface") - MTU=$(get_mtu "$iface") - GATEWAY=$(get_gateway "$iface") - # TODO: not implemented - #METRIC=$(get_iface_var "$iface" "METRIC") + echo " -accept_rtadv\"" + fi - IP6=$(get_iface_var "$iface" "IP6") - [ -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") + if [ -n "${ip6_ula}" ]; then + echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\"" + alias_num=$((alias_num + 1)) + fi +} - [ -z "${IP}${IP6}" ] && continue - [ -z "${DEV}" ] && continue - HAS_IP6="${IP6}" +gen_network_configuration() +{ + # clean routing information + cat /dev/null > /etc/rc.conf.d/routing + + _context_interfaces=$(get_context_interfaces) - [ -n "${IP}" ] && gen_iface_conf - [ -n "${IP6}" ] && gen_iface6_conf + for _iface in $_context_interfaces; do + setup_iface_vars "$_iface" - ALIASES=$(get_interface_alias) - ALIAS_NUM=0 + skip_interface && continue - for nic_alias in $ALIASES; do - IP=$(get_ip "$nic_alias") - MASK=$(get_mask "$nic_alias") + 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 - IP6=$(get_iface_var "$nic_alias" "IP6") - [ -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") + has_ip6="${ip6}" + _aliases=$(get_interface_alias) + alias_num=0 - EXTERNAL=$(get_iface_var "$nic_alias" "EXTERNAL") - EXTERNAL=${EXTERNAL^^} - DETACH=$(get_iface_var "$nic_alias" "DETACH") + 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 [ -z "${EXTERNAL}" ] || [ "$EXTERNAL" = "NO" ]; then - [ -n "${IP}" ] && gen_alias_conf + if [ -z "${detach}" ]; then + if ! is_true "${external}" ; then + [ -n "${ip}" ] && gen_alias_conf - if [ -n "${IP6}" ]; then + if [ -n "${ip6}" ]; then gen_alias6_conf - HAS_IP6="${IP6}" + has_ip6="${ip6}" fi fi fi done done } - diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces b/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces index bbecbb3..49dda21 100644 --- a/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces @@ -22,7 +22,7 @@ is_network_supported() { - case "${OS_ID}" in + case "${os_id}" in alpine) return 0 ;; @@ -36,30 +36,32 @@ is_network_supported() configure_network() { + gen_resolvconf gen_network_configuration > /etc/network/interfaces - case "${OS_ID}" in + case "${os_id}" in debian|ubuntu|devuan) echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces ;; esac } -stop_network() { - case "${OS_ID}" in +stop_network() +{ + case "${os_id}" in alpine) service networking stop || true # took from find_ifaces in the networking service - IFACES=$(\ + _ifaces=$(\ awk '$1 == "auto" { for (i = 2; i <= NF; i = i + 1) printf("%s ", $i) }' /etc/network/interfaces) - for i in $IFACES; do - if [ "${i}" != 'lo' ]; then - /sbin/ip link set dev "${i}" down || true - /sbin/ip addr flush dev "${i}" || true + for _iface in $_ifaces; do + if [ "${_iface}" != 'lo' ]; then + /sbin/ip link set dev "${_iface}" down || true + /sbin/ip addr flush dev "${_iface}" || true fi done ;; @@ -68,12 +70,12 @@ stop_network() { return 0 fi - IFACES=$(/sbin/ifquery --list -a) + _ifaces=$(/sbin/ifquery --list -a) - for i in $IFACES; do - if [ "${i}" != 'lo' ] ; then - /sbin/ifdown "${i}" - /sbin/ip addr flush dev "${i}" + for _iface in $_ifaces; do + if [ "${_iface}" != 'lo' ] ; then + /sbin/ifdown "${_iface}" + /sbin/ip addr flush dev "${_iface}" fi done ;; @@ -83,8 +85,9 @@ stop_network() { esac } -start_network() { - case "${OS_ID}" in +start_network() +{ + case "${os_id}" in alpine) service networking start ;; @@ -94,10 +97,10 @@ start_network() { return 0 fi - IFACES=$(/sbin/ifquery --list -a) + _ifaces=$(/sbin/ifquery --list -a) - for i in $IFACES; do - /sbin/ifup "${i}" + for _iface in $_ifaces; do + /sbin/ifup "${_iface}" done ;; *) @@ -106,7 +109,8 @@ start_network() { esac } -reload_network() { +reload_network() +{ stop_network start_network } @@ -115,128 +119,164 @@ reload_network() { # 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() { cat < /proc/sys/net/ipv6/conf/${DEV}/autoconf - pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/accept_ra +iface ${dev} inet6 static + address ${ip6} + 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}/accept_ra EOT ;; debian|ubuntu|devuan) cat < /proc/sys/net/ipv6/conf/${DEV}/autoconf - pre-up echo 0 > /proc/sys/net/ipv6/conf/${DEV}/accept_ra +iface ${dev} inet6 static + address ${ip6} + 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}/accept_ra EOT ;; debian|ubuntu|devuan) cat </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 </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 </dev/null + + return $? } configure_network() { + gen_resolvconf gen_network_configuration } -stop_network() { +stop_network() +{ systemctl stop systemd-networkd.service } -start_network() { +start_network() +{ systemctl start systemd-networkd.service } -reload_network() { +reload_network() +{ systemctl restart systemd-networkd.service } @@ -58,41 +52,48 @@ reload_network() { # 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 < "/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 } - diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-nm b/src/etc/one-context.d/loc-10-network.d/netcfg-nm new file mode 100644 index 0000000..55585ea --- /dev/null +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-nm @@ -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: +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 +} diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-scripts b/src/etc/one-context.d/loc-10-network.d/netcfg-scripts index 8e7f5e3..4798b60 100644 --- a/src/etc/one-context.d/loc-10-network.d/netcfg-scripts +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-scripts @@ -22,32 +22,33 @@ is_network_supported() { - case "${OS_ID}" in - fedora|centos|rhel|almalinux|ol|rocky) - return 0 - ;; - opensuse*) - return 0 - ;; - esac + if [ -e /etc/sysconfig/network-scripts/ifup ] || \ + [ -e /etc/sysconfig/network/ifup ] ; + then + return 0 + fi return 1 } configure_network() { + gen_resolvconf gen_network_configuration } -stop_network() { +stop_network() +{ service network stop } -start_network() { +start_network() +{ service network start } -reload_network() { +reload_network() +{ service network restart } @@ -55,163 +56,192 @@ reload_network() { # 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 <> "${CONFIG_PATH}/ifroute-${DEV}" + if [ -n "$gateway" ]; then + if [ "$config_path" = "/etc/sysconfig/network" ]; then + echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \ + >> "${config_path}/ifroute-${dev}" else - echo "default via $GATEWAY dev $DEV ${METRIC:+metric ${METRIC}}" \ - >> "${CONFIG_PATH}/route-${DEV}" + echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \ + >> "${config_path}/route-${dev}" fi fi - if [ -n "$MTU" ]; then - echo "MTU=$MTU" + if [ -n "$mtu" ]; then + echo "MTU=${mtu}" fi } +gen_dhcp_conf() +{ + echo "BOOTPROTO=dhcp" +} + gen_alias_conf() { cat <> "/etc/sysconfig/network/ifsysctl-${DEV}" + cat <> "/etc/sysconfig/network/ifsysctl-${dev}" net.ipv6.conf.\$SYSCTL_IF.autoconf = 0 net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0 EOT else cat <> "/etc/sysconfig/network/ifroute-${DEV}" + if [ -n "$gateway6" ]; then + if [ "$config_path" = "/etc/sysconfig/network" ]; then + echo "default ${gateway6} - ${dev}" >> "/etc/sysconfig/network/ifroute-${dev}" else - echo "IPV6_DEFAULTGW=$GATEWAY6" + echo "IPV6_DEFAULTGW=${gateway6}" fi fi - if [ -n "$MTU" ]; then - echo "IPV6_MTU=$MTU" + if [ -n "${mtu}" ]; then + echo "IPV6_MTU=${mtu}" + fi +} + +gen_dhcp6_conf() +{ + cat < "${CONFIG_PATH}/ifcfg-${DEV}" + } > "${config_path}/ifcfg-${dev}" # TODO: do we want this here? - ifup "${DEV}" + ifup "${dev}" done } - diff --git a/src/etc/one-context.d/loc-11-dns##one b/src/etc/one-context.d/loc-11-dns##one deleted file mode 100755 index 99486b0..0000000 --- a/src/etc/one-context.d/loc-11-dns##one +++ /dev/null @@ -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 diff --git a/src/etc/one-context.d/loc-12-firewall##vr b/src/etc/one-context.d/loc-12-firewall##vr index e9496c8..5e06cb6 100755 --- a/src/etc/one-context.d/loc-12-firewall##vr +++ b/src/etc/one-context.d/loc-12-firewall##vr @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + get_management_interfaces() { 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 -if [ "$1" == "reconfigure" ]; then +if [ "$2" == "reconfigure" ]; then reload_service else rc-update add iptables boot diff --git a/src/etc/one-context.d/loc-14-mount-swap##one b/src/etc/one-context.d/loc-14-mount-swap##one index bcbdb1a..978b3b8 100755 --- a/src/etc/one-context.d/loc-14-mount-swap##one +++ b/src/etc/one-context.d/loc-14-mount-swap##one @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + activate_swaps_linux() { SWAP_DRIVES=$(blkid -t TYPE="swap" -o device) for SWAP in $SWAP_DRIVES ; do diff --git a/src/etc/one-context.d/loc-15-ip_forward##vr b/src/etc/one-context.d/loc-15-ip_forward##vr index 373e4af..4611484 100755 --- a/src/etc/one-context.d/loc-15-ip_forward##vr +++ b/src/etc/one-context.d/loc-15-ip_forward##vr @@ -16,6 +16,11 @@ # 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 [ -f /etc/sysctl.d/01-one.conf ]; then unlink /etc/sysctl.d/01-one.conf diff --git a/src/etc/one-context.d/loc-15-keepalived##vr b/src/etc/one-context.d/loc-15-keepalived##vr index 012c3e7..074649b 100755 --- a/src/etc/one-context.d/loc-15-keepalived##vr +++ b/src/etc/one-context.d/loc-15-keepalived##vr @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + get_context_interfaces() { env | grep -E "^ETH[0-9]+_VROUTER_IP=" | sed 's/_.*$//' | sort } @@ -181,7 +186,7 @@ gen_instances ) > /etc/keepalived/keepalived.conf -if [ "$1" == "reconfigure" ]; then +if [ "$2" == "reconfigure" ]; then reload_service else rc-update add keepalived boot diff --git a/src/etc/one-context.d/loc-16-gen-env b/src/etc/one-context.d/loc-16-gen-env index 4d4b764..57c2004 100755 --- a/src/etc/one-context.d/loc-16-gen-env +++ b/src/etc/one-context.d/loc-16-gen-env @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + ENV_FILE=/var/run/one-context/one_env MOUNT_DIR="${MOUNT_DIR:-/mnt}" TOKEN_FILE="${MOUNT_DIR}/token.txt" diff --git a/src/etc/one-context.d/loc-20-set-username-password b/src/etc/one-context.d/loc-20-set-username-password index be8c90b..fbf89e3 100755 --- a/src/etc/one-context.d/loc-20-set-username-password +++ b/src/etc/one-context.d/loc-20-set-username-password @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + # defaults USERNAME=${USERNAME:-root} USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}} diff --git a/src/etc/one-context.d/loc-22-ssh_public_key b/src/etc/one-context.d/loc-22-ssh_public_key index ab16444..6fd5b90 100755 --- a/src/etc/one-context.d/loc-22-ssh_public_key +++ b/src/etc/one-context.d/loc-22-ssh_public_key @@ -16,6 +16,11 @@ # 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 if [ -z "${USERNAME}" ] diff --git a/src/etc/one-context.d/loc-24-ssh_host_key##deb b/src/etc/one-context.d/loc-24-ssh_host_key##deb index b9f4af4..3cd504d 100755 --- a/src/etc/one-context.d/loc-24-ssh_host_key##deb +++ b/src/etc/one-context.d/loc-24-ssh_host_key##deb @@ -16,6 +16,11 @@ # 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 ssh-keygen -A; then if type restorecon >/dev/null 2>&1; then diff --git a/src/etc/one-context.d/loc-30-console##one b/src/etc/one-context.d/loc-30-console##one index 4e9b26d..5990a0a 100755 --- a/src/etc/one-context.d/loc-30-console##one +++ b/src/etc/one-context.d/loc-30-console##one @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + # Linux for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}" diff --git a/src/etc/one-context.d/loc-35-securetty b/src/etc/one-context.d/loc-35-securetty index 35b28c7..afe26b3 100755 --- a/src/etc/one-context.d/loc-35-securetty +++ b/src/etc/one-context.d/loc-35-securetty @@ -16,6 +16,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# THIS IS A CONTEXTUALIZATION GUARD +if [ "$1" != 'local' ] ; then + exit 0 +fi + _pam_file="/etc/pam.d/login" if [ ! -f "${_pam_file}" ]; then exit 0 diff --git a/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one b/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one index 41573c0..79b49a2 100644 --- a/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one +++ b/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one @@ -1,8 +1,8 @@ [Unit] Description=OpenNebula pre-networking contextualization script DefaultDependencies=no -Before=network-pre.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 ConditionPathExists=!/var/run/one-context/context.sh.local diff --git a/src/usr/lib/systemd/system/one-context-local.service##rpm.systemd.one b/src/usr/lib/systemd/system/one-context-local.service##rpm.systemd.one index f3dfafa..20e68f9 100644 --- a/src/usr/lib/systemd/system/one-context-local.service##rpm.systemd.one +++ b/src/usr/lib/systemd/system/one-context-local.service##rpm.systemd.one @@ -1,7 +1,7 @@ [Unit] Description=OpenNebula pre-networking contextualization script -Before=network-pre.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 ConditionPathExists=!/var/run/one-context/context.sh.local diff --git a/src/usr/lib/systemd/system/one-context-online.service##systemd.one b/src/usr/lib/systemd/system/one-context-online.service##systemd.one new file mode 100644 index 0000000..6816d28 --- /dev/null +++ b/src/usr/lib/systemd/system/one-context-online.service##systemd.one @@ -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 diff --git a/src/usr/sbin/one-contextd b/src/usr/sbin/one-contextd index a64fead..9a9f83d 100755 --- a/src/usr/sbin/one-contextd +++ b/src/usr/sbin/one-contextd @@ -18,8 +18,8 @@ set -e -TYPE="${1:-all}" # local, network, all -COMMAND="${2}" # reconfigure? +TYPE="${1:-all}" # local, online, network, all +COMMAND="${2}" # force, reconfigure? SCRIPTS_DIR="${SCRIPTS_DIR:-/etc/one-context.d}" RUNTIME_DIR="${RUNTIME_DIR:-/var/run/one-context}" @@ -93,38 +93,36 @@ function export_rc_vars } function execute_scripts { - local _type=$1 - local _command=$2 + local _type="$1" + local _command="$2" # choose - if [ "${_type}" = 'local' ]; then - local _scripts=$(find "${SCRIPTS_DIR}" \ - -maxdepth 1 -mindepth 1 \ - -name 'loc-*' \ - 2>/dev/null) - elif [ "${_type}" = 'network' ]; then - local _scripts=$(find "${SCRIPTS_DIR}" \ - -maxdepth 1 -mindepth 1 \ - \! \( -name 'net-*' -o -name 'loc-*' \) \ - -o -name 'net-*' \ - 2>/dev/null) - fi + case "${_type}" in + local|online) + local _scripts=$(find "${SCRIPTS_DIR}" \ + -maxdepth 1 -mindepth 1 -type f \ + -name 'loc-*' \ + 2>/dev/null | sort) + ;; + network) + local _scripts=$(find "${SCRIPTS_DIR}" \ + -maxdepth 1 -mindepth 1 -type f \ + \! \( -name 'net-*' -o -name 'loc-*' \) \ + -o -name 'net-*' \ + 2>/dev/null | sort) + ;; + esac export MOUNT_DIR export RUNTIME_DIR log info "Processing ${_type} scripts" for _script in ${_scripts}; do - if [ -d "${_script}" ] ; then - # skip loc-10-network.d and similar - continue - fi - local _name=$(basename "${_script}") # run script and catch output and exit code log debug "Script ${_name}: Starting ..." - _out=$("${_script}" "${_command}" 2>&1) + _out=$("${_script}" "${_type}" "${_command}" 2>&1) local _rtn=$? # 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 exit 1 fi @@ -367,6 +365,7 @@ get_new_context if [ "${TYPE}" = 'all' ]; then run_context 'local' "${COMMAND}" + run_context 'online' "${COMMAND}" run_context 'network' "${COMMAND}" else run_context "${TYPE}" "${COMMAND}" diff --git a/targets.sh b/targets.sh index ab55946..1e8fe2f 100644 --- a/targets.sh +++ b/targets.sh @@ -37,7 +37,7 @@ case "${TARGET}" in NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-.el6} 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} PROVIDES=${PROVIDES:-} REPLACES=${REPLACES:-cloud-init} @@ -48,27 +48,11 @@ case "${TARGET}" in 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') NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-.el7} 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} PROVIDES=${PROVIDES:-} REPLACES=${REPLACES:-cloud-init} @@ -79,26 +63,11 @@ case "${TARGET}" in 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') NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-.el8} 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} PROVIDES=${PROVIDES:-} REPLACES=${REPLACES:-cloud-init} @@ -109,26 +78,11 @@ case "${TARGET}" in 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') NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-alt} 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} PROVIDES=${PROVIDES:-} REPLACES=${REPLACES:-cloud-init} @@ -144,7 +98,7 @@ case "${TARGET}" in NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-.suse} 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} PROVIDES=${PROVIDES:-} REPLACES=${REPLACES:-cloud-init cloud-init-config-suse} @@ -155,27 +109,11 @@ case "${TARGET}" in 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') NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-} 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} PROVIDES=${PROVIDES:-} REPLACES=${REPLACES:-cloud-init} @@ -186,26 +124,11 @@ case "${TARGET}" in 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') NAME=${NAME:-one-context} RELSUFFIX=${RELSUFFIX:-} 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} PROVIDES=${PROVIDES:-} 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 ;; - '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') NAME=${NAME:-one-context-linux} TYPE=${TYPE:-iso} @@ -241,7 +149,7 @@ case "${TARGET}" in RELSUFFIX=${RELSUFFIX:-} TYPE=${TYPE:-pacman} EXT=${EXT:-pkg.tar.xz} - TAGS=${TAGS:-arch systemd one networkd} + TAGS=${TAGS:-linux arch systemd one networkd} # mkinitcpio-growrootfs ruby-json DEPENDS=${DEPENDS:-filesystem util-linux bash curl bind-tools ruby sudo shadow open-vm-tools qemu-guest-agent gawk} PROVIDES=${PROVIDES:-}