Skip to content

Commit

Permalink
fix: Improved the way netplan is disabled on Kura install (#4662)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Timeus <[email protected]>
  • Loading branch information
nicolatimeus authored May 19, 2023
1 parent 3aaa020 commit 2b80007
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 30 deletions.
23 changes: 23 additions & 0 deletions kura/distrib/src/main/resources/generic-aarch64/deb/control/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ function stopWatchdog {
fi
}

function restore_backup_files {
SUFFIX="${1}"

shift

for file in "${@}"
do
if [ -f "${file}" ] && expr "${file}" : ".*[.]${SUFFIX}$" > /dev/null; then
mv "${file}" "${file%."${SUFFIX}"}"
fi
done
}

function restore_netplan {
if [ -f /etc/netplan/zz-kura-use-nm.yaml ]; then
rm -f /etc/netplan/zz-kura-use-nm.yaml
fi

restore_backup_files kurasave /lib/netplan/* /etc/netplan/*
}

# Pre-remove script
function preRemove {
#Remove INIT scripts
Expand Down Expand Up @@ -107,6 +128,8 @@ function preRemove {
if [ -f /etc/default/dnsmasq.old ]; then
mv /etc/default/dnsmasq.old /etc/default/dnsmasq
fi

restore_netplan

echo ""
echo "Uninstalling KURA... Done!"
Expand Down
44 changes: 34 additions & 10 deletions kura/distrib/src/main/resources/generic-aarch64/kura_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
# Eurotech
#

backup_files() {
SUFFIX="${1}"

shift

for file in "${@}"
do
if [ -f "${file}" ]
then
mv "${file}" "${file}.${SUFFIX}"
fi
done
}

disable_netplan() {
# disable netplan configuration files
backup_files kurasave /lib/netplan/*.yaml /etc/netplan/*.yaml

if [ -d /etc/netplan ]
then

# use NM renderer
cat > /etc/netplan/zz-kura-use-nm.yaml <<EOF
network:
version: 2
renderer: NetworkManager
EOF
fi
}

INSTALL_DIR=/opt/eclipse

# create known kura install location
Expand Down Expand Up @@ -60,6 +90,7 @@ systemctl stop dnsmasq
systemctl disable dnsmasq
systemctl stop dhcpcd
systemctl disable dhcpcd
systemctl disable systemd-networkd

# set up users and grant permissions
cp ${INSTALL_DIR}/kura/install/manage_kura_users.sh ${INSTALL_DIR}/kura/.data/manage_kura_users.sh
Expand Down Expand Up @@ -89,16 +120,9 @@ systemctl enable firewall
if [ -d /etc/cloud/cloud.cfg.d ]; then
echo "network: {config: disabled}" | sudo tee -a /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg > /dev/null
fi
if [ -d /etc/netplan/ ]; then
cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.BAK
cat << EOF >> /etc/netplan/00-installer-config.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: NetworkManager
EOF
fi

disable_netplan

if [ -d /usr/lib/NetworkManager/conf.d/ ]; then
TO_REMOVE=$( find /usr/lib/NetworkManager/conf.d/ -type f -name "*-globally-managed-devices.conf" | awk 'NR==1{print $1}' )

Expand Down
23 changes: 23 additions & 0 deletions kura/distrib/src/main/resources/generic-arm32/deb/control/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ function stopWatchdog {
fi
}

function restore_backup_files {
SUFFIX="${1}"

shift

for file in "${@}"
do
if [ -f "${file}" ] && expr "${file}" : ".*[.]${SUFFIX}$" > /dev/null; then
mv "${file}" "${file%."${SUFFIX}"}"
fi
done
}

function restore_netplan {
if [ -f /etc/netplan/zz-kura-use-nm.yaml ]; then
rm -f /etc/netplan/zz-kura-use-nm.yaml
fi

restore_backup_files kurasave /lib/netplan/* /etc/netplan/*
}

# Pre-remove script
function preRemove {
#Remove INIT scripts
Expand Down Expand Up @@ -107,6 +128,8 @@ function preRemove {
if [ -f /etc/default/dnsmasq.old ]; then
mv /etc/default/dnsmasq.old /etc/default/dnsmasq
fi

restore_netplan

echo ""
echo "Uninstalling KURA... Done!"
Expand Down
44 changes: 34 additions & 10 deletions kura/distrib/src/main/resources/generic-arm32/kura_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
# Eurotech
#

backup_files() {
SUFFIX="${1}"

shift

for file in "${@}"
do
if [ -f "${file}" ]
then
mv "${file}" "${file}.${SUFFIX}"
fi
done
}

disable_netplan() {
# disable netplan configuration files
backup_files kurasave /lib/netplan/*.yaml /etc/netplan/*.yaml

if [ -d /etc/netplan ]
then

# use NM renderer
cat > /etc/netplan/zz-kura-use-nm.yaml <<EOF
network:
version: 2
renderer: NetworkManager
EOF
fi
}

INSTALL_DIR=/opt/eclipse

# create known kura install location
Expand Down Expand Up @@ -60,6 +90,7 @@ systemctl stop dnsmasq
systemctl disable dnsmasq
systemctl stop dhcpcd
systemctl disable dhcpcd
systemctl disable systemd-networkd

# set up users and grant permissions
cp ${INSTALL_DIR}/kura/install/manage_kura_users.sh ${INSTALL_DIR}/kura/.data/manage_kura_users.sh
Expand Down Expand Up @@ -89,16 +120,9 @@ systemctl enable firewall
if [ -d /etc/cloud/cloud.cfg.d ]; then
echo "network: {config: disabled}" | sudo tee -a /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg > /dev/null
fi
if [ -d /etc/netplan/ ]; then
cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.BAK
cat << EOF >> /etc/netplan/00-installer-config.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: NetworkManager
EOF
fi

disable_netplan

if [ -d /usr/lib/NetworkManager/conf.d/ ]; then
TO_REMOVE=$( find /usr/lib/NetworkManager/conf.d/ -type f -name "*-globally-managed-devices.conf" | awk 'NR==1{print $1}' )

Expand Down
23 changes: 23 additions & 0 deletions kura/distrib/src/main/resources/generic-x86_64/deb/control/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ function stopWatchdog {
fi
}

function restore_backup_files {
SUFFIX="${1}"

shift

for file in "${@}"
do
if [ -f "${file}" ] && expr "${file}" : ".*[.]${SUFFIX}$" > /dev/null; then
mv "${file}" "${file%."${SUFFIX}"}"
fi
done
}

function restore_netplan {
if [ -f /etc/netplan/zz-kura-use-nm.yaml ]; then
rm -f /etc/netplan/zz-kura-use-nm.yaml
fi

restore_backup_files kurasave /lib/netplan/* /etc/netplan/*
}

# Pre-remove script
function preRemove {
#Remove INIT scripts
Expand Down Expand Up @@ -108,6 +129,8 @@ function preRemove {
mv /etc/default/dnsmasq.old /etc/default/dnsmasq
fi

restore_netplan

echo ""
echo "Uninstalling KURA... Done!"
}
Expand Down
44 changes: 34 additions & 10 deletions kura/distrib/src/main/resources/generic-x86_64/kura_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
# Eurotech
#

backup_files() {
SUFFIX="${1}"

shift

for file in "${@}"
do
if [ -f "${file}" ]
then
mv "${file}" "${file}.${SUFFIX}"
fi
done
}

disable_netplan() {
# disable netplan configuration files
backup_files kurasave /lib/netplan/*.yaml /etc/netplan/*.yaml

if [ -d /etc/netplan ]
then

# use NM renderer
cat > /etc/netplan/zz-kura-use-nm.yaml <<EOF
network:
version: 2
renderer: NetworkManager
EOF
fi
}

INSTALL_DIR=/opt/eclipse

# create known kura install location
Expand Down Expand Up @@ -60,6 +90,7 @@ systemctl stop dnsmasq
systemctl disable dnsmasq
systemctl stop dhcpcd
systemctl disable dhcpcd
systemctl disable systemd-networkd

# set up users and grant permissions
cp ${INSTALL_DIR}/kura/install/manage_kura_users.sh ${INSTALL_DIR}/kura/.data/manage_kura_users.sh
Expand Down Expand Up @@ -89,16 +120,9 @@ systemctl enable firewall
if [ -d /etc/cloud/cloud.cfg.d ]; then
echo "network: {config: disabled}" | sudo tee -a /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg > /dev/null
fi
if [ -d /etc/netplan/ ]; then
cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.BAK
cat << EOF >> /etc/netplan/00-installer-config.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: NetworkManager
EOF
fi

disable_netplan

if [ -d /usr/lib/NetworkManager/conf.d/ ]; then
TO_REMOVE=$( find /usr/lib/NetworkManager/conf.d/ -type f -name "*-globally-managed-devices.conf" | awk 'NR==1{print $1}' )

Expand Down

0 comments on commit 2b80007

Please sign in to comment.