59 lines
1.3 KiB
Bash
Executable File
59 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#Charger les variables du fichier .env
|
|
if [ -f .env ]; then
|
|
export $(grep -v '^#' .env | xargs)
|
|
fi
|
|
|
|
#Confirmation de l'utilisateur
|
|
read -e -p "⚠️ Attention vous allez réinitialiser complètement la salle, voulez-vous vraiment continuer [o/n] : " -i "n" confirmation
|
|
echo "Vous avez entré ${confirmation}"
|
|
|
|
if [ "$confirmation" == "o" ]; then
|
|
|
|
echo "Lancement de la tâche de réinitialisation de la salle"
|
|
|
|
#Configuration
|
|
GROUP_ID="1"
|
|
IMAGE_ID="1"
|
|
TASK_TYPE="1" # Multicast
|
|
SHUTDOWN="1" # Éteindre à la fin
|
|
|
|
#Récupération des MAC des PCs
|
|
MACS=$(curl -s -H "fog-api-token: $FOG_API_TOKEN" -H "fog-user-token: $FOG_USER_TOKEN" \
|
|
http://localhost/fog/host | jq -r '.hosts[].macs[]')
|
|
|
|
#Envoi du WOL à chaque MAC
|
|
echo "Révéil des machines"
|
|
for MAC in $MACS; do
|
|
#echo "💡 Envoi WOL à $MAC"
|
|
wakeonlan "$MAC"
|
|
done
|
|
|
|
|
|
|
|
# Construction du JSON de tâche
|
|
DATA=$(cat <<EOF
|
|
{
|
|
"taskTypeID": "$TASK_TYPE",
|
|
"shutdown": "$SHUTDOWN",
|
|
"imageID": "$IMAGE_ID"
|
|
}
|
|
EOF
|
|
)
|
|
|
|
# Création de la tâche
|
|
echo "Création de la tâche pour le groupe ${GROUP_ID}"
|
|
curl -s -H "fog-api-token: ${FOG_API_TOKEN}" -H "fog-user-token: ${FOG_USER_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-X POST http://localhost/fog/group/${GROUP_ID}/task -d "$DATA"
|
|
|
|
|
|
|
|
else
|
|
echo "Annulation de la tâche de réinitialisation de la salle"
|
|
fi
|
|
|
|
echo "FIN"
|
|
|