From 961f73f161e92c802e3df5cc24ade017385400f9 Mon Sep 17 00:00:00 2001 From: "Esteban Mackay Q." Date: Fri, 13 Dec 2024 12:51:25 -0500 Subject: [PATCH] Update move_nmconnection.sh --- install/move_nmconnection.sh | 51 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/install/move_nmconnection.sh b/install/move_nmconnection.sh index 1ea6cf2..cf3b977 100644 --- a/install/move_nmconnection.sh +++ b/install/move_nmconnection.sh @@ -6,15 +6,16 @@ # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Move and configure NetworkManager connections -# Description: Moves the .nmconnection files from /boot to /etc/NetworkManager/system-connections and restarts NetworkManager. +# Description: Moves the .nmconnection files from /boot and /boot/firmware to /etc/NetworkManager/system-connections and restarts NetworkManager. ### END INIT INFO BOOT_DIR="/boot" +FIRMWARE_DIR="/boot/firmware" DEST_DIR="/etc/NetworkManager/system-connections" -# Verificar si hay archivos .nmconnection en /boot -if ! ls "$BOOT_DIR"/*.nmconnection &>/dev/null; then - echo "No se encontraron archivos .nmconnection en $BOOT_DIR. Saliendo..." +# Verificar si hay archivos .nmconnection en /boot o /boot/firmware +if ! ls "$BOOT_DIR"/*.nmconnection &>/dev/null && ! ls "$FIRMWARE_DIR"/*.nmconnection &>/dev/null; then + echo "No se encontraron archivos .nmconnection en $BOOT_DIR ni en $FIRMWARE_DIR. Saliendo..." exit 0 fi @@ -22,24 +23,32 @@ get_ssid_from_file() { grep -oP '^ssid=\K.*' "$1" } -for nm_file in "$BOOT_DIR"/*.nmconnection; do - if [ -f "$nm_file" ]; then - new_ssid=$(get_ssid_from_file "$nm_file") - if [ -z "$new_ssid" ]; then - echo "El archivo $nm_file no tiene SSID, se omite." - continue +# Función para mover los archivos .nmconnection desde cualquier directorio +move_files() { + local source_dir="$1" + for nm_file in "$source_dir"/*.nmconnection; do + if [ -f "$nm_file" ]; then + new_ssid=$(get_ssid_from_file "$nm_file") + if [ -z "$new_ssid" ]; then + echo "El archivo $nm_file no tiene SSID, se omite." + continue + fi + existing_files=$(find "$DEST_DIR" -name "*.nmconnection" -exec grep -l "ssid=$new_ssid" {} \;) + if [ -n "$existing_files" ]; then + echo "Encontrados archivos con SSID duplicado ('$new_ssid'). Eliminando archivos antiguos..." + for file in $existing_files; do + rm -f "$file" + done + fi + mv -f "$nm_file" "$DEST_DIR/" + chmod 600 "$DEST_DIR/$(basename "$nm_file")" fi - existing_files=$(find "$DEST_DIR" -name "*.nmconnection" -exec grep -l "ssid=$new_ssid" {} \;) - if [ -n "$existing_files" ]; then - echo "Encontrados archivos con SSID duplicado ('$new_ssid'). Eliminando archivos antiguos..." - for file in $existing_files; do - rm -f "$file" - done - fi - mv -f "$nm_file" "$DEST_DIR/" - chmod 600 "$DEST_DIR/$(basename "$nm_file")" - fi -done + done +} + +# Mover los archivos de ambas ubicaciones +move_files "$BOOT_DIR" +move_files "$FIRMWARE_DIR" network_name="WiFi Connect" nmcli connection show "$network_name" &>/dev/null && nmcli connection delete "$network_name" &>/dev/null