devzone 7.4.0 → 7.5.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 (48) hide show
  1. package/.devcontainer/devzone +18 -63
  2. package/.devcontainer/devzone-modules.sh +8 -3
  3. package/.devcontainer/devzone-repair.sh +7 -7
  4. package/.devcontainer/devzone-services.sh +21 -21
  5. package/.devcontainer/devzone-status.sh +12 -9
  6. package/.devcontainer/help.sh +5 -1
  7. package/.devcontainer/versions.env +8 -0
  8. package/.devcontainer/workspace-init.sh +8 -9
  9. package/.gitattributes +8 -0
  10. package/README.md +2 -2
  11. package/bin/SHA256SUMS +6 -6
  12. package/bin/devzone-darwin-amd64 +0 -0
  13. package/bin/devzone-darwin-arm64 +0 -0
  14. package/bin/devzone-linux-amd64 +0 -0
  15. package/bin/devzone-linux-arm64 +0 -0
  16. package/bin/devzone-windows-amd64.exe +0 -0
  17. package/bin/devzone-windows-arm64.exe +0 -0
  18. package/charts/devzone-mysql/values.yaml +1 -1
  19. package/charts/devzone-postgres/values.yaml +1 -1
  20. package/manage/devzone +6 -3
  21. package/manage/scripts/create-mode.sh +3 -3
  22. package/manage/scripts/uninstall.sh +4 -5
  23. package/manage/scripts/workspace/argocd-workspace.sh +2 -2
  24. package/manage/workspace.sh +1 -1
  25. package/package.json +1 -1
  26. package/.devcontainer/ai/host-check.sh +0 -173
  27. package/.devcontainer/ai/host-models.sh +0 -200
  28. package/.devcontainer/catalog/app.sh +0 -202
  29. package/.devcontainer/catalog/catalog-watcher.sh +0 -127
  30. package/.devcontainer/catalog.sh +0 -208
  31. package/.devcontainer/chart-direct.sh +0 -49
  32. package/.devcontainer/cluster.sh +0 -388
  33. package/.devcontainer/clusters.sh +0 -86
  34. package/.devcontainer/devzone-ai-guard.sh +0 -98
  35. package/.devcontainer/devzone-ai.sh +0 -201
  36. package/.devcontainer/devzone-cluster.sh +0 -209
  37. package/.devcontainer/devzone-skill.sh +0 -97
  38. package/.devcontainer/isolation.sh +0 -65
  39. package/.devcontainer/kube-account.sh +0 -107
  40. package/.devcontainer/kube-prompt.sh +0 -42
  41. package/.devcontainer/memory.sh +0 -113
  42. package/.devcontainer/metrics-server.sh +0 -100
  43. package/.devcontainer/packages.sh +0 -228
  44. package/.devcontainer/password.sh +0 -148
  45. package/.devcontainer/ports-json.sh +0 -31
  46. package/.devcontainer/ports.sh +0 -132
  47. package/manage/scripts/create-cluster.sh +0 -107
  48. package/manage/scripts/docker.sh +0 -43
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Kubernetes prompt of the shell (#337): ⎈ ctx/ns.
3
-
4
- # Renders the Kubernetes prompt (⎈ ctx/ns), with a cache keyed on the mtime.
5
- devzone_kube_prompt() {
6
- local kubeconfig="${KUBECONFIG:-$HOME/.kube/config:$HOME/.kube/hote.config}"
7
- local files=() f sig="" cache mtime ctx ns result ici
8
- ici="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
- IFS=':' read -ra files <<<"$kubeconfig"
10
- for f in "${files[@]}"; do
11
- [ -n "$f" ] || continue
12
- if [ -f "$f" ]; then
13
- mtime="$(stat -c '%Y' "$f" 2>/dev/null || echo 0)"
14
- else
15
- mtime="missing"
16
- fi
17
- sig+="${f}:${mtime};"
18
- done
19
- cache="${XDG_CACHE_HOME:-$HOME/.cache}/devzone-kube-prompt"
20
- mkdir -p "$(dirname "$cache")"
21
- if [ -f "$cache" ]; then
22
- if [ "$(sed -n '1p' "$cache" 2>/dev/null)" = "$sig" ]; then
23
- sed -n '2p' "$cache" 2>/dev/null
24
- return 0
25
- fi
26
- fi
27
- ctx="$(kubectl config current-context 2>/dev/null || true)"
28
- if [ -z "$ctx" ]; then
29
- result=""
30
- else
31
- ns="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.namespace}" 2>/dev/null || true)"
32
- [ -n "$ns" ] || ns=default
33
- # shellcheck disable=SC1090,SC1091
34
- if ( . "$ici/cluster.sh"; cluster_is_local "$ctx" ) >/dev/null 2>&1; then
35
- result="$(printf '\001\033[36m\002⎈ %s/%s\001\033[0m\002' "$ctx" "$ns")"
36
- else
37
- result="$(printf '\001\033[1;31m\002⎈ %s/%s remote\001\033[0m\002' "$ctx" "$ns")"
38
- fi
39
- fi
40
- printf '%s\n%s\n' "$sig" "$result" >"$cache"
41
- printf '%s\n' "$result"
42
- }
@@ -1,113 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Memory check of the services cluster (#608, #612): a module refuses its
3
- # installation when the allocatable memory of the nodes is below its minimum.
4
- # Sourced by the modules (gitlab, llm) and by the tests; bash 3.2 (macOS).
5
- # quantity_ki <quantity> Kubernetes quantity in Ki
6
- # memory_cluster_ki allocatable memory of the cluster, in Ki
7
- # check_module_memory <module> <minimum_gi> [hint]
8
- # Messages in English. Return 0 when the memory is enough, 2 when it is not or
9
- # when the cluster is unreachable.
10
-
11
- # Globals written by memory_cluster_ki (#612) and read by
12
- # check_module_memory, which calls the function directly: a call written
13
- # memory="$(memory_cluster_ki)" would run it in a subshell and lose them.
14
- # Callers that only need the number keep using $(memory_cluster_ki): the
15
- # value is still printed on stdout (argocd, gitlab, llm are unaffected).
16
- # MEMORY_KI same value as on stdout, in Ki
17
- # MEMORY_RULE "maximum" when every node is a kind node (the nodes share
18
- # one VM), "sum" otherwise
19
- MEMORY_KI=""
20
- MEMORY_RULE=""
21
-
22
- # Converts a Kubernetes memory quantity (Ki, Mi, Gi, Ti, K, M, G, bytes)
23
- # into Ki, to total the allocatable memory of the nodes.
24
- quantity_ki() {
25
- local q="${1:-}" number
26
- case "$q" in
27
- *Ki) number="${q%Ki}"; echo $((number)) ;;
28
- *Mi) number="${q%Mi}"; echo $((number * 1024)) ;;
29
- *Gi) number="${q%Gi}"; echo $((number * 1024 * 1024)) ;;
30
- *Ti) number="${q%Ti}"; echo $((number * 1024 * 1024 * 1024)) ;;
31
- *K | *k) number="${q%[Kk]}"; echo $((number * 1000 / 1024)) ;;
32
- *M) number="${q%M}"; echo $((number * 1000 * 1000 / 1024)) ;;
33
- *G) number="${q%G}"; echo $((number * 1000 * 1000 * 1000 / 1024)) ;;
34
- *)
35
- case "$q" in
36
- '' | *[!0-9]*) echo 0 ;;
37
- *) echo $((q / 1024)) ;;
38
- esac
39
- ;;
40
- esac
41
- }
42
-
43
- # Allocatable memory of the services cluster nodes, in Ki. Reading the nodes
44
- # is reserved to the administrator (#430). One kubectl call gives, per node,
45
- # its providerID and its allocatable memory on one "<providerID>|<memory>"
46
- # line (#612). A kind cluster runs on a single Docker daemon: its nodes share
47
- # the memory of one VM and each of them declares the whole VM, so adding them
48
- # up lies. When every providerID starts with "kind://" the greatest node
49
- # memory is returned (MEMORY_RULE=maximum); as soon as one node has no such
50
- # prefix or an empty providerID the sum is returned (MEMORY_RULE=sum), as
51
- # before. Known limit, documented: k3d and minikube in Docker mode share a VM
52
- # too but are not kind, they stay on the sum. A line without the separator
53
- # carries the memory alone, so it is a node without providerID (sum).
54
- memory_cluster_ki() {
55
- local output line providerID memory node total=0 max=0 n=0 all_kind=1
56
- MEMORY_KI=""
57
- MEMORY_RULE=""
58
- output="$(account_admin "$(account_context)" get nodes \
59
- -o jsonpath='{range .items[*]}{.spec.providerID}{"|"}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || return 1
60
- [ -n "$output" ] || return 1
61
- while IFS= read -r line; do
62
- [ -n "$line" ] || continue
63
- case "$line" in
64
- *'|'*)
65
- providerID="${line%%|*}"
66
- memory="${line#*|}"
67
- ;;
68
- *)
69
- providerID=""
70
- memory="$line"
71
- ;;
72
- esac
73
- node="$(quantity_ki "$memory")"
74
- total=$((total + node))
75
- if [ "$node" -gt "$max" ]; then max="$node"; fi
76
- case "$providerID" in
77
- kind://*) ;;
78
- *) all_kind=0 ;;
79
- esac
80
- n=$((n + 1))
81
- done <<<"$output"
82
- if [ "$n" -gt 0 ] && [ "$all_kind" -eq 1 ]; then
83
- MEMORY_RULE="maximum"
84
- MEMORY_KI="$max"
85
- else
86
- MEMORY_RULE="sum"
87
- MEMORY_KI="$total"
88
- fi
89
- echo "$MEMORY_KI"
90
- }
91
-
92
- # Refuses the installation of <module> under <minimum_gi> GiB of allocatable
93
- # memory. The message says the minimum, the available memory and how to enlarge
94
- # the cluster; [hint] adds an optional hint (for example --preset light).
95
- # On a kind cluster (#612) the available memory is the one of a single node
96
- # and the message says so. Return 0 when the memory is enough, 2 when it is
97
- # not or the cluster is unreachable.
98
- check_module_memory() {
99
- local module_name="$1" minimum_gi="$2" hint="${3:-}" memory precision=""
100
- if ! memory_cluster_ki >/dev/null; then
101
- echo "devzone : ${module_name} : services cluster unreachable: devzone cluster" >&2
102
- return 2
103
- fi
104
- memory="$MEMORY_KI"
105
- if [ "$MEMORY_RULE" = "maximum" ]; then
106
- precision=" (memory of a single node: kind cluster, shared VM)"
107
- fi
108
- if [ "$memory" -lt "$((minimum_gi * 1048576))" ]; then
109
- echo "devzone : ${module_name} : at least ${minimum_gi} GiB of allocatable memory is needed in the cluster (available: $((memory / 1048576)) GiB)${precision} ; enlarge the cluster (Docker Desktop → Settings → Resources) then retry: devzone enable ${module_name}${hint:+ ; hint: ${hint}}" >&2
110
- return 2
111
- fi
112
- return 0
113
- }
@@ -1,100 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Installs metrics-server (CPU/RAM in k9s, kubectl top) on the clusters that
3
- # have no Metrics API. Docker Desktop and kind do not have it by default.
4
- # Usage: metrics-server.sh [context...] | metrics-server.sh retirer [context...]
5
- # (default: reachable local clusters; retirer, the public subcommand
6
- # name kept as is: removal from the clusters where devzone installed it)
7
- # --kubelet-insecure-tls: the kubelet of Docker Desktop and kind has a
8
- # self-signed certificate, without this option the pod never becomes Ready.
9
- # Exits in error if a requested context is unknown or unreachable, or if an
10
- # installation fails.
11
- set -euo pipefail
12
-
13
- # shellcheck source=SCRIPTDIR/cluster.sh
14
- . "$(dirname "$0")/cluster.sh"
15
-
16
- VERSION=v0.9.0
17
- MANIFEST="https://github.com/kubernetes-sigs/metrics-server/releases/download/${VERSION}/components.yaml"
18
-
19
- mapfile -t known < <(kubectl config get-contexts -o name 2>/dev/null || true)
20
-
21
- if [ "${1:-}" = retirer ]; then
22
- shift
23
- # Removal (kubernetes module disabled): only the contexts where devzone
24
- # installed metrics-server (devzone=installe mark) are removed
25
- requested=$#
26
- if [ "$requested" -eq 0 ]; then
27
- # Local clusters only: removal on a remote cluster has nothing to remove
28
- # (devzone never installs there)
29
- mapfile -t contexts < <(printf '%s\n' ${known[@]+"${known[@]}"} |
30
- while IFS= read -r c; do cluster_is_local "$c" && echo "$c"; done || true)
31
- set -- ${contexts[@]+"${contexts[@]}"}
32
- fi
33
- code=0
34
- for context in "$@"; do
35
- # Mark read on the deployment by its name: kubectl refuses a name with
36
- # a selector (-l), the test would always be false (#255)
37
- mark="$(kubectl --context "$context" -n kube-system get deployment metrics-server \
38
- -o jsonpath='{.metadata.labels.devzone}' 2>/dev/null || true)"
39
- if [ "$mark" = installe ]; then
40
- if kubectl --context "$context" delete -f "$MANIFEST" --ignore-not-found >/dev/null 2>&1; then
41
- echo "metrics-server removed ($VERSION) : $context"
42
- else
43
- echo "metrics-server : removal failed: $context" >&2
44
- code=1
45
- fi
46
- elif kubectl --context "$context" -n kube-system get deployment metrics-server >/dev/null 2>&1; then
47
- # Installed by someone else: not up to devzone to remove it
48
- echo "metrics-server present without a devzone mark, left: $context" >&2
49
- fi
50
- done
51
- exit "$code"
52
- fi
53
-
54
- requested=$#
55
- if [ "$requested" -eq 0 ]; then
56
- # Local clusters only: never an automatic installation on a remote cluster
57
- # of the host (prod, staging…); for another one, name it as an argument
58
- mapfile -t contexts < <(printf '%s\n' ${known[@]+"${known[@]}"} |
59
- while IFS= read -r c; do cluster_is_local "$c" && echo "$c"; done || true)
60
- set -- ${contexts[@]+"${contexts[@]}"}
61
- fi
62
-
63
- code=0
64
- reachable=0
65
- for context in "$@"; do
66
- if [ "$requested" -gt 0 ] && ! printf '%s\n' ${known[@]+"${known[@]}"} | grep -qxF -- "$context"; then
67
- echo "metrics-server : unknown context: $context (see kubectl config get-contexts)" >&2
68
- code=1
69
- continue
70
- fi
71
- k=(kubectl --context "$context" --request-timeout=5s)
72
- if ! "${k[@]}" get --raw /readyz >/dev/null 2>&1; then
73
- # Without argument: kind may still be starting, ignored
74
- if [ "$requested" -gt 0 ]; then
75
- echo "metrics-server : cluster unreachable: $context" >&2
76
- code=1
77
- fi
78
- continue
79
- fi
80
- reachable=$((reachable + 1))
81
- if "${k[@]}" get apiservice v1beta1.metrics.k8s.io >/dev/null 2>&1; then
82
- echo "metrics-server : already present: $context"
83
- continue
84
- fi
85
- if "${k[@]}" apply -f "$MANIFEST" >/dev/null &&
86
- "${k[@]}" -n kube-system patch deployment metrics-server --type=json \
87
- -p '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]' >/dev/null &&
88
- # Mark: make desinstaller only removes what devzone installed
89
- "${k[@]}" -n kube-system label deployment metrics-server devzone=installe app.kubernetes.io/managed-by=devzone --overwrite >/dev/null; then
90
- echo "metrics-server : installed ($VERSION): $context (metrics within ~1 min)"
91
- else
92
- echo "metrics-server : installation failed: $context" >&2
93
- code=1
94
- fi
95
- done
96
-
97
- if [ "$requested" -eq 0 ] && [ "$reachable" -eq 0 ]; then
98
- echo "metrics-server : no reachable local cluster; after kind create cluster: bash .devcontainer/metrics-server.sh"
99
- fi
100
- exit "$code"
@@ -1,228 +0,0 @@
1
- #!/usr/bin/env bash
2
- # System packages kept after a rebuild (#351): a list in the devzone folder
3
- # (<root>/.devzone.packages, a comment header + one package name per line, sorted,
4
- # without duplicates), reinstalled at each container creation.
5
- # A package installed by hand is lost by a rebuild, unless it is in this list.
6
- # packages.sh or packages.sh list list with the state of each package
7
- # packages.sh add <name>… validates, installs, adds to the list
8
- # packages.sh remove <name>… removes from the list and uninstalls (except image packages)
9
- # packages.sh apply installs everything missing
10
- # The state of a package comes from dpkg-query -W -f='${Status}'; the system
11
- # commands go through overridable variables for the tests (sudo, apt-get,
12
- # apt-cache, dpkg-query, mark, timestamp). Compatible with bash 3.2 (macOS).
13
- set -euo pipefail
14
-
15
- HERE="$(cd "$(dirname "$0")" && pwd)"
16
- ROOT="${DEVZONE_ROOT:-$(dirname "$HERE")}"
17
- LIST="${ROOT}/.devzone.packages"
18
- MARK="${DEVZONE_PACKAGES_MARKER:-/tmp/devzone-packages.failed}"
19
- UPDATED="${DEVZONE_PACKAGES_UPDATE:-/tmp/devzone-packages.updated}"
20
- SUDO="${DEVZONE_PACKAGES_SUDO-sudo}"
21
- APT="${DEVZONE_PACKAGES_APT:-apt-get}"
22
- APTCACHE="${DEVZONE_PACKAGES_APTCACHE:-apt-cache}"
23
- DPKGQUERY="${DEVZONE_PACKAGES_DPKG_QUERY:-dpkg-query}"
24
- FORMAT="-f=\${Status}"
25
- # Stored values, kept byte for byte (the users' list file): the header and the
26
- # « already present » mark are written in UTF-8 as byte escapes (contract).
27
- HEADER=$'# paquets ajout\303\251s par devzone packages add ; r\303\251install\303\251s \303\240 chaque cr\303\251ation du conteneur'
28
- PRESENT_MARK=$'# d\303\251j\303\240 pr\303\251sent'
29
-
30
-
31
- refuse() { echo "devzone : packages : $*" >&2; exit 1; }
32
-
33
- as_root() {
34
- if [ -n "$SUDO" ]; then
35
- "$SUDO" "$@"
36
- else
37
- env "$@"
38
- fi
39
- }
40
-
41
- is_installed() {
42
- "$DPKGQUERY" -W "$FORMAT" "$1" 2>/dev/null | grep -q 'install ok installed'
43
- }
44
-
45
- # List lines as they are (name, or name followed by the present mark).
46
- list_lines() {
47
- [ -f "$LIST" ] || return 0
48
- grep -vE '^[[:space:]]*(#|$)' "$LIST" 2>/dev/null |
49
- sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d' |
50
- sort -k1,1 -u || true
51
- }
52
-
53
- # Names only: the end-of-line mark is ignored.
54
- list_names() {
55
- list_lines | sed -e 's/[[:space:]]*#.*$//' | sort -u || true
56
- }
57
-
58
- name_listed() {
59
- local name
60
- while IFS= read -r name; do
61
- [ "$name" = "$1" ] && return 0
62
- done < <(list_names)
63
- return 1
64
- }
65
-
66
- # True if the package was marked as already present in the image.
67
- mark_present() {
68
- grep -qxF -e "$1 $PRESENT_MARK" "$LIST" 2>/dev/null
69
- }
70
-
71
- # Rewrites the list: a single header, then the given lines (sorted by name).
72
- write_list() {
73
- local tmp
74
- tmp="$(mktemp)"
75
- {
76
- echo "$HEADER"
77
- [ "$#" -eq 0 ] || printf '%s\n' "$@" | sort -k1,1 -u
78
- } >"$tmp"
79
- mv "$tmp" "$LIST"
80
- }
81
-
82
- update_index() {
83
- local last
84
- last="$(cat "$UPDATED" 2>/dev/null || true)"
85
- if [ -n "$last" ] && [ $(( $(date +%s) - last )) -lt 3600 ]; then
86
- return 0
87
- fi
88
- as_root "$APT" update || return 1
89
- date +%s >"$UPDATED"
90
- }
91
-
92
- list_packages() {
93
- local packages package
94
- packages="$(list_names)"
95
- if [ -z "$packages" ]; then
96
- echo "no package (devzone packages add <name>)"
97
- return 0
98
- fi
99
- while IFS= read -r package; do
100
- [ -n "$package" ] || continue
101
- if is_installed "$package"; then
102
- echo " ✔ $package"
103
- else
104
- echo " ○ $package"
105
- fi
106
- done < <(printf '%s\n' "$packages")
107
- }
108
-
109
- add_packages() {
110
- local -a a=()
111
- local -a entries=()
112
- local arg name line already=""
113
- for arg in "$@"; do
114
- case "$arg" in
115
- -*) refuse "unknown argument: $arg (devzone packages add <name>…)" ;;
116
- *) a+=("$arg") ;;
117
- esac
118
- done
119
- [ "${#a[@]}" -gt 0 ] || refuse "add expects at least one name: devzone packages add <name>…"
120
- update_index || echo "apt index not updated" >&2
121
- for name in "${a[@]}"; do
122
- if ! "$APTCACHE" show "$name" >/dev/null 2>&1; then
123
- refuse "unknown package: $name (list unchanged)"
124
- fi
125
- done
126
- # What is already installed before the installation comes from the image: marked
127
- for name in "${a[@]}"; do
128
- if is_installed "$name"; then
129
- already="$already $name"
130
- fi
131
- done
132
- if as_root DEBIAN_FRONTEND=noninteractive "$APT" install -y --no-install-recommends "${a[@]}"; then
133
- while IFS= read -r line; do
134
- entries+=("$line")
135
- done < <(list_lines)
136
- for name in "${a[@]}"; do
137
- if name_listed "$name"; then
138
- continue
139
- fi
140
- case " $already " in
141
- *" $name "*)
142
- entries+=("$name $PRESENT_MARK")
143
- echo "$name : already present before devzone packages (marked ; removing will leave it installed)"
144
- ;;
145
- *) entries+=("$name") ;;
146
- esac
147
- done
148
- write_list "${entries[@]}"
149
- else
150
- refuse "installation failed: ${a[*]} (list unchanged)"
151
- fi
152
- }
153
-
154
- remove_packages() {
155
- local -a a=()
156
- local -a removals=()
157
- local -a remaining=()
158
- local arg name line name_line
159
- for arg in "$@"; do
160
- case "$arg" in
161
- -*) refuse "unknown argument: $arg (devzone packages remove <name>…)" ;;
162
- *) a+=("$arg") ;;
163
- esac
164
- done
165
- [ "${#a[@]}" -gt 0 ] || refuse "remove expects at least one name: devzone packages remove <name>…"
166
- for name in "${a[@]}"; do
167
- name_listed "$name" ||
168
- refuse "package not listed: $name (provided by the image?) : devzone packages remove does not add image packages"
169
- if ! mark_present "$name"; then
170
- removals+=("$name")
171
- fi
172
- done
173
- if [ "${#removals[@]}" -gt 0 ] && ! as_root "$APT" remove -y "${removals[@]}"; then
174
- refuse "removal failed: ${removals[*]} (list unchanged)"
175
- fi
176
- for name in "${a[@]}"; do
177
- if mark_present "$name"; then
178
- echo "$name : removed from the list, left installed (present before devzone packages)"
179
- fi
180
- done
181
- while IFS= read -r line; do
182
- name_line="${line%% *}"
183
- case " ${a[*]} " in
184
- *" $name_line "*) ;;
185
- *) remaining+=("$line") ;;
186
- esac
187
- done < <(list_lines)
188
- write_list "${remaining[@]+"${remaining[@]}"}"
189
- }
190
-
191
- apply_packages() {
192
- local package
193
- local -a missing=()
194
- while IFS= read -r package; do
195
- [ -n "$package" ] || continue
196
- if ! is_installed "$package"; then
197
- missing+=("$package")
198
- fi
199
- done < <(printf '%s\n' "$(list_names)")
200
- if [ "${#missing[@]}" -eq 0 ]; then
201
- rm -f "$MARK"
202
- return 0
203
- fi
204
- update_index || echo "apt index not updated" >&2
205
- for package in "${missing[@]}"; do
206
- as_root DEBIAN_FRONTEND=noninteractive "$APT" install -y --no-install-recommends "$package" || true
207
- done
208
- local -a still_missing=()
209
- for package in "${missing[@]}"; do
210
- if ! is_installed "$package"; then
211
- still_missing+=("$package")
212
- fi
213
- done
214
- if [ "${#still_missing[@]}" -gt 0 ]; then
215
- printf '%s\n' "${still_missing[@]}" >"$MARK"
216
- return 1
217
- fi
218
- rm -f "$MARK"
219
- }
220
-
221
- case "${1:-}" in
222
- '' | list) list_packages ;;
223
- add) add_packages "${@:2}" ;;
224
- remove) remove_packages "${@:2}" ;;
225
- apply) apply_packages ;;
226
- -h | --help) awk 'NR==1{next} /^#$/{exit} /^#/{sub(/^# ?/,""); print; next} {exit}' "${BASH_SOURCE[0]}" ;;
227
- *) refuse "unknown command: ${1:-(none)} (devzone packages --help)" ;;
228
- esac
@@ -1,148 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Grouped credentials of the accounts created by devzone (#332).
3
- # password.sh regenerate reads the module files, writes $ROOT/.password
4
- # password.sh path prints the path of $ROOT/.password
5
- # The module files stay the source: .password is a regenerated view.
6
- # Plain-text secrets: never printed, never committed (.gitignore), mode 600.
7
- set -euo pipefail
8
-
9
- PASSWORD_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
- PASSWORD_ROOT="${DEVZONE_ROOT:-$(dirname "$PASSWORD_HERE")}"
11
- PASSWORD_TARGET="$PASSWORD_ROOT/.password"
12
-
13
- # Regenerates $ROOT/.password from workspace/.gitlab, workspace/.postgres,
14
- # workspace/.argocd, workspace/.mysql and the other workspace/.<app>/ folders.
15
- # Silent on success; without any account, the file is removed.
16
- password_regenerate() (
17
- umask 077
18
- local target="$PASSWORD_TARGET" root="$PASSWORD_ROOT"
19
- local gl="$root/workspace/.gitlab" pg="$root/workspace/.postgres"
20
- local ar="$root/workspace/.argocd"
21
- local my="$root/workspace/.mysql"
22
- local tab entries tmp file name service address user secret
23
- tab="$(printf '\t')"
24
- entries="$(mktemp "$root/.password.entries.XXXXXX")" || return 1
25
- tmp=""
26
-
27
- if [ -s "$gl/root-password" ]; then
28
- secret="$(cat "$gl/root-password")"
29
- if [ -n "$secret" ]; then
30
- printf 'gitlab\t%s\troot\t%s\n' "http://gitlab.localhost:8929" "$secret" >>"$entries"
31
- fi
32
- fi
33
- if [ -s "$gl/dev-password" ]; then
34
- secret="$(cat "$gl/dev-password")"
35
- if [ -n "$secret" ]; then
36
- printf 'gitlab\t%s\tdev\t%s\n' "http://gitlab.localhost:8929" "$secret" >>"$entries"
37
- fi
38
- fi
39
- if [ -s "$pg/admin-password" ]; then
40
- secret="$(cat "$pg/admin-password")"
41
- if [ -n "$secret" ]; then
42
- printf 'postgres\t%s\tpostgres\t%s\n' "127.0.0.1:5432" "$secret" >>"$entries"
43
- fi
44
- fi
45
- # Catalogue MySQL root (direct helm or Argo CD, #538): mirror of the workstation
46
- if [ -s "$my/admin-password" ]; then
47
- secret="$(cat "$my/admin-password")"
48
- if [ -n "$secret" ]; then
49
- printf 'mysql\t%s\troot\t%s\n' "127.0.0.1:3306" "$secret" >>"$entries"
50
- fi
51
- fi
52
- if [ -s "$ar/admin.env" ]; then
53
- user="$(sed -n 's/^ARGOCD_USER=//p' "$ar/admin.env" 2>/dev/null | tail -1 || true)"
54
- secret="$(sed -n 's/^ARGOCD_PASSWORD=//p' "$ar/admin.env" 2>/dev/null | tail -1 || true)"
55
- if [ -n "$user" ] && [ -n "$secret" ]; then
56
- printf 'argocd\t%s\t%s\t%s\n' "https://127.0.0.1:8443" "$user" "$secret" >>"$entries"
57
- fi
58
- fi
59
- for file in "$pg"/*.env; do
60
- [ -f "$file" ] || continue
61
- name="${file##*/}"
62
- name="${name%.env}"
63
- service="postgres:$name"
64
- user="$(sed -n 's/^DB_USER=//p' "$file" 2>/dev/null | tail -1 || true)"
65
- secret="$(sed -n 's/^DB_PASSWORD=//p' "$file" 2>/dev/null | tail -1 || true)"
66
- address="$(sed -n 's/^DB_NAME=//p' "$file" 2>/dev/null | tail -1 || true)"
67
- if [ -z "$user" ] || [ -z "$secret" ]; then
68
- continue
69
- fi
70
- address="127.0.0.1:5432/${address:-$name}"
71
- printf '%s\t%s\t%s\t%s\n' "$service" "$address" "$user" "$secret" >>"$entries"
72
- done
73
- # Each other catalogue application: workspace/.<app>/*.env, keys <APP>_HOST,
74
- # <APP>_PORT, <APP>_USER, <APP>_PASSWORD (or MYSQL_* for mysql)
75
- for dir in "$root"/workspace/.*/; do
76
- [ -d "$dir" ] || continue
77
- app="${dir%/}"
78
- app="${app##*/}"
79
- case "$app" in . | .. | .gitlab | .postgres | .argocd) continue ;; esac
80
- app="${app#.}"
81
- app_upper="$(printf '%s' "$app" | tr '[:lower:]' '[:upper:]')"
82
- for file in "$dir"*.env; do
83
- [ -f "$file" ] || continue
84
- base="${file##*/}"
85
- base="${base%.env}"
86
- user="$(sed -n "s/^${app_upper}_USER=//p" "$file" 2>/dev/null | tail -1 || true)"
87
- [ -z "$user" ] && user="$(sed -n 's/^DB_USER=//p' "$file" 2>/dev/null | tail -1 || true)"
88
- [ -z "$user" ] && user="$(sed -n 's/^MYSQL_USER=//p' "$file" 2>/dev/null | tail -1 || true)"
89
- secret="$(sed -n "s/^${app_upper}_PASSWORD=//p" "$file" 2>/dev/null | tail -1 || true)"
90
- [ -z "$secret" ] && secret="$(sed -n 's/^DB_PASSWORD=//p' "$file" 2>/dev/null | tail -1 || true)"
91
- [ -z "$secret" ] && secret="$(sed -n 's/^MYSQL_PASSWORD=//p' "$file" 2>/dev/null | tail -1 || true)"
92
- [ -z "$user" ] || [ -z "$secret" ] && continue
93
- host="$(sed -n "s/^${app_upper}_HOST=//p" "$file" 2>/dev/null | tail -1 || true)"
94
- [ -z "$host" ] && host="$(sed -n 's/^DB_HOST=//p' "$file" 2>/dev/null | tail -1 || true)"
95
- [ -z "$host" ] && host="$(sed -n 's/^MYSQL_HOST=//p' "$file" 2>/dev/null | tail -1 || true)"
96
- [ -z "$host" ] && host=127.0.0.1
97
- port="$(sed -n "s/^${app_upper}_PORT=//p" "$file" 2>/dev/null | tail -1 || true)"
98
- [ -z "$port" ] && port="$(sed -n 's/^DB_PORT=//p' "$file" 2>/dev/null | tail -1 || true)"
99
- [ -z "$port" ] && port="$(sed -n 's/^MYSQL_PORT=//p' "$file" 2>/dev/null | tail -1 || true)"
100
- [ -z "$port" ] && port=3306
101
- printf '%s\t%s\t%s\t%s\n' "$app:$base" "$host:$port" "$user" "$secret" >>"$entries"
102
- done
103
- done
104
-
105
- if [ ! -s "$entries" ]; then
106
- rm -f "$entries" "$target"
107
- return 0
108
- fi
109
-
110
- tmp="$(mktemp "$root/.password.XXXXXX")" || {
111
- rm -f "$entries"
112
- return 1
113
- }
114
- {
115
- printf '%s\n' \
116
- '# devzone : identifiers of the accounts created by devzone. Plain-text secrets:' \
117
- '# never commit, copy or paste them into a ticket. Regenerated by devzone.' \
118
- "# service${tab}address${tab}user${tab}password"
119
- LC_ALL=C sort -t "$tab" -k1,1 -k3,3 "$entries"
120
- } >"$tmp" || {
121
- rm -f "$entries" "$tmp"
122
- return 1
123
- }
124
- chmod 600 "$tmp" || {
125
- rm -f "$entries" "$tmp"
126
- return 1
127
- }
128
- mv "$tmp" "$target" || {
129
- rm -f "$entries" "$tmp"
130
- return 1
131
- }
132
- chmod 600 "$target" || {
133
- rm -f "$entries"
134
- return 1
135
- }
136
- rm -f "$entries"
137
- )
138
-
139
- if [ "${BASH_SOURCE[0]}" = "$0" ]; then
140
- case "${1:-}" in
141
- regenerate) password_regenerate ;;
142
- path) printf '%s\n' "$PASSWORD_TARGET" ;;
143
- *)
144
- echo "devzone : password.sh : regenerate | path" >&2
145
- exit 1
146
- ;;
147
- esac
148
- fi
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env bash
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.
5
- # Sourced by ports.sh, which holds the functions used here.
6
-
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)")"
11
- if [ -z "$ports" ]; then
12
- printf '[]\n'
13
- return 0
14
- fi
15
- # shellcheck disable=SC2046 # list of ports separated by commas
16
- for port in $(printf '%s' "$ports" | tr ',' ' '); do
17
- if relay_active "$port"; then
18
- active=true
19
- else
20
- active=false
21
- fi
22
- if app_responds "$port"; then
23
- app="$JSON_APP_RESPONDS"
24
- else
25
- app="$JSON_APP_NONE"
26
- fi
27
- json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" \
28
- '. + [{port:$port,active:$active,application:$app,auto:false}]' <<<"$json")"
29
- done
30
- printf '%s\n' "$json"
31
- }