mirror of https://gitlab.com/hp3icc/emq-TE1.git
This commit is contained in:
parent
37fb711f54
commit
165ba8a4a3
|
|
@ -9,61 +9,38 @@
|
||||||
# Description: Moves the .nmconnection files from /boot to /etc/NetworkManager/system-connections and restarts NetworkManager.
|
# Description: Moves the .nmconnection files from /boot to /etc/NetworkManager/system-connections and restarts NetworkManager.
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
# Directorio de la partición boot
|
|
||||||
BOOT_DIR="/boot"
|
BOOT_DIR="/boot"
|
||||||
|
|
||||||
# Directorio de destino para los archivos de configuración de NetworkManager
|
|
||||||
DEST_DIR="/etc/NetworkManager/system-connections"
|
DEST_DIR="/etc/NetworkManager/system-connections"
|
||||||
|
|
||||||
# Función para obtener el SSID del archivo .nmconnection
|
|
||||||
get_ssid_from_file() {
|
get_ssid_from_file() {
|
||||||
grep -oP '^ssid=\K.*' "$1"
|
grep -oP '^ssid=\K.*' "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Buscar archivos .nmconnection en /boot y moverlos a /etc/NetworkManager/system-connections/
|
|
||||||
for nm_file in $BOOT_DIR/*.nmconnection; do
|
for nm_file in $BOOT_DIR/*.nmconnection; do
|
||||||
if [ -f "$nm_file" ]; then
|
if [ -f "$nm_file" ]; then
|
||||||
# Obtener el SSID del archivo nuevo
|
new_ssid=$(get_ssid_from_file "$nm_file")
|
||||||
new_ssid=$(get_ssid_from_file "$nm_file")
|
if [ -z "$new_ssid" ]; then
|
||||||
|
echo "El archivo $nm_file no tiene SSID, se omite."
|
||||||
if [ -z "$new_ssid" ]; then
|
continue
|
||||||
echo "El archivo $nm_file no tiene SSID, se omite."
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Buscar archivos existentes en /etc/NetworkManager/system-connections que tengan el mismo SSID
|
|
||||||
existing_files=$(find "$DEST_DIR" -name "*.nmconnection" -exec grep -l "ssid=$new_ssid" {} \;)
|
|
||||||
|
|
||||||
# Si se encuentran archivos con el mismo SSID, eliminarlos
|
|
||||||
if [ -n "$existing_files" ]; then
|
|
||||||
echo "Encontrados archivos con SSID duplicado ('$new_ssid'). Eliminando archivos antiguos..."
|
|
||||||
for file in $existing_files; do
|
|
||||||
existing_ssid=$(get_ssid_from_file "$file")
|
|
||||||
|
|
||||||
if [ "$existing_ssid" == "$new_ssid" ]; then
|
|
||||||
echo "Eliminando archivo antiguo: $file con SSID '$existing_ssid'"
|
|
||||||
rm -f "$file"
|
|
||||||
fi
|
fi
|
||||||
done
|
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
|
fi
|
||||||
|
|
||||||
# Mover el archivo .nmconnection a la carpeta de configuración de NetworkManager (forzando la sobrescritura)
|
|
||||||
mv -f "$nm_file" "$DEST_DIR/"
|
|
||||||
|
|
||||||
# Asegurarse de que los permisos sean correctos (solo lectura para root)
|
|
||||||
chmod 600 "$DEST_DIR/$(basename $nm_file)"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
network_name="WiFi Connect"
|
network_name="WiFi Connect"
|
||||||
nmcli connection show "$network_name" &>/dev/null && nmcli connection delete "$network_name" &>/dev/null
|
nmcli connection show "$network_name" &>/dev/null && nmcli connection delete "$network_name" &>/dev/null
|
||||||
# Detener NetworkManager
|
|
||||||
sudo systemctl stop NetworkManager
|
sudo systemctl stop NetworkManager
|
||||||
|
|
||||||
# Iniciar NetworkManager
|
|
||||||
sudo systemctl start NetworkManager
|
sudo systemctl start NetworkManager
|
||||||
|
|
||||||
# Recargar las configuraciones de NetworkManager para que se reconozcan los cambios
|
|
||||||
sudo nmcli connection reload
|
sudo nmcli connection reload
|
||||||
|
|
||||||
echo "Proceso completado."
|
echo "Proceso completado."
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ EOF
|
||||||
sudo systemctl disable networking
|
sudo systemctl disable networking
|
||||||
sudo systemctl stop dhcpcd
|
sudo systemctl stop dhcpcd
|
||||||
sudo systemctl disable dhcpcd
|
sudo systemctl disable dhcpcd
|
||||||
|
sudo systemctl stop wpa_supplicant
|
||||||
|
sudo systemctl disable wpa_supplicant
|
||||||
|
|
||||||
# Habilitar y reiniciar NetworkManager
|
# Habilitar y reiniciar NetworkManager
|
||||||
sudo systemctl enable NetworkManager
|
sudo systemctl enable NetworkManager
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue