From 84d98c7755a3e695a355f698ced59fc650da7c77 Mon Sep 17 00:00:00 2001 From: kvaps Date: Wed, 3 May 2017 16:34:53 +0200 Subject: [PATCH 1/7] add: suse network configuration --- src/etc/one-context.d/loc-10-network##rpm.one | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/etc/one-context.d/loc-10-network##rpm.one b/src/etc/one-context.d/loc-10-network##rpm.one index df472b9..84a1890 100755 --- a/src/etc/one-context.d/loc-10-network##rpm.one +++ b/src/etc/one-context.d/loc-10-network##rpm.one @@ -106,6 +106,9 @@ EOT if [ -n "$GATEWAY" ]; then echo "GATEWAY=$GATEWAY" + if [ -d /etc/sysconfig/network ]; then + echo "default $GATEWAY - -" >> /etc/sysconfig/network/routes + fi fi if [ -n "$MTU" ]; then @@ -126,6 +129,9 @@ EOT if [ -n "$GATEWAY6" ]; then echo "IPV6_DEFAULTGW=$GATEWAY6" + if [ -d /etc/sysconfig/network ]; then + echo "default $GATEWAY6 - -" >> /etc/sysconfig/network/routes + fi fi if [ -n "$MTU" ]; then @@ -153,6 +159,12 @@ get_dev() gen_network_configuration() { + if [ -d /etc/sysconfig/network-scripts ]; then + CONFIG_PATH=/etc/sysconfig/network-scripts + elif [ -d /etc/sysconfig/network ]; then + CONFIG_PATH=/etc/sysconfig/network + fi + INTERFACE_MAC=$(get_interface_mac) CONTEXT_INTERFACES=$(get_context_interfaces) GATEWAY_IFACE_NUM=$(echo "$GATEWAY_IFACE" | sed 's/^ETH//') @@ -179,9 +191,10 @@ gen_network_configuration() [ -z "${DEV}" ] && continue ( + rm -f /etc/sysconfig/network/routes cat < /etc/sysconfig/network-scripts/ifcfg-${DEV} + ) > ${CONFIG_PATH}/ifcfg-${DEV} ifup ${DEV} From d92c89e02f70ee4d7542f74004ceda3c29fb2f7b Mon Sep 17 00:00:00 2001 From: kvaps Date: Thu, 4 May 2017 12:37:16 +0200 Subject: [PATCH 2/7] fix: network startup --- src/etc/one-context.d/loc-10-network##rpm.one | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/etc/one-context.d/loc-10-network##rpm.one b/src/etc/one-context.d/loc-10-network##rpm.one index 84a1890..5043310 100755 --- a/src/etc/one-context.d/loc-10-network##rpm.one +++ b/src/etc/one-context.d/loc-10-network##rpm.one @@ -105,9 +105,10 @@ IPADDR=$IP EOT if [ -n "$GATEWAY" ]; then - echo "GATEWAY=$GATEWAY" - if [ -d /etc/sysconfig/network ]; then + if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then echo "default $GATEWAY - -" >> /etc/sysconfig/network/routes + else + echo "GATEWAY=$GATEWAY" fi fi @@ -128,9 +129,10 @@ EOT fi if [ -n "$GATEWAY6" ]; then - echo "IPV6_DEFAULTGW=$GATEWAY6" - if [ -d /etc/sysconfig/network ]; then + if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then echo "default $GATEWAY6 - -" >> /etc/sysconfig/network/routes + else + echo "IPV6_DEFAULTGW=$GATEWAY6" fi fi @@ -195,10 +197,15 @@ gen_network_configuration() cat < Date: Thu, 4 May 2017 12:37:40 +0200 Subject: [PATCH 3/7] add: dns configuration --- src/etc/one-context.d/loc-11-dns##one | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/etc/one-context.d/loc-11-dns##one b/src/etc/one-context.d/loc-11-dns##one index 7409267..d195f56 100755 --- a/src/etc/one-context.d/loc-11-dns##one +++ b/src/etc/one-context.d/loc-11-dns##one @@ -46,7 +46,14 @@ 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 From d38f035f22fa2977500eb5c0cb2981f65deea377 Mon Sep 17 00:00:00 2001 From: kvaps Date: Thu, 4 May 2017 13:15:01 +0200 Subject: [PATCH 4/7] add: selinux installed check --- postinstall.one | 11 ++++++++++- src/etc/one-context.d/loc-23-selinux-ssh##rpm | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/postinstall.one b/postinstall.one index 7f9fe42..d8a03c5 100755 --- a/postinstall.one +++ b/postinstall.one @@ -32,7 +32,7 @@ then fi if [ -f /etc/init.d/one-context ]; then - if [ -d /etc/sysconfig/network-scripts ]; then + if [ -d /etc/sysconfig/network-scripts ] || [ -d /etc/sysconfig/network ]; then chkconfig --add one-context-local chkconfig --add one-context elif [ -d /etc/network ]; then @@ -79,3 +79,12 @@ if [ -d /etc/sysconfig/network-scripts ]; then rm -f /etc/sysconfig/network-scripts/ifcfg-eth* fi +# openSUSE based distros +if [ -d /etc/sysconfig/network ]; then + # Prepare network files + rm -f /etc/sysconfig/network/ifcfg-eth* + rm -f /etc/sysconfig/network/routes + sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=""/' /etc/sysconfig/network/config + sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config +fi + diff --git a/src/etc/one-context.d/loc-23-selinux-ssh##rpm b/src/etc/one-context.d/loc-23-selinux-ssh##rpm index 164d1c1..bfc513d 100755 --- a/src/etc/one-context.d/loc-23-selinux-ssh##rpm +++ b/src/etc/one-context.d/loc-23-selinux-ssh##rpm @@ -1 +1 @@ -restorecon -R -v /root/.ssh +[ -x /sbin/restorecon ] && restorecon -R -v /root/.ssh From 789066a5cbddc5084b08c92a1fbfd78be5472879 Mon Sep 17 00:00:00 2001 From: kvaps Date: Thu, 4 May 2017 13:38:56 +0200 Subject: [PATCH 5/7] fix: dns commas --- src/etc/one-context.d/loc-11-dns##one | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/etc/one-context.d/loc-11-dns##one b/src/etc/one-context.d/loc-11-dns##one index d195f56..464c12e 100755 --- a/src/etc/one-context.d/loc-11-dns##one +++ b/src/etc/one-context.d/loc-11-dns##one @@ -47,7 +47,7 @@ for nameserver in $nameservers; do done if [ -f /etc/sysconfig/network/config ]; then - sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/="'$nameservers'"/' /etc/sysconfig/network/config + sed -i "/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=\"$nameservers\"/" /etc/sysconfig/network/config fi [ -z "$searchdomains" ] && exit 0 @@ -55,5 +55,5 @@ fi 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 + sed -i "/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=\"$searchdomains\"/" /etc/sysconfig/network/config fi From d5c9443a631712cf39bc7270775a64b9faa1ee42 Mon Sep 17 00:00:00 2001 From: kvaps Date: Thu, 4 May 2017 13:39:17 +0200 Subject: [PATCH 6/7] fix: get_first_ip --- src/etc/one-context.d/net-15-hostname##one | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/one-context.d/net-15-hostname##one b/src/etc/one-context.d/net-15-hostname##one index 9085e3b..293d0bf 100755 --- a/src/etc/one-context.d/net-15-hostname##one +++ b/src/etc/one-context.d/net-15-hostname##one @@ -24,7 +24,7 @@ function set_domainname() { } function get_first_ip() { - hostname -I | cut -d' ' -f1 + ip route get 1 | awk '{print $NF;exit}' } function get_dns_name() { From 372cb6a183ec08857616771574fb8db15af0e9ab Mon Sep 17 00:00:00 2001 From: kvaps Date: Thu, 18 May 2017 02:24:59 +0200 Subject: [PATCH 7/7] fix: Changes for this review https://github.com/OpenNebula/addon-context-linux/pull/75#pullrequestreview-37265447 --- postinstall.one | 2 +- src/etc/one-context.d/loc-10-network##rpm.one | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/postinstall.one b/postinstall.one index d8a03c5..00194e7 100755 --- a/postinstall.one +++ b/postinstall.one @@ -83,7 +83,7 @@ fi if [ -d /etc/sysconfig/network ]; then # Prepare network files rm -f /etc/sysconfig/network/ifcfg-eth* - rm -f /etc/sysconfig/network/routes + rm -f /etc/sysconfig/network/ifroute-eth* sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=""/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config fi diff --git a/src/etc/one-context.d/loc-10-network##rpm.one b/src/etc/one-context.d/loc-10-network##rpm.one index 5043310..6617f00 100755 --- a/src/etc/one-context.d/loc-10-network##rpm.one +++ b/src/etc/one-context.d/loc-10-network##rpm.one @@ -106,7 +106,7 @@ EOT if [ -n "$GATEWAY" ]; then if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then - echo "default $GATEWAY - -" >> /etc/sysconfig/network/routes + echo "default $GATEWAY - $DEV" >> /etc/sysconfig/network/ifroute-$DEV else echo "GATEWAY=$GATEWAY" fi @@ -130,7 +130,7 @@ EOT if [ -n "$GATEWAY6" ]; then if [ "$CONFIG_PATH" = "/etc/sysconfig/network" ]; then - echo "default $GATEWAY6 - -" >> /etc/sysconfig/network/routes + echo "default $GATEWAY6 - $DEV" >> /etc/sysconfig/network/ifroute-$DEV else echo "IPV6_DEFAULTGW=$GATEWAY6" fi @@ -193,18 +193,18 @@ gen_network_configuration() [ -z "${DEV}" ] && continue ( - rm -f /etc/sysconfig/network/routes + rm -f /etc/sysconfig/network/ifroute-$DEV cat <