Init
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration des ports (À remplacer par tes propres chemins by-id)
|
||||
# Pour trouver tes chemins, branche tes ESP et tape : ls -l /dev/serial/by-id/
|
||||
PORT_ESP_WIFI="/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0"
|
||||
PORT_ESP_LORA="/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0002-if00-port0"
|
||||
# Ajoute les autres si besoin...
|
||||
|
||||
# Configuration Raspberry Pi
|
||||
RPI_HOST="10.85.213.190"
|
||||
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 :certs
|
||||
|
||||
echo "🔄 Redémarrage de l'ESP..."
|
||||
mpremote connect "$PORT" soft-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
|
||||
Reference in New Issue
Block a user