-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.sh
More file actions
53 lines (44 loc) · 1.25 KB
/
worker.sh
File metadata and controls
53 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
for arg in "$@"; do
case $arg in
ip=*)
IP="${arg#*=}"
;;
c=*)
CONTAINERS="${arg#*=}"
;;
IPS=*)
IPS="${arg#*=}"
;;
esac
done
# Lista blanca de IPs permitidas (pueden ser varias)
ALLOWED_IPS=("$IP")
# Obtener IP local: (ejemplo con ifconfig y grep)
# Ajusta la interfaz si sabes cuál usar, por ejemplo eth0 o enp0s3
LOCAL_IP=$(ip addr show enp4s0f0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
# Alternativa con ip (más moderna)
# LOCAL_IP=$(ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d/ -f1 | head -n1)
echo "IP local detectada: $LOCAL_IP"
# Verificar si IP está en la lista blanca
IP_ALLOWED=false
for ip in "${ALLOWED_IPS[@]}"; do
if [[ "$LOCAL_IP" == "$ip" ]]; then
IP_ALLOWED=true
break
fi
done
if [ "$IP_ALLOWED" = true ]; then
echo "IP permitida. Ejecutando comando..."
# Aquí pones tu comando real, por ejemplo:
wget -q --server-response http://$IPS:8000/dockers.tar.gz -O dockers.tar.gz && tar -xzf dockers.tar.gz
cd src
echo "Ejecutando contenedor..."
docker compose build $CONTAINERS
docker compose up $CONTAINERS
echo "EXIT"
exit
else
echo "❌ IP $LOCAL_IP :$ALLOWED_IPSno está en la lista de permitidas. Abortando."
exit 1
fi