Skip to content

Instantly share code, notes, and snippets.

@okikio
Created August 8, 2025 20:23
Show Gist options
  • Save okikio/e1b98bffe4b06790b4406eda949ab40e to your computer and use it in GitHub Desktop.
Save okikio/e1b98bffe4b06790b4406eda949ab40e to your computer and use it in GitHub Desktop.
Setup network manager to work with tailwind
#!/bin/bash
# Define the path for the NetworkManager configuration file
CONFIG_FILE="/etc/NetworkManager/conf.d/99-tailscale.conf"
# Function to check if the script is run with sudo (root privileges)
check_root() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (use sudo)."
exit 1
fi
}
# Function to create the config file
create_config_file() {
echo "Creating the configuration file to unmanage tailscale network devices..."
# Write the configuration to the file
echo -e "[keyfile]\nunmanaged-devices=interface-name:tailscale0" | sudo tee "$CONFIG_FILE" > /dev/null
echo "Configuration file created at $CONFIG_FILE."
}
# Function to restart NetworkManager
restart_networkmanager() {
echo "Restarting NetworkManager..."
sudo systemctl restart NetworkManager
echo "NetworkManager restarted."
}
# Function to remove the config file
remove_config_file() {
echo "Removing the configuration file..."
sudo rm -f "$CONFIG_FILE" && echo "Configuration file removed."
}
# Function to check if the config file already exists
check_existing_file() {
if [[ -f "$CONFIG_FILE" ]]; then
return 0 # Indicate that the file exists
else
return 1 # Indicate that the file doesn't exist
fi
}
# Function to ask for confirmation to remove the config file
ask_remove_confirmation() {
read -p "The configuration file already exists at $CONFIG_FILE. Do you want to delete it? (y/n): " confirmation
if [[ "$confirmation" =~ ^[Yy]$ ]]; then
remove_config_file
restart_networkmanager
else
echo "No changes made. Exiting script."
exit 0
fi
}
# Main logic of the script
check_root # Ensure the script is run with root privileges
if check_existing_file; then
# If the file exists, ask the user if they want to delete it
ask_remove_confirmation
else
# If the file doesn't exist, ask for confirmation to create it
read -p "This will create a configuration file to unmanage the Tailscale device (tailscale0) and restart NetworkManager. Are you sure you want to proceed? (y/n): " confirmation
if [[ "$confirmation" =~ ^[Yy]$ ]]; then
create_config_file
restart_networkmanager
else
echo "No changes made."
exit 0
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment