mirror of https://gitlab.com/hp3icc/emq-TE1.git
53 lines
1.7 KiB
Bash
53 lines
1.7 KiB
Bash
#!/bin/bash
|
|
### BEGIN INIT INFO
|
|
# Provides: move_nmconnection.sh
|
|
# Required-Start: $network $local_fs $remote_fs $syslog
|
|
# Required-Stop: $network $local_fs $remote_fs $syslog
|
|
# 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.
|
|
### END INIT INFO
|
|
|
|
BOOT_DIR="/boot"
|
|
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..."
|
|
exit 0
|
|
fi
|
|
|
|
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
|
|
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
|
|
|
|
network_name="WiFi Connect"
|
|
nmcli connection show "$network_name" &>/dev/null && nmcli connection delete "$network_name" &>/dev/null
|
|
|
|
sudo systemctl stop NetworkManager
|
|
sudo systemctl start NetworkManager
|
|
sudo nmcli connection reload
|
|
|
|
echo "Proceso completado."
|
|
exit 0
|