Skip to content

Instantly share code, notes, and snippets.

@nbuchwitz
Last active June 28, 2023 12:18
Show Gist options
  • Save nbuchwitz/06876674ebd0b2bab429f1a8506271a1 to your computer and use it in GitHub Desktop.
Save nbuchwitz/06876674ebd0b2bab429f1a8506271a1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
nm_files="dhcp-eth0.nmconnection dhcp-eth1.nmconnection fallback-link-local-eth0.nmconnection fallback-link-local-eth1.nmconnection 99-revpi.conf"
download_dir=$(mktemp -d)
echo -n "This script will change the network configuration from dhcpcd to NetworkManager. Do you want to proceed? [yN] "
read choice
if [ "$choice" != "y" ] && [ "$choice" != "Y" ]; then
echo "Aborted. Configuration has not been changed."
echo
exit
fi
echo
echo -n ">> Downloading configuration files "
for file in $nm_files ; do
url="https://raw.githubusercontent.com/RevolutionPi/imagebakery/master/templates/network-manager/$file"
wget --quiet "$url" -O "$download_dir/$file"
echo -n .
done
echo
echo
echo ">> Install NetworkManager package ..."
if ! $(dpkg -s network-manager >/dev/null 2>&1); then
sudo apt update && sudo apt install -y network-manager
else
echo "Package already installed. Nothing to do here."
fi
echo
echo ">> Configure system with raspi-config to use NetworkManager instead of dhcpcd ..."
sudo raspi-config nonint do_netconf 2
echo
echo ">> Copy RevPi specific configuration files for NetworkManager ..."
# Don't manage pileft / piright with NetworkManager
sudo install -o root -m 0644 "$download_dir/99-revpi.conf" "$IMAGEDIR/etc/NetworkManager/conf.d/99-revpi.conf"
# Use fallback to dhcp if no connection is configured
sudo install -o root -m 0600 "$download_dir/dhcp-eth0.nmconnection" "/etc/NetworkManager/system-connections"
sudo install -o root -m 0600 "$download_dir/dhcp-eth1.nmconnection" "/etc/NetworkManager/system-connections"
# Use fallback to link-local if dhcp fails
sudo install -o root -m 0600 "$download_dir/fallback-link-local-eth0.nmconnection" "/etc/NetworkManager/system-connections"
sudo install -o root -m 0600 "$download_dir/fallback-link-local-eth1.nmconnection" "/etc/NetworkManager/system-connections"
echo ">> Cleanup downloaded files and temp folder ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment