97 lines
2.8 KiB
Bash
Executable File
97 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration des ports (À remplacer par tes propres chemins by-path)
|
|
# Pour trouver tes chemins : ls -l /dev/serial/by-path/
|
|
PORT_ESP_WIFI="/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:6.2:1.0-port0"
|
|
PORT_ESP_LORA="/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:6.1:1.0-port0"
|
|
# Ajoute les autres si besoin...
|
|
|
|
# Configuration Raspberry Pi
|
|
RPI_HOST="192.168.50.1"
|
|
RPI_USER="pi"
|
|
RPI_DEST="/home/pi/SmartWave"
|
|
RPI_SYSTEMD_SERVICE="smartwave.service"
|
|
|
|
# Vérification des arguments
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: ./deploy.sh [wifi|lora|rpi|all]"
|
|
exit 1
|
|
fi
|
|
|
|
CIBLE=$1
|
|
|
|
# Fonction de déploiement
|
|
deploy_to_esp() {
|
|
TARGET_DIR=$1
|
|
PORT=$2
|
|
NAME=$3
|
|
|
|
echo "======================================"
|
|
echo "🚀 Déploiement de [$NAME] sur $PORT"
|
|
echo "======================================"
|
|
|
|
if [ ! -e "$PORT" ]; then
|
|
echo "❌ Erreur : Le port $PORT est introuvable. L'ESP est-il branché ?"
|
|
return 1
|
|
fi
|
|
|
|
echo "📦 Copie du dossier shared/..."
|
|
# L'option 'cp -r' copie le contenu de façon récursive
|
|
mpremote connect "$PORT" cp -r shared/ :
|
|
|
|
echo "📂 Copie du code spécifique ($TARGET_DIR)..."
|
|
# Copie le contenu du dossier cible à la racine de l'ESP
|
|
mpremote connect "$PORT" cp -r "$TARGET_DIR"/* :
|
|
|
|
echo "📦 Copie des certificats MQTT..."
|
|
mpremote connect "$PORT" cp -r orchestrateur/mqtt/certs/ :
|
|
|
|
echo "🔄 Redémarrage de l'ESP..."
|
|
mpremote connect "$PORT" reset
|
|
|
|
echo "✅ [$NAME] mis à jour avec succès !"
|
|
echo ""
|
|
}
|
|
|
|
deploy_to_rpi() {
|
|
echo "======================================"
|
|
echo "🚀 Déploiement vers le Raspberry Pi"
|
|
echo "======================================"
|
|
|
|
echo "📦 Synchronisation via rsync vers ${RPI_USER}:hepl@${RPI_HOST}:${RPI_DEST}..."
|
|
rsync -az --delete \
|
|
--exclude '.git' \
|
|
--exclude 'venv' \
|
|
--exclude '__pycache__' \
|
|
--exclude '*.pyc' \
|
|
--exclude '.mypy_cache' \
|
|
./ "${RPI_USER}@${RPI_HOST}:${RPI_DEST}/"
|
|
|
|
echo "🔄 Redémarrage du service systemd ${RPI_SYSTEMD_SERVICE}..."
|
|
ssh "${RPI_USER}@${RPI_HOST}" "sudo systemctl restart ${RPI_SYSTEMD_SERVICE}"
|
|
|
|
echo "✅ Raspberry Pi mis à jour avec succès !"
|
|
echo ""
|
|
}
|
|
|
|
# Routage selon l'argument passé
|
|
case $CIBLE in
|
|
"wifi")
|
|
deploy_to_esp "micro_ondes/esp_wifi" "$PORT_ESP_WIFI" "ESP-WIFI"
|
|
;;
|
|
"lora")
|
|
deploy_to_esp "micro_ondes/esp_lora" "$PORT_ESP_LORA" "ESP-LORA"
|
|
;;
|
|
"rpi")
|
|
deploy_to_rpi
|
|
;;
|
|
"all")
|
|
deploy_to_esp "micro_ondes/esp_wifi" "$PORT_ESP_WIFI" "ESP-WIFI"
|
|
deploy_to_esp "micro_ondes/esp_lora" "$PORT_ESP_LORA" "ESP-LORA"
|
|
deploy_to_rpi
|
|
# Ajoute les autres ici
|
|
;;
|
|
*)
|
|
echo "Cible inconnue. Utilise 'wifi', 'lora' ou 'all'."
|
|
;;
|
|
esac |