devzone 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.devcontainer/agent-errors.sh +6 -6
  2. package/.devcontainer/agent-pod-manifest.sh +4 -4
  3. package/.devcontainer/agent-session.sh +2 -2
  4. package/.devcontainer/agent-state-json.sh +2 -2
  5. package/.devcontainer/agent-workspace.sh +1 -1
  6. package/.devcontainer/agent.sh +7 -7
  7. package/.devcontainer/ai/host-models.sh +2 -2
  8. package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
  9. package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
  10. package/.devcontainer/argocd/argocd.sh +90 -89
  11. package/.devcontainer/argocd/catalog-argocd.sh +2 -2
  12. package/.devcontainer/argocd/services-hook.sh +3 -3
  13. package/.devcontainer/argocd/services.sh +1 -1
  14. package/.devcontainer/catalog/app.sh +114 -116
  15. package/.devcontainer/catalog/catalog-watcher.sh +62 -62
  16. package/.devcontainer/catalog/mysql/app.conf +1 -1
  17. package/.devcontainer/catalog/mysql/install.sh +40 -40
  18. package/.devcontainer/catalog/mysql/mysql.sh +141 -141
  19. package/.devcontainer/catalog/mysql/volume.sh +39 -39
  20. package/.devcontainer/catalog.sh +112 -112
  21. package/.devcontainer/chart-direct.sh +1 -1
  22. package/.devcontainer/cluster.sh +216 -218
  23. package/.devcontainer/clusters.sh +41 -41
  24. package/.devcontainer/command-aliases.sh +17 -8
  25. package/.devcontainer/devzone +93 -1496
  26. package/.devcontainer/devzone-ai-guard.sh +76 -0
  27. package/.devcontainer/devzone-ai.sh +201 -0
  28. package/.devcontainer/devzone-cluster.sh +210 -0
  29. package/.devcontainer/devzone-modules.sh +126 -0
  30. package/.devcontainer/devzone-platform.sh +189 -0
  31. package/.devcontainer/devzone-repair.sh +94 -0
  32. package/.devcontainer/devzone-services.sh +241 -0
  33. package/.devcontainer/devzone-skill.sh +97 -0
  34. package/.devcontainer/devzone-status.sh +140 -0
  35. package/.devcontainer/devzone-version.sh +78 -0
  36. package/.devcontainer/git-identity.sh +28 -0
  37. package/.devcontainer/gitlab/chart.sh +2 -2
  38. package/.devcontainer/gitlab/gitlab.sh +81 -82
  39. package/.devcontainer/gitlab/installation.sh +109 -109
  40. package/.devcontainer/gitlab/secrets.sh +47 -47
  41. package/.devcontainer/gitlab/seed.sh +77 -77
  42. package/.devcontainer/gitlab/test-gitlab.sh +242 -243
  43. package/.devcontainer/help.sh +1 -1
  44. package/.devcontainer/isolation.sh +30 -30
  45. package/.devcontainer/kind-wrapper.sh +17 -17
  46. package/.devcontainer/kube-account.sh +112 -113
  47. package/.devcontainer/kube-config.sh +45 -46
  48. package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
  49. package/.devcontainer/kube-reachable.sh +40 -40
  50. package/.devcontainer/memory.sh +1 -1
  51. package/.devcontainer/metrics-server.sh +2 -2
  52. package/.devcontainer/opencode.jsonc +2 -2
  53. package/.devcontainer/packages.sh +136 -135
  54. package/.devcontainer/password.sh +1 -1
  55. package/.devcontainer/ports-auto.sh +152 -153
  56. package/.devcontainer/ports-json.sh +16 -15
  57. package/.devcontainer/ports.sh +126 -122
  58. package/.devcontainer/post-create.sh +52 -52
  59. package/.devcontainer/postgres/postgres.sh +174 -174
  60. package/.devcontainer/rename-legacy-files.sh +103 -0
  61. package/.devcontainer/services-admin.sh +3 -3
  62. package/.devcontainer/skills/devzone/SKILL.md +40 -41
  63. package/.devcontainer/startup.sh +48 -49
  64. package/.devcontainer/state-gitops.sh +1 -1
  65. package/.devcontainer/state-json.sh +36 -62
  66. package/.devcontainer/state.sh +2 -2
  67. package/.devcontainer/workspace-init.sh +16 -2
  68. package/Makefile +1 -1
  69. package/README.md +191 -195
  70. package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
  71. package/manage/devzone +7 -11
  72. package/manage/scripts/argocd-workspace.sh +1 -1
  73. package/manage/scripts/{check-charts.sh → ci/check-charts.sh} +1 -1
  74. package/manage/scripts/{check-english.sh → ci/check-english.sh} +1 -1
  75. package/manage/scripts/{check-go-layout.sh → ci/check-go-layout.sh} +1 -1
  76. package/manage/scripts/{check-names.sh → ci/check-names.sh} +7 -6
  77. package/manage/scripts/{check-utf8-vars.sh → ci/check-utf8-vars.sh} +1 -1
  78. package/manage/scripts/{versions.sh → ci/versions.sh} +8 -8
  79. package/manage/scripts/create-cluster.sh +1 -1
  80. package/manage/scripts/create-mode.sh +11 -18
  81. package/manage/scripts/devzone-create.sh +7 -35
  82. package/manage/scripts/devzone-manifest.sh +1 -1
  83. package/manage/scripts/devzone-update.sh +12 -8
  84. package/manage/scripts/launch.sh +7 -48
  85. package/manage/scripts/ports-apps.sh +1 -1
  86. package/manage/scripts/ports-workspace.sh +7 -7
  87. package/manage/scripts/poste.sh +6 -7
  88. package/manage/scripts/uninstall.sh +8 -8
  89. package/manage/scripts/workspace-egress.sh +2 -2
  90. package/manage/scripts/workspace-update.sh +5 -2
  91. package/manage/scripts/workspace-wait.sh +2 -2
  92. package/manage/workspace.sh +2 -12
  93. package/package.json +1 -1
  94. package/.devcontainer/docker-relay.sh +0 -149
  95. package/.devcontainer/docker-without-host.sh +0 -12
  96. package/.devcontainer/git-identite.sh +0 -28
  97. package/manage/scripts/docker-workstation.sh +0 -73
  98. package/manage/scripts/migrate-revert.sh +0 -60
  99. package/manage/scripts/migrate.sh +0 -243
  100. /package/manage/scripts/{ci-dns.sh → ci/ci-dns.sh} +0 -0
@@ -1,151 +1,150 @@
1
1
  #!/usr/bin/env bash
2
- ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
3
3
  # shellcheck source=ports.sh
4
4
  # shellcheck disable=SC1091
5
- . "$ICI/ports.sh"
5
+ . "$HERE/ports.sh"
6
6
  PORTS_AUTO_DIR="${DEVZONE_PORTS_AUTO_DIR:-/tmp/devzone-ports-auto}"
7
7
  BASE="$PORTS_AUTO_DIR/${INSTANCE:-devzone}"
8
8
  BRIDGES="$BASE/bridges"
9
- VERROU="$BASE/verrou"
10
- OCCUPES="$BASE/occupes"
11
- ACTIFS="$BASE/actifs"
12
- PENDING="$BASE/pending"
13
- COURANT="$BASE/courant"
9
+ # State file names on disk (verrou, occupes, actifs, courant) are kept: tests and the watcher use them
10
+ LOCK="$BASE/verrou"; BUSY="$BASE/occupes"; ACTIVE="$BASE/actifs"
11
+ PENDING="$BASE/pending"; CURRENT="$BASE/courant"
12
+ JSON_APP_BUSY=$'occup\303\251 sur le poste' # JSON value, contract (see ports.sh)
14
13
  mkdir -p "$BASE" "$BRIDGES"
15
14
 
16
- # État de l'activation du veilleur : off dès que ports_auto= est à off.
17
- ports_auto_actif() { local v; v="$(grep -E '^ports_auto=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"; case "$v" in off|false|0|non|no) echo off ;; *) echo on ;; esac; }
18
- # Liste des ports exclus par l'utilisateur (ports_exclus=, virgules).
19
- ports_exclus_lus() { grep -E '^ports_exclus=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true; }
20
- # Ecrit une ligne cle=valeur dans l'etat, comme ecrire_ports pour ports=
21
- ecrire() { state_write "$1" "${2:-}" || { echo "devzone : port : etat non enregistre : $ETAT" >&2; return 1; }; }
22
- # Un port est exclu quand il figure dans la liste ports_exclus=.
23
- port_exclu() { case ",$(ports_exclus_lus)," in *",$1,"*) return 0 ;; esac; return 1; }
24
- # Nom du relais automatique d'un port : devzone-<instance>-auto-<port>.
25
- nom_relais_auto() { echo "devzone-$INSTANCE-auto-$1"; }
26
- # Relais automatique <port> déjà en vie sur le Docker de l'hôte ?
27
- relais_auto_actif() { local nom; nom="$(nom_relais_auto "$1")"; command -v docker >/dev/null 2>&1 || return 1; [ -n "$(docker ps --filter "name=^$nom$" --format '{{.Names}}' 2>/dev/null | grep -Fx "$nom" || true)" ]; }
28
- # Délai après disparition d'un port avant de retirer le pont et le relais.
29
- delai_disparition() { local v; for v in DEVZONE_PORTS_AUTO_DELAI_DISPARITION DEVZONE_PORTS_AUTO_DELAI DEVZONE_PORTS_AUTO_RETARD PORTS_AUTO_DELAI PORTS_AUTO_RETARD; do [ -n "${!v:-}" ] && { echo "${!v}"; return 0; }; done; echo 10; }
30
-
31
- # Garde-fou (règle docker-relay.sh #293) : la boucle et demarrer ne tournent
32
- # jamais sous bats, et hors du conteneur que si le contexte réel est posé.
33
- garde_veilleur() {
15
+ # Automatic watcher state: off as soon as ports_auto= is off (« non » kept as a stored value)
16
+ auto_enabled() { local v; v="$(grep -E '^ports_auto=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"; case "$v" in off|false|0|non|no) echo off ;; *) echo on ;; esac; }
17
+ # List of the ports excluded by the user (ports_exclus=, comma-separated)
18
+ excluded_read() { grep -E '^ports_exclus=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true; }
19
+ # Writes a key=value line in the state, like write_ports does for ports=
20
+ write_key() { state_write "$1" "${2:-}" || { echo "devzone : port : state not saved : $ETAT" >&2; return 1; }; }
21
+ # A port is excluded when it is listed in ports_exclus=.
22
+ port_excluded() { case ",$(excluded_read)," in *",$1,"*) return 0 ;; esac; return 1; }
23
+ # Name of the automatic relay of a port: devzone-<instance>-auto-<port>.
24
+ auto_relay_name() { echo "devzone-$INSTANCE-auto-$1"; }
25
+ # Is the automatic relay of <port> already alive on the host's Docker?
26
+ auto_relay_active() { local name; name="$(auto_relay_name "$1")"; command -v docker >/dev/null 2>&1 || return 1; [ -n "$(docker ps --filter "name=^$name$" --format '{{.Names}}' 2>/dev/null | grep -Fx "$name" || true)" ]; }
27
+ # Delay after a port disappears before removing its bridge and relay.
28
+ disappearance_delay() { local v; for v in DEVZONE_PORTS_AUTO_DISAPPEARANCE_DELAY DEVZONE_PORTS_AUTO_DELAY DEVZONE_PORTS_AUTO_LATE PORTS_AUTO_DELAI PORTS_AUTO_RETARD; do [ -n "${!v:-}" ] && { echo "${!v}"; return 0; }; done; echo 10; }
29
+
30
+ # Guard: the loop and demarrer never run under bats,
31
+ # and outside the container only if the real context is set.
32
+ guard_watcher() {
34
33
  if [ -n "${BATS_TEST_TMPDIR:-}" ]; then
35
- echo "devzone : port : veilleur automatique refusé sous bats (tests)" >&2
34
+ echo "devzone : port : automatic watcher refused under bats (tests)" >&2
36
35
  return 2
37
36
  fi
38
- [ "${DEVZONE_PORTS_AUTO_REEL:-}" = oui ] && return 0
39
- echo "devzone : port : veilleur automatique refusé ici : lancer plutôt devzone repair" >&2
37
+ [ "${DEVZONE_PORTS_AUTO_REAL:-}" = yes ] && return 0
38
+ echo "devzone : port : automatic watcher refused here: run devzone repair instead" >&2
40
39
  return 2
41
40
  }
42
41
 
43
- # Lance le relais automatique ; échec → message et code 1 (port déjà pris marqué).
44
- lancer_auto() {
45
- local port="$1" reseau="$2" ip="$3" nom sortie
46
- nom="$(nom_relais_auto "$port")"
47
- if sortie="$(docker run -d --restart unless-stopped --name "$nom" --label "devzone.instance=$INSTANCE" --label "devzone.port=$port" --label "devzone.auto=true" --network "$reseau" -p "127.0.0.1:$port:$port" "$SOCAT_IMAGE" "tcp-listen:$port,fork,reuseaddr" "tcp-connect:$ip:$port" 2>&1)"; then return 0; fi
48
- case "$sortie" in *"port is already allocated"*|*"address already in use"*) echo "devzone : port : port déjà utilisé sur le poste : $port" >&2 ;; *) echo "devzone : port : échec du relais $port : $sortie" >&2 ;; esac
42
+ # Launches the automatic relay; on failure, a message and code 1 (busy port marked).
43
+ launch_auto() {
44
+ local port="$1" network="$2" ip="$3" name output
45
+ name="$(auto_relay_name "$port")"
46
+ if output="$(docker run -d --restart unless-stopped --name "$name" --label "devzone.instance=$INSTANCE" --label "devzone.port=$port" --label "devzone.auto=true" --network "$network" -p "127.0.0.1:$port:$port" "$SOCAT_IMAGE" "tcp-listen:$port,fork,reuseaddr" "tcp-connect:$ip:$port" 2>&1)"; then return 0; fi
47
+ case "$output" in *"port is already allocated"*|*"address already in use"*) echo "devzone : port : port already in use on the workstation : $port" >&2 ;; *) echo "devzone : port : relay on port $port failed : $output" >&2 ;; esac
49
48
  return 1
50
49
  }
51
- # Démarre le pont interne : socat sur l'IP du conteneur, vers le 127.0.0.1 du port.
52
- demarrer_pont() { local port="$1" ip="$2"; local pidfile="$BRIDGES/$port.pid"; if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile" 2>/dev/null)" 2>/dev/null; then return 0; fi; socat "TCP-LISTEN:$port,bind=$ip,fork,reuseaddr" "TCP:127.0.0.1:$port" >/dev/null 2>&1 & echo "$!" >"$pidfile"; }
53
- # Arrête le pont interne (pid dans $BRIDGES).
54
- arreter_pont() { local port="$1"; local pidfile="$BRIDGES/$port.pid"; local pid; if [ -f "$pidfile" ]; then pid="$(cat "$pidfile" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi; wait "$pid" 2>/dev/null || true; rm -f "$pidfile"; fi; }
55
- # Retire le relais automatique et son pont.
56
- fermer_auto() { local port="$1"; docker rm -f "$(nom_relais_auto "$port")" >/dev/null 2>&1 || true; arreter_pont "$port"; }
57
-
58
- # Retire tous les relais automatiques et leurs ponts, puis vide les états.
59
- nettoyer_auto_tout() {
60
- local port; [ -f "$ACTIFS" ] && while IFS= read -r port; do [ -n "$port" ] && fermer_auto "$port"; done <"$ACTIFS"
61
- [ -f "$OCCUPES" ] && while IFS= read -r port; do [ -n "$port" ] && arreter_pont "$port"; done <"$OCCUPES"
62
- : >"$ACTIFS" 2>/dev/null || true; : >"$OCCUPES" 2>/dev/null || true; : >"$PENDING" 2>/dev/null || true; rm -f "$BRIDGES"/*.pid 2>/dev/null || true
50
+ # Starts the internal bridge: socat on the container IP, toward the 127.0.0.1 of the port.
51
+ start_bridge() { local port="$1" ip="$2"; local pidfile="$BRIDGES/$port.pid"; if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile" 2>/dev/null)" 2>/dev/null; then return 0; fi; socat "TCP-LISTEN:$port,bind=$ip,fork,reuseaddr" "TCP:127.0.0.1:$port" >/dev/null 2>&1 & echo "$!" >"$pidfile"; }
52
+ # Stops the internal bridge (pid in $BRIDGES).
53
+ stop_bridge() { local port="$1"; local pidfile="$BRIDGES/$port.pid"; local pid; if [ -f "$pidfile" ]; then pid="$(cat "$pidfile" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi; wait "$pid" 2>/dev/null || true; rm -f "$pidfile"; fi; }
54
+ # Removes the automatic relay and its bridge.
55
+ close_auto() { local port="$1"; docker rm -f "$(auto_relay_name "$port")" >/dev/null 2>&1 || true; stop_bridge "$port"; }
56
+
57
+ # Removes all the automatic relays and their bridges, then empties the states.
58
+ clean_auto_all() {
59
+ local port; [ -f "$ACTIVE" ] && while IFS= read -r port; do [ -n "$port" ] && close_auto "$port"; done <"$ACTIVE"
60
+ [ -f "$BUSY" ] && while IFS= read -r port; do [ -n "$port" ] && stop_bridge "$port"; done <"$BUSY"
61
+ : >"$ACTIVE" 2>/dev/null || true; : >"$BUSY" 2>/dev/null || true; : >"$PENDING" 2>/dev/null || true; rm -f "$BRIDGES"/*.pid 2>/dev/null || true
63
62
  }
64
- # Retire les relais automatiques d'une session précédente.
65
- nettoyer_precedents() { docker ps -a --filter "name=devzone-$INSTANCE-auto-" --format '{{.Names}}' 2>/dev/null | while IFS= read -r nom; do case "$nom" in devzone-"$INSTANCE"-auto-*) docker rm -f "$nom" >/dev/null 2>&1 || true ;; esac; done; rm -f "$BRIDGES"/*.pid 2>/dev/null || true; }
63
+ # Removes the automatic relays of a previous session.
64
+ clean_previous() { docker ps -a --filter "name=devzone-$INSTANCE-auto-" --format '{{.Names}}' 2>/dev/null | while IFS= read -r name; do case "$name" in devzone-"$INSTANCE"-auto-*) docker rm -f "$name" >/dev/null 2>&1 || true ;; esac; done; rm -f "$BRIDGES"/*.pid 2>/dev/null || true; }
66
65
 
67
- # Verrou exclusif (mkdir) avec pid : une seule instance de veilleur.
68
- verrou_prendre() {
69
- local debut now age pid
70
- debut="$(date +%s)"
66
+ # Exclusive lock (mkdir) with a pid: a single watcher instance.
67
+ lock_take() {
68
+ local start now age pid
69
+ start="$(date +%s)"
71
70
  while true; do
72
- if mkdir "$VERROU" 2>/dev/null; then echo "$$" >"$VERROU/pid"; return 0; fi
73
- now="$(date +%s)"; age=""; [ -d "$VERROU" ] && age="$(stat -c %Y "$VERROU" 2>/dev/null || stat -f %m "$VERROU" 2>/dev/null || true)"
74
- pid="$(cat "$VERROU/pid" 2>/dev/null || true)"
75
- if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$VERROU"; continue; fi
76
- if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$VERROU"; continue; fi
77
- [ "$(( now - debut ))" -ge 5 ] && return 1
71
+ if mkdir "$LOCK" 2>/dev/null; then echo "$$" >"$LOCK/pid"; return 0; fi
72
+ now="$(date +%s)"; age=""; [ -d "$LOCK" ] && age="$(stat -c %Y "$LOCK" 2>/dev/null || stat -f %m "$LOCK" 2>/dev/null || true)"
73
+ pid="$(cat "$LOCK/pid" 2>/dev/null || true)"
74
+ if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$LOCK"; continue; fi
75
+ if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$LOCK"; continue; fi
76
+ [ "$(( now - start ))" -ge 5 ] && return 1
78
77
  sleep 1
79
78
  done
80
79
  }
81
80
 
82
- # Marque le verrou comme vivant : date récente et pid du titulaire à jour,
83
- # sinon une instance voisine croit le verrou rouillé et le prend.
84
- verrou_rafraichir() { touch "$VERROU" 2>/dev/null || true; echo "$$" >"$VERROU/pid" 2>/dev/null || true; }
81
+ # Marks the lock as alive: recent date and pid of the holder up to date,
82
+ # otherwise another instance takes the lock as stale.
83
+ lock_refresh() { touch "$LOCK" 2>/dev/null || true; echo "$$" >"$LOCK/pid" 2>/dev/null || true; }
85
84
 
86
- # Un tour de veilleur : relaie les ports écoutés, retire les disparus.
87
- ports_auto_tour() {
88
- local port now delay sortie
89
- # État restauré ou reconstruit : rien pendant 60 s (#417, étape 4)
85
+ # One watcher pass: relays the listening ports, removes the vanished ones.
86
+ auto_pass() {
87
+ local port now delay output
88
+ # State restored or rebuilt: nothing for 60 s (#417, step 4)
90
89
  state_recovery_wait && return 0
91
- if [ "$(ports_auto_actif)" = off ]; then
92
- # Jamais de désinstallation sur un état non confirmé (#417, étape 4)
93
- state_recovery_pending || nettoyer_auto_tout
90
+ if [ "$(auto_enabled)" = off ]; then
91
+ # Never uninstall on an unconfirmed state (#417, step 4)
92
+ state_recovery_pending || clean_auto_all
94
93
  return 0
95
94
  fi
96
- if ! reseau_ip; then echo "devzone : ports-auto : conteneur devzone introuvable" >&2; return 1; fi
97
- : >"$COURANT"
98
- ss -ltnH 2>/dev/null | awk '{ if (NF >= 4) print $4; else if (NF >= 1) print $1 }' | while IFS= read -r local; do
99
- [ -n "$local" ] || continue
100
- p="${local##*:}"; a="${local%:*}"; a="${a#[}"; a="${a%]}"
95
+ if ! network_ip; then echo "devzone : ports-auto : devzone container not found" >&2; return 1; fi
96
+ : >"$CURRENT"
97
+ ss -ltnH 2>/dev/null | awk '{ if (NF >= 4) print $4; else if (NF >= 1) print $1 }' | while IFS= read -r listen; do
98
+ [ -n "$listen" ] || continue
99
+ p="${listen##*:}"; a="${listen%:*}"; a="${a#[}"; a="${a%]}"
101
100
  case "$p" in ''|*[!0-9]*) continue ;; esac
102
101
  [ "$a" = "127.0.0.11" ] && continue
103
102
  [ "$p" -lt 1024 ] 2>/dev/null && continue
104
103
  case "$p" in 5432|8929|2224) continue ;; esac
105
- case ",$(lire_ports)," in *",$p,"*) continue ;; esac
106
- port_exclu "$p" && continue
104
+ case ",$(read_ports)," in *",$p,"*) continue ;; esac
105
+ port_excluded "$p" && continue
107
106
  [ "$a" = "$IP" ] && continue
108
- printf '%s %s\n' "$a" "$p" >>"$COURANT"
107
+ printf '%s %s\n' "$a" "$p" >>"$CURRENT"
109
108
  done
110
- awk '{print $2}' "$COURANT" 2>/dev/null | sort -n -u >"$BASE/actuels"
111
- awk '$1=="0.0.0.0" || $1=="::" || $1=="*" || $1==":::" {print $2}' "$COURANT" 2>/dev/null | sort -n -u >"$BASE/allif"
109
+ awk '{print $2}' "$CURRENT" 2>/dev/null | sort -n -u >"$BASE/actuels"
110
+ awk '$1=="0.0.0.0" || $1=="::" || $1=="*" || $1==":::" {print $2}' "$CURRENT" 2>/dev/null | sort -n -u >"$BASE/allif"
112
111
  : >"$BASE/managed"
113
- [ -f "$ACTIFS" ] && cat "$ACTIFS" >>"$BASE/managed"
112
+ [ -f "$ACTIVE" ] && cat "$ACTIVE" >>"$BASE/managed"
114
113
  for f in "$BRIDGES"/*.pid; do [ -e "$f" ] || continue; basename "${f%.pid}" >>"$BASE/managed"; done
115
- [ -f "$OCCUPES" ] && cat "$OCCUPES" >>"$BASE/managed"
114
+ [ -f "$BUSY" ] && cat "$BUSY" >>"$BASE/managed"
116
115
  sort -n -u "$BASE/managed" -o "$BASE/managed" 2>/dev/null || true
117
116
 
118
- now="$(date +%s)"; delay="$(delai_disparition)"
117
+ now="$(date +%s)"; delay="$(disappearance_delay)"
119
118
  while IFS= read -r port; do
120
119
  [ -n "$port" ] || continue
121
- grep -qxF "$port" "$OCCUPES" 2>/dev/null && continue
122
- grep -qxF "$port" "$ACTIFS" 2>/dev/null && continue
123
- grep -qxF "$port" "$BASE/allif" || demarrer_pont "$port" "$IP"
120
+ grep -qxF "$port" "$BUSY" 2>/dev/null && continue
121
+ grep -qxF "$port" "$ACTIVE" 2>/dev/null && continue
122
+ grep -qxF "$port" "$BASE/allif" || start_bridge "$port" "$IP"
124
123
  # shellcheck disable=SC2153
125
- if sortie="$(lancer_auto "$port" "$RESEAU" "$IP" 2>&1)"; then
126
- grep -qxF "$port" "$ACTIFS" 2>/dev/null || echo "$port" >>"$ACTIFS"
124
+ if output="$(launch_auto "$port" "$NETWORK" "$IP" 2>&1)"; then
125
+ grep -qxF "$port" "$ACTIVE" 2>/dev/null || echo "$port" >>"$ACTIVE"
127
126
  else
128
- printf '%s\n' "$sortie" >&2
129
- grep -qxF "$port" "$BASE/allif" || arreter_pont "$port"
130
- case "$sortie" in *"déjà utilisé sur le poste"*|*"already in use"*|*"already allocated"*) echo "$port" >>"$OCCUPES" ;; esac
127
+ printf '%s\n' "$output" >&2
128
+ grep -qxF "$port" "$BASE/allif" || stop_bridge "$port"
129
+ case "$output" in *"already in use"*|*"already allocated"*) echo "$port" >>"$BUSY" ;; esac
131
130
  fi
132
131
  done <"$BASE/actuels"
133
132
 
134
133
  while IFS= read -r port; do
135
134
  [ -n "$port" ] || continue
136
135
  grep -qxF "$port" "$BASE/actuels" 2>/dev/null && continue
137
- if grep -qxF "$port" "$OCCUPES" 2>/dev/null; then
138
- grep -vxF "$port" "$OCCUPES" >"$OCCUPES.tmp" 2>/dev/null || true; mv "$OCCUPES.tmp" "$OCCUPES" 2>/dev/null || true
139
- arreter_pont "$port"; continue
136
+ if grep -qxF "$port" "$BUSY" 2>/dev/null; then
137
+ grep -vxF "$port" "$BUSY" >"$BUSY.tmp" 2>/dev/null || true; mv "$BUSY.tmp" "$BUSY" 2>/dev/null || true
138
+ stop_bridge "$port"; continue
140
139
  fi
141
140
  if grep -q "^$port " "$PENDING" 2>/dev/null; then
142
- ancien="$(grep "^$port " "$PENDING" | head -1 | cut -d' ' -f2)"
143
- # Rien ne se retire sur un état restauré non confirmé (#417)
141
+ old="$(grep "^$port " "$PENDING" | head -1 | cut -d' ' -f2)"
142
+ # Nothing is removed on an unconfirmed restored state (#417)
144
143
  if state_recovery_pending; then continue; fi
145
- if [ -n "$ancien" ] && [ "$(( now - ancien ))" -ge "$delay" ]; then
146
- fermer_auto "$port"
144
+ if [ -n "$old" ] && [ "$(( now - old ))" -ge "$delay" ]; then
145
+ close_auto "$port"
147
146
  grep -v "^$port " "$PENDING" >"$PENDING.tmp" 2>/dev/null || true; mv "$PENDING.tmp" "$PENDING" 2>/dev/null || true
148
- grep -vxF "$port" "$ACTIFS" >"$ACTIFS.tmp" 2>/dev/null || true; mv "$ACTIFS.tmp" "$ACTIFS" 2>/dev/null || true
147
+ grep -vxF "$port" "$ACTIVE" >"$ACTIVE.tmp" 2>/dev/null || true; mv "$ACTIVE.tmp" "$ACTIVE" 2>/dev/null || true
149
148
  fi
150
149
  else
151
150
  echo "$port $now" >>"$PENDING"
@@ -158,91 +157,91 @@ ports_auto_tour() {
158
157
  done <"$BASE/actuels"
159
158
  }
160
159
 
161
- # Arrête le veilleur et nettoie ses relais.
162
- arreter_veilleur() { local pid; pid="$(cat "$VERROU/pid" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi; nettoyer_auto_tout; rm -rf "$VERROU"; }
160
+ # Stops the watcher and cleans its relays.
161
+ stop_watcher() { local pid; pid="$(cat "$LOCK/pid" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi; clean_auto_all; rm -rf "$LOCK"; }
163
162
 
164
- # Boucle : un tour toutes les DEVZONE_PORTS_AUTO_PAS secondes.
165
- ports_auto_boucle() {
166
- if ! verrou_prendre; then return 0; fi
167
- nettoyer_precedents
168
- trap 'nettoyer_auto_tout; rm -rf "$VERROU"' EXIT INT TERM
163
+ # Loop: one pass every DEVZONE_PORTS_AUTO_STEP seconds.
164
+ auto_loop() {
165
+ if ! lock_take; then return 0; fi
166
+ clean_previous
167
+ trap 'clean_auto_all; rm -rf "$LOCK"' EXIT INT TERM
169
168
  while true; do
170
- # État restauré ou reconstruit : rien pendant 60 s (#417, étape 4)
169
+ # State restored or rebuilt: nothing for 60 s (#417, step 4)
171
170
  if state_recovery_wait; then
172
- verrou_rafraichir
173
- sleep "${DEVZONE_PORTS_AUTO_PAS:-2}"
171
+ lock_refresh
172
+ sleep "${DEVZONE_PORTS_AUTO_STEP:-2}"
174
173
  continue
175
174
  fi
176
- # Dossier d'état disparu : le conteneur est parti, le veilleur s'arrête.
177
- if [ ! -f "$ETAT" ]; then nettoyer_auto_tout; break; fi
178
- verrou_rafraichir
179
- if [ "$(ports_auto_actif)" = off ]; then
180
- # Jamais de désinstallation sur un état non confirmé (#417)
181
- state_recovery_pending || nettoyer_auto_tout
175
+ # State folder gone: the container has left, the watcher stops.
176
+ if [ ! -f "$ETAT" ]; then clean_auto_all; break; fi
177
+ lock_refresh
178
+ if [ "$(auto_enabled)" = off ]; then
179
+ # Never uninstall on an unconfirmed state (#417)
180
+ state_recovery_pending || clean_auto_all
182
181
  break
183
182
  fi
184
- ports_auto_tour || true
185
- sleep "${DEVZONE_PORTS_AUTO_PAS:-2}"
183
+ auto_pass || true
184
+ sleep "${DEVZONE_PORTS_AUTO_STEP:-2}"
186
185
  done
187
186
  }
188
187
 
189
- # Exclut un port de la liste automatique (écrit ports_exclus=).
190
- ports_auto_exclure() { valider_port "${1:-}"; local cur; cur="$(ports_exclus_lus)"; case ",$cur," in *",$1,"*) echo "port $1 déjà exclu"; return 0 ;; esac; ecrire ports_exclus "$(trier_ports "$cur,$1")"; echo "✔ port $1 exclu"; }
191
- # Réintègre un port à la liste automatique (retire ports_exclus=).
192
- ports_auto_inclure() { valider_port "${1:-}"; local cur reste p; cur="$(ports_exclus_lus)"; reste=""; for p in $(printf '%s' "$cur" | tr ',' ' '); do [ "$p" = "$1" ] || reste="$reste${reste:+,}$p"; done; ecrire ports_exclus "$(trier_ports "$reste")"; echo "✔ port $1 inclus"; }
188
+ # Excludes a port from the automatic list (writes ports_exclus=).
189
+ auto_exclude() { validate_port "${1:-}"; local current; current="$(excluded_read)"; case ",$current," in *",$1,"*) echo "port $1 already excluded"; return 0 ;; esac; write_key ports_exclus "$(sort_ports "$current,$1")"; echo "✔ port $1 excluded"; }
190
+ # Puts a port back in the automatic list (removes it from ports_exclus=).
191
+ auto_include() { validate_port "${1:-}"; local current rest p; current="$(excluded_read)"; rest=""; for p in $(printf '%s' "$current" | tr ',' ' '); do [ "$p" = "$1" ] || rest="$rest${rest:+,}$p"; done; write_key ports_exclus "$(sort_ports "$rest")"; echo "✔ port $1 included"; }
193
192
 
194
- # Liste les relais automatiques en vie (ou occupés sur le poste).
195
- ports_auto_liste() {
196
- local port marque app
197
- if [ -f "$ACTIFS" ]; then
193
+ # Lists the automatic relays alive (or busy on the workstation).
194
+ auto_list() {
195
+ local port mark app
196
+ if [ -f "$ACTIVE" ]; then
198
197
  while IFS= read -r port; do
199
198
  [ -n "$port" ] || continue
200
- if grep -qxF "$port" "$OCCUPES" 2>/dev/null; then printf ' %-5s %s auto\n' "$port" "occupé sur le poste"; continue; fi
201
- if relais_auto_actif "$port"; then marque="● actif"; else marque="○ arrêté"; fi
202
- if application_repond "$port"; then app="$APP_REPOND"; else app="$APP_AUCUNE"; fi
203
- printf ' %-5s %s auto %s\n' "$port" "$marque" "$app"
204
- done <"$ACTIFS"
199
+ if grep -qxF "$port" "$BUSY" 2>/dev/null; then printf ' %-5s %s auto\n' "$port" "busy on the workstation"; continue; fi
200
+ if auto_relay_active "$port"; then mark="● active"; else mark="○ stopped"; fi
201
+ if app_responds "$port"; then app="$APP_RESPONDS"; else app="$APP_NONE"; fi
202
+ printf ' %-5s %s auto %s\n' "$port" "$mark" "$app"
203
+ done <"$ACTIVE"
205
204
  fi
206
- if [ -f "$OCCUPES" ]; then
205
+ if [ -f "$BUSY" ]; then
207
206
  while IFS= read -r port; do
208
207
  [ -n "$port" ] || continue
209
- grep -qxF "$port" "$ACTIFS" 2>/dev/null && continue
210
- printf ' %-5s %s auto\n' "$port" "occupé sur le poste"
211
- done <"$OCCUPES"
208
+ grep -qxF "$port" "$ACTIVE" 2>/dev/null && continue
209
+ printf ' %-5s %s auto\n' "$port" "busy on the workstation"
210
+ done <"$BUSY"
212
211
  fi
213
212
  }
214
213
 
215
- # Sortie machine (jq) des relais automatiques.
216
- ports_auto_liste_json() {
217
- local port actif app json='[]' ports=""
218
- [ -f "$ACTIFS" ] && ports="$(cat "$ACTIFS")"
219
- [ -f "$OCCUPES" ] && ports="$ports"$'\n'"$(cat "$OCCUPES")"
214
+ # Machine output (jq) of the automatic relays.
215
+ auto_list_json() {
216
+ local port active app json='[]' ports=""
217
+ [ -f "$ACTIVE" ] && ports="$(cat "$ACTIVE")"
218
+ [ -f "$BUSY" ] && ports="$ports"$'\n'"$(cat "$BUSY")"
220
219
  ports="$(printf '%s\n' "$ports" | awk 'NF' | sort -n -u)"
221
220
  while IFS= read -r port; do
222
221
  [ -n "$port" ] || continue
223
- if grep -qxF "$port" "$OCCUPES" 2>/dev/null; then
224
- json="$(jq -c --argjson port "$port" '. + [{port:$port,actif:false,application:"occupé sur le poste",auto:true}]' <<<"$json")"; continue
222
+ if grep -qxF "$port" "$BUSY" 2>/dev/null; then
223
+ json="$(jq -c --argjson port "$port" --arg busy "$JSON_APP_BUSY" '. + [{port:$port,active:false,application:$busy,auto:true}]' <<<"$json")"; continue
225
224
  fi
226
- if relais_auto_actif "$port"; then actif=true; else actif=false; fi
227
- if application_repond "$port"; then app="$APP_REPOND"; else app="$APP_AUCUNE"; fi
228
- json="$(jq -c --argjson port "$port" --argjson actif "$actif" --arg app "$app" '. + [{port:$port,actif:$actif,application:$app,auto:true}]' <<<"$json")"
225
+ if auto_relay_active "$port"; then active=true; else active=false; fi
226
+ if app_responds "$port"; then app="$JSON_APP_RESPONDS"; else app="$JSON_APP_NONE"; fi
227
+ json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" '. + [{port:$port,active:$active,application:$app,auto:true}]' <<<"$json")"
229
228
  done <<<"$ports"
230
229
  printf '%s\n' "$json"
231
230
  }
232
231
 
233
232
  if [ "${BASH_SOURCE[0]}" = "$0" ]; then
234
233
  case "${1:-}" in
235
- ''|boucle|loop) if ! garde_veilleur; then exit 2; fi; ports_auto_boucle ;;
236
- tour|one|un-tour) ports_auto_tour ;;
237
- demarrer|start|lancer) if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then echo "ports: Kubernetes workspace, ports go through devzone workspace ports"; exit 0; fi; if ! garde_veilleur; then exit 2; fi; if kill -0 "$(cat "$VERROU/pid" 2>/dev/null)" 2>/dev/null; then echo "déjà lancé"; else DEVZONE_PORTS_AUTO_REEL=oui bash "$0" boucle >/dev/null 2>&1 & echo "lancé"; fi ;;
238
- arreter|stop) arreter_veilleur; echo "arrêté" ;;
239
- nettoyer|clean) nettoyer_auto_tout ;;
240
- auto) case "${2:-}" in on) ecrire ports_auto on; echo "✔ ports auto activés" ;; off) ecrire ports_auto off; arreter_veilleur; echo "✔ ports auto désactivés" ;; *) echo "devzone : port : auto on|off" >&2; exit 2 ;; esac ;;
241
- exclude|exclure) ports_auto_exclure "${2:-}" ;;
242
- include|inclure) ports_auto_inclure "${2:-}" ;;
243
- liste_auto) ports_auto_liste ;;
244
- liste_json_auto) ports_auto_liste_json ;;
234
+ ''|boucle|loop) if ! guard_watcher; then exit 2; fi; auto_loop ;;
235
+ tour|one|un-tour) auto_pass ;;
236
+ demarrer|start|lancer) if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then echo "ports: Kubernetes workspace, ports go through devzone workspace ports"; exit 0; fi; if ! guard_watcher; then exit 2; fi; if kill -0 "$(cat "$LOCK/pid" 2>/dev/null)" 2>/dev/null; then echo "already running"; else DEVZONE_PORTS_AUTO_REAL=yes bash "$0" boucle >/dev/null 2>&1 & echo "started"; fi ;;
237
+ arreter|stop) stop_watcher; echo "stopped" ;;
238
+ nettoyer|clean) clean_auto_all ;;
239
+ auto) case "${2:-}" in on) write_key ports_auto on; echo "✔ automatic ports enabled" ;; off) write_key ports_auto off; stop_watcher; echo "✔ automatic ports disabled" ;; *) echo "devzone : port : auto on|off" >&2; exit 2 ;; esac ;;
240
+ exclude|exclure) auto_exclude "${2:-}" ;;
241
+ include|inclure) auto_include "${2:-}" ;;
242
+ list_auto) auto_list ;;
243
+ list_json_auto) auto_list_json ;;
245
244
  -h|--help|aide) sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//' ;;
246
- *) echo "devzone : ports-auto : commande inconnue : ${1:-}" >&2; exit 2 ;;
245
+ *) echo "devzone : ports-auto : unknown command : ${1:-}" >&2; exit 2 ;;
247
246
  esac
248
247
  fi
@@ -1,32 +1,33 @@
1
1
  #!/usr/bin/env bash
2
- # JSON output of the port relays (#557) : the array
3
- # [{port,actif,application,auto}] read by the tools (devzone status --json).
2
+ # JSON output of the port relays (#557): the array
3
+ # [{port,active,application,auto}] read by the tools (devzone status --json).
4
+ # The keys and the application values are a contract.
4
5
  # Sourced by ports.sh, which holds the functions used here.
5
6
 
6
- # JSON list of the relays of the state : jq only
7
- liste_json() {
8
- local ports port actif app json='[]'
9
- ports="$(trier_ports "$(lire_ports)")"
7
+ # JSON list of the relays of the state: jq only
8
+ list_json() {
9
+ local ports port active app json='[]'
10
+ ports="$(sort_ports "$(read_ports)")"
10
11
  if [ -z "$ports" ]; then
11
12
  printf '[]\n'
12
13
  return 0
13
14
  fi
14
15
  # shellcheck disable=SC2046 # list of ports separated by commas
15
16
  for port in $(printf '%s' "$ports" | tr ',' ' '); do
16
- if relais_actif "$port"; then
17
- actif=true
17
+ if relay_active "$port"; then
18
+ active=true
18
19
  else
19
- actif=false
20
+ active=false
20
21
  fi
21
- if application_repond "$port"; then
22
- app="$APP_REPOND"
22
+ if app_responds "$port"; then
23
+ app="$JSON_APP_RESPONDS"
23
24
  else
24
- app="$APP_AUCUNE"
25
+ app="$JSON_APP_NONE"
25
26
  fi
26
- json="$(jq -c --argjson port "$port" --argjson actif "$actif" --arg app "$app" \
27
- '. + [{port:$port,actif:$actif,application:$app,auto:false}]' <<<"$json")"
27
+ json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" \
28
+ '. + [{port:$port,active:$active,application:$app,auto:false}]' <<<"$json")"
28
29
  done
29
- auto_json="$(bash "$ICI/ports-auto.sh" liste_json_auto 2>/dev/null || echo '[]')"
30
+ auto_json="$(bash "$HERE/ports-auto.sh" list_json_auto 2>/dev/null || echo '[]')"
30
31
  if [ -n "$auto_json" ] && [ "$auto_json" != "[]" ]; then
31
32
  json="$(jq -s 'add' <<<"$json"$'\n'"$auto_json")"
32
33
  fi