devzone 0.58.0 → 1.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.
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/argocd/argocd.sh +0 -12
- package/.devcontainer/catalogue/mysql/mysql.sh +0 -12
- package/.devcontainer/catalogue.sh +1 -13
- package/.devcontainer/command-aliases.sh +78 -114
- package/.devcontainer/devzone +21 -36
- package/.devcontainer/gitlab/gitlab.sh +0 -12
- package/.devcontainer/gitlab/test-gitlab.sh +1 -1
- package/.devcontainer/help.sh +3 -3
- package/.devcontainer/paquets.sh +0 -12
- package/.devcontainer/ports.sh +0 -12
- package/.devcontainer/postgres/postgres.sh +0 -12
- package/.devcontainer/skills/devzone/SKILL.md +2 -2
- package/README.md +12 -2
- package/manage/devzone +61 -569
- package/manage/scripts/argocd-services.sh +2 -2
- package/manage/scripts/create-cluster.sh +107 -0
- package/manage/scripts/create-mode.sh +10 -0
- package/manage/scripts/devzone-create.sh +138 -0
- package/manage/scripts/devzone-manifest.sh +171 -0
- package/manage/scripts/devzone-update.sh +222 -0
- package/manage/scripts/migrer.sh +2 -6
- package/manage/scripts/workspace-aliases.sh +4 -31
- package/manage/workspace.sh +7 -12
- package/package.json +1 -1
|
@@ -22,13 +22,13 @@ MYSQL_NS="devzone-mysql"
|
|
|
22
22
|
# shellcheck disable=SC2034 # read by services.sh
|
|
23
23
|
SERVICES_LIST="postgres mysql"
|
|
24
24
|
|
|
25
|
-
# The only option of a removal: --yes
|
|
25
|
+
# The only option of a removal: --yes; prints 1 or 0
|
|
26
26
|
yes_flag() {
|
|
27
27
|
local usage="$1" arg found=0
|
|
28
28
|
shift
|
|
29
29
|
for arg in "$@"; do
|
|
30
30
|
case "$arg" in
|
|
31
|
-
--yes
|
|
31
|
+
--yes) found=1 ;;
|
|
32
32
|
*) echo "✖ unknown option: $arg (devzone workspace $usage)" >&2; return 1 ;;
|
|
33
33
|
esac
|
|
34
34
|
done
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Way out of "no cluster" at creation (#653), sourced by create-mode.sh.
|
|
3
|
+
# In a terminal, a menu: a remote cluster (a context of the kubeconfig, its name
|
|
4
|
+
# typed back to confirm, #326) or a local minikube cluster (profile devzone).
|
|
5
|
+
# Without a terminal nothing is asked: the caller prints the failure (no silent
|
|
6
|
+
# fallback). devzone never runs a cloud command and never installs minikube: it
|
|
7
|
+
# only displays the official command. DEVZONE_TERMINAL=1 forces the terminal
|
|
8
|
+
# mode, the answers then come from stdin (tests). Sourced only. Bash 3.2.
|
|
9
|
+
|
|
10
|
+
# True in a terminal (or forced for the tests).
|
|
11
|
+
create_cluster_terminal() {
|
|
12
|
+
[ -n "${DEVZONE_TERMINAL:-}" ] || [ -t 0 ]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
# True when the context is a local cluster: never offered as a remote one.
|
|
16
|
+
create_cluster_is_local() {
|
|
17
|
+
local ctx="$1" server
|
|
18
|
+
case "$ctx" in
|
|
19
|
+
docker-desktop | desktop-* | minikube | devzone | rancher-desktop | orbstack | colima | kind-* | k3d-*) return 0 ;;
|
|
20
|
+
esac
|
|
21
|
+
server="$(kubectl config view --minify --context "$ctx" -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
|
|
22
|
+
case "$server" in
|
|
23
|
+
*//127.0.0.1* | *//localhost* | *//\[::1\]*) return 0 ;;
|
|
24
|
+
esac
|
|
25
|
+
return 1
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Remote contexts of the kubeconfig, one per line.
|
|
29
|
+
create_cluster_remote_contexts() {
|
|
30
|
+
local ctx
|
|
31
|
+
kubectl config get-contexts -o name 2>/dev/null | while IFS= read -r ctx; do
|
|
32
|
+
[ -n "$ctx" ] || continue
|
|
33
|
+
create_cluster_is_local "$ctx" || printf '%s\n' "$ctx"
|
|
34
|
+
done
|
|
35
|
+
return 0
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Remote cluster: pick a context, type its name back, make it the current one.
|
|
39
|
+
create_cluster_remote() {
|
|
40
|
+
local list answer ctx i=0
|
|
41
|
+
list="$(create_cluster_remote_contexts)"
|
|
42
|
+
if [ -z "$list" ]; then
|
|
43
|
+
echo "✖ no remote context in your kubeconfig: add one with the command of your provider (aws, gcloud, az), then run the same command again" >&2
|
|
44
|
+
return 1
|
|
45
|
+
fi
|
|
46
|
+
echo "Remote contexts of your kubeconfig:"
|
|
47
|
+
while IFS= read -r ctx; do
|
|
48
|
+
i=$((i + 1))
|
|
49
|
+
printf ' %s) %s (remote)\n' "$i" "$ctx"
|
|
50
|
+
done <<<"$list"
|
|
51
|
+
printf 'Number of the cluster (empty to cancel): '
|
|
52
|
+
read -r answer || answer=""
|
|
53
|
+
case "$answer" in
|
|
54
|
+
'' | *[!0-9]*) echo "✖ cancelled" >&2; return 1 ;;
|
|
55
|
+
esac
|
|
56
|
+
ctx="$(printf '%s\n' "$list" | sed -n "${answer}p")"
|
|
57
|
+
[ -n "$ctx" ] || { echo "✖ no such cluster: $answer" >&2; return 1; }
|
|
58
|
+
echo "remote cluster: $ctx. devzone will install a pod, a volume and the namespace devzone-workspace in it: it needs enough rights and may cost."
|
|
59
|
+
printf 'Type its name to confirm: '
|
|
60
|
+
read -r answer || answer=""
|
|
61
|
+
[ "$answer" = "$ctx" ] || { echo "✖ name not typed back: nothing done" >&2; return 1; }
|
|
62
|
+
kubectl config use-context "$ctx" >/dev/null 2>&1 || { echo "✖ cannot select the context $ctx" >&2; return 1; }
|
|
63
|
+
echo "✔ current kubectl context: $ctx"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# minikube: displays the official install command when it is missing (never
|
|
67
|
+
# runs it); otherwise creates the profile devzone after a confirmation.
|
|
68
|
+
create_cluster_minikube() {
|
|
69
|
+
local answer
|
|
70
|
+
if ! command -v minikube >/dev/null 2>&1; then
|
|
71
|
+
echo "minikube is not installed. Official command (devzone does not run it):"
|
|
72
|
+
case "$(uname -s)" in
|
|
73
|
+
Darwin) echo " brew install minikube" ;;
|
|
74
|
+
Linux) echo " curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && sudo install minikube-linux-amd64 /usr/local/bin/minikube" ;;
|
|
75
|
+
*) echo " winget install Kubernetes.minikube" ;;
|
|
76
|
+
esac
|
|
77
|
+
echo "Then run the same command again."
|
|
78
|
+
return 1
|
|
79
|
+
fi
|
|
80
|
+
echo "minikube: devzone will run: minikube start -p devzone (profile devzone, driver chosen by minikube)."
|
|
81
|
+
printf 'Create it now? [y/N] '
|
|
82
|
+
read -r answer || answer=""
|
|
83
|
+
case "$answer" in
|
|
84
|
+
y | Y | yes | o | O | oui) ;;
|
|
85
|
+
*) echo "✖ cancelled" >&2; return 1 ;;
|
|
86
|
+
esac
|
|
87
|
+
minikube start -p devzone || { echo "✖ minikube start failed: nothing else done" >&2; return 1; }
|
|
88
|
+
kubectl config use-context devzone >/dev/null 2>&1 || true
|
|
89
|
+
echo "✔ minikube cluster devzone started"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Offers the choice in a terminal. Returns 0 when a cluster was selected or
|
|
93
|
+
# created (the caller checks that it answers), 1 otherwise or without a terminal.
|
|
94
|
+
create_cluster_offer() {
|
|
95
|
+
local choice
|
|
96
|
+
create_cluster_terminal || return 1
|
|
97
|
+
echo "No Kubernetes cluster answers. Pick one:"
|
|
98
|
+
echo " 1) a remote cluster (AWS, GCP, Azure, other: a context of your kubeconfig)"
|
|
99
|
+
echo " 2) a local minikube cluster (profile devzone)"
|
|
100
|
+
printf 'Your choice (empty to cancel): '
|
|
101
|
+
read -r choice || choice=""
|
|
102
|
+
case "$choice" in
|
|
103
|
+
1) create_cluster_remote ;;
|
|
104
|
+
2) create_cluster_minikube ;;
|
|
105
|
+
*) echo "✖ cancelled" >&2; return 1 ;;
|
|
106
|
+
esac
|
|
107
|
+
}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
# shellcheck disable=SC2034 # CREATE_MODE is read by manage/devzone (creer)
|
|
10
10
|
# shellcheck source=manage/scripts/kube-ready.sh
|
|
11
11
|
. "$(dirname "${BASH_SOURCE[0]}")/kube-ready.sh"
|
|
12
|
+
# shellcheck source=manage/scripts/create-cluster.sh
|
|
13
|
+
. "$(dirname "${BASH_SOURCE[0]}")/create-cluster.sh"
|
|
12
14
|
|
|
13
15
|
# Context shown to the user: devzone if declared, otherwise the current one.
|
|
14
16
|
kube_context() {
|
|
@@ -53,6 +55,14 @@ create_mode_choose() {
|
|
|
53
55
|
create_mode_existing
|
|
54
56
|
return 0
|
|
55
57
|
fi
|
|
58
|
+
# No option, in a terminal: a menu (remote cluster, minikube) instead of a
|
|
59
|
+
# failure (#653); the choice is accepted only if the cluster then answers.
|
|
60
|
+
if [ -z "$option" ] && create_cluster_offer && reason="$(kube_ready_reason)"; then
|
|
61
|
+
CREATE_MODE=kubernetes
|
|
62
|
+
echo "✔ Kubernetes ready ($(kube_context)): workspace in the cluster"
|
|
63
|
+
create_mode_existing
|
|
64
|
+
return 0
|
|
65
|
+
fi
|
|
56
66
|
create_mode_no_cluster "$reason"
|
|
57
67
|
return 1
|
|
58
68
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Creation of a devzone (devzone <folder>): asks for the GitOps repository,
|
|
3
|
+
# copies the package, writes .argocd.conf and the manifest, then starts the
|
|
4
|
+
# workspace (Kubernetes) or the container (Docker). Sourced by manage/devzone,
|
|
5
|
+
# which defines PAQUET, PACKAGE_ITEMS and version(); devzone-manifest.sh must
|
|
6
|
+
# be sourced first.
|
|
7
|
+
# shellcheck disable=SC2154 # PAQUET, PACKAGE_ITEMS: set by manage/devzone
|
|
8
|
+
|
|
9
|
+
# GitOps repository of Argo CD for the creation (#539): github, an existing
|
|
10
|
+
# URL, or none. Asked in a terminal (default: github when gh is connected),
|
|
11
|
+
# or none with a notice without one (the --gitops option names the choice).
|
|
12
|
+
ask_gitops() {
|
|
13
|
+
local answer default=""
|
|
14
|
+
if gh auth status >/dev/null 2>&1; then
|
|
15
|
+
default="github"
|
|
16
|
+
fi
|
|
17
|
+
printf 'GitOps repository for Argo CD? [G]itHub (created under your gh account at first start) / a URL / [n]one : ' >&2
|
|
18
|
+
read -r answer || answer=""
|
|
19
|
+
answer="${answer:-$default}"
|
|
20
|
+
case "$answer" in
|
|
21
|
+
G | g | GitHub | github | Oui | oui | OUI) echo "github" ;;
|
|
22
|
+
n | N | none | None | Non | non | NON | aucun | Aucun) echo "none" ;;
|
|
23
|
+
*) echo "$answer" ;;
|
|
24
|
+
esac
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
create_workstation() {
|
|
28
|
+
local target="$1" gitops="" expect="" option="" arg value login name instance
|
|
29
|
+
shift
|
|
30
|
+
for arg in "$@"; do
|
|
31
|
+
if [ "$expect" = gitops ]; then gitops="$arg"; expect=""; continue; fi
|
|
32
|
+
case "$arg" in
|
|
33
|
+
--gitops) expect=gitops ;;
|
|
34
|
+
--gitops=*) gitops="${arg#--gitops=}" ;;
|
|
35
|
+
--kubernetes | --docker)
|
|
36
|
+
if [ -n "$option" ] && [ "$option" != "${arg#--}" ]; then
|
|
37
|
+
echo "✖ --kubernetes and --docker: choose one" >&2
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
option="${arg#--}"
|
|
41
|
+
;;
|
|
42
|
+
*) echo "✖ option inconnue : $arg (devzone <dossier> [--gitops github|none|<url>] [--kubernetes|--docker])" >&2; exit 1 ;;
|
|
43
|
+
esac
|
|
44
|
+
done
|
|
45
|
+
if [ -n "$expect" ]; then
|
|
46
|
+
echo "✖ --gitops attend une valeur (github, none or a URL)" >&2
|
|
47
|
+
exit 1
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
if [ -e "$target" ] && [ -n "$(ls -A "$target" 2>/dev/null)" ]; then
|
|
51
|
+
echo "✖ $target existe et n'est pas vide : rien n'est écrasé. Choisis un autre dossier." >&2
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# Mode before any copy: --kubernetes without a cluster creates nothing (#497)
|
|
56
|
+
# shellcheck source=SCRIPTDIR/create-mode.sh
|
|
57
|
+
. "$PAQUET/manage/scripts/create-mode.sh"
|
|
58
|
+
create_mode_choose "$option" || exit 1
|
|
59
|
+
|
|
60
|
+
if [ -z "$gitops" ]; then
|
|
61
|
+
if [ -t 0 ]; then
|
|
62
|
+
gitops="$(ask_gitops)"
|
|
63
|
+
else
|
|
64
|
+
echo "⚠ no GitOps repository for Argo CD: pass --gitops <github|none|https://github.com/<login>/<name>.git> to create a devzone without a terminal; using none" >&2
|
|
65
|
+
gitops="none"
|
|
66
|
+
fi
|
|
67
|
+
fi
|
|
68
|
+
mkdir -p "$target/workspace" "$target/manage"
|
|
69
|
+
cp -R "${PACKAGE_ITEMS[@]/#/$PAQUET/}" "$target/"
|
|
70
|
+
cp -R "$PAQUET/manage/scripts" "$target/manage/"
|
|
71
|
+
touch "$target/workspace/.gitkeep"
|
|
72
|
+
# npm never includes .gitignore: written here
|
|
73
|
+
: >"$target/.gitignore"
|
|
74
|
+
complete_gitignore "$target"
|
|
75
|
+
chmod +x "$target/manage/scripts/desinstaller.sh" "$target/manage/scripts/lancer.sh"
|
|
76
|
+
create_mode_write "$target" "$CREATE_MODE"
|
|
77
|
+
# The GitOps repository of the new devzone (#539): github, an existing URL,
|
|
78
|
+
# or none, written in the .argocd.conf of the new devzone (conf.sh writes
|
|
79
|
+
# the header of the file when absent)
|
|
80
|
+
. "$PAQUET/.devcontainer/argocd/conf.sh"
|
|
81
|
+
# shellcheck disable=SC2034 # read by conf.sh
|
|
82
|
+
ARGOCD_CONF="$target/.argocd.conf"
|
|
83
|
+
if [ "$gitops" = github ]; then
|
|
84
|
+
if ! gh auth status >/dev/null 2>&1; then
|
|
85
|
+
echo "⚠ GitHub not connected (gh auth login): no GitOps repository, the Applications are applied directly; pass --gitops none" >&2
|
|
86
|
+
value="none"
|
|
87
|
+
else
|
|
88
|
+
login="$(gh api user --jq .login 2>/dev/null)" || login=""
|
|
89
|
+
if [ -z "$login" ]; then
|
|
90
|
+
echo "⚠ GitHub login unreadable (gh api user): no GitOps repository, the Applications are applied directly; pass --gitops none" >&2
|
|
91
|
+
value="none"
|
|
92
|
+
else
|
|
93
|
+
name="${DEVZONE_GITOPS_REPO_NAME:-devzone-argocd}"
|
|
94
|
+
instance="${DEVZONE_VOLUMES:-devzone}"
|
|
95
|
+
if [ "$instance" != "devzone" ]; then
|
|
96
|
+
name="$name-$instance"
|
|
97
|
+
fi
|
|
98
|
+
value="https://github.com/$login/$name.git"
|
|
99
|
+
fi
|
|
100
|
+
fi
|
|
101
|
+
elif [ "$gitops" = none ]; then
|
|
102
|
+
value="none"
|
|
103
|
+
else
|
|
104
|
+
value="$gitops"
|
|
105
|
+
fi
|
|
106
|
+
conf_set argocd "repo=$value"
|
|
107
|
+
case "$value" in
|
|
108
|
+
none) echo "✔ no GitOps repository: the Applications are applied directly (devzone workspace argocd init to change)" ;;
|
|
109
|
+
*) echo "✔ GitOps repository: $value ($target/.argocd.conf)" ;;
|
|
110
|
+
esac
|
|
111
|
+
target="$(cd "$target" && pwd)"
|
|
112
|
+
write_manifest "$target"
|
|
113
|
+
echo "✔ devzone $(version) créé dans $target"
|
|
114
|
+
# Kubernetes: the workspace goes to the cluster, no Docker check (Docker
|
|
115
|
+
# Desktop hosts the cluster, but devzone does not need it directly)
|
|
116
|
+
if [ "$CREATE_MODE" = kubernetes ]; then
|
|
117
|
+
create_mode_start "$target" "$PAQUET/manage/workspace.sh"
|
|
118
|
+
return
|
|
119
|
+
fi
|
|
120
|
+
if [ -n "${DEVZONE_SANS_DEMARRER:-}" ]; then
|
|
121
|
+
echo "Pour le lancer : cd $target && make up"
|
|
122
|
+
return 0
|
|
123
|
+
fi
|
|
124
|
+
# Docker first: the folder stays ready, to start once Docker is running
|
|
125
|
+
# shellcheck source=SCRIPTDIR/docker.sh
|
|
126
|
+
. "$PAQUET/manage/scripts/docker.sh"
|
|
127
|
+
if ! docker_ready "cd $target && make shell"; then
|
|
128
|
+
echo " Le dossier est prêt : rien à refaire, sauf ce lancement." >&2
|
|
129
|
+
exit 1
|
|
130
|
+
fi
|
|
131
|
+
echo "▶ Lancement (quelques minutes la première fois)…"
|
|
132
|
+
if command -v make >/dev/null 2>&1; then
|
|
133
|
+
make -C "$target" up
|
|
134
|
+
else
|
|
135
|
+
bash "$target/manage/scripts/lancer.sh" up "$target"
|
|
136
|
+
fi
|
|
137
|
+
echo "Ensuite : cd $target && make shell (ou ouvre le dossier dans VS Code : Reopen in Container)."
|
|
138
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Manifest of a devzone (.devzone.version) and the paths read back from it:
|
|
3
|
+
# checksum of each copied file, safe relative paths, the .gitignore lines of a
|
|
4
|
+
# devzone. Sourced by manage/devzone (update and create), which defines PAQUET
|
|
5
|
+
# (package folder), PACKAGE_ITEMS, GITIGNORE_LINES and version().
|
|
6
|
+
# shellcheck disable=SC2154 # PAQUET, PACKAGE_ITEMS, GITIGNORE_LINES: set by manage/devzone
|
|
7
|
+
|
|
8
|
+
# SHA-256 checksum of a file, computed by node (portable: macOS, Linux, Windows
|
|
9
|
+
# Git Bash); the path is passed as an argument, as for version()
|
|
10
|
+
checksum() {
|
|
11
|
+
node -e 'const fs = require("fs"), crypto = require("crypto"); const h = crypto.createHash("sha256"); h.update(fs.readFileSync(process.argv[1])); process.stdout.write(h.digest("hex"))' "$1"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
# Files of the package copied into a devzone, absolute paths
|
|
15
|
+
package_files() {
|
|
16
|
+
local base
|
|
17
|
+
for base in "${PACKAGE_ITEMS[@]}"; do
|
|
18
|
+
if [ -d "$PAQUET/$base" ]; then
|
|
19
|
+
find "$PAQUET/$base" -type f -print
|
|
20
|
+
elif [ -f "$PAQUET/$base" ]; then
|
|
21
|
+
printf '%s\n' "$PAQUET/$base"
|
|
22
|
+
fi
|
|
23
|
+
done
|
|
24
|
+
if [ -d "$PAQUET/manage/scripts" ]; then
|
|
25
|
+
find "$PAQUET/manage/scripts" -type f -print
|
|
26
|
+
fi
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# The same files, relative to the package, sorted
|
|
30
|
+
relative_package_files() {
|
|
31
|
+
local f
|
|
32
|
+
package_files | while IFS= read -r f; do
|
|
33
|
+
printf '%s\n' "${f#"$PAQUET"/}"
|
|
34
|
+
done | LC_ALL=C sort
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# .devzone.version: version of the folder, then one checksum per copied file
|
|
38
|
+
write_manifest() {
|
|
39
|
+
local folder="$1" rel
|
|
40
|
+
{
|
|
41
|
+
printf 'version %s\n' "$(version)"
|
|
42
|
+
relative_package_files | while IFS= read -r rel; do
|
|
43
|
+
printf '%s %s\n' "$(checksum "$folder/$rel")" "$rel"
|
|
44
|
+
done
|
|
45
|
+
} >"$folder/.devzone.version"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Version written in the manifest of a folder, 'inconnue' when there is none
|
|
49
|
+
folder_version() {
|
|
50
|
+
local folder="${1:-.}" v
|
|
51
|
+
if [ -f "$folder/.devzone.version" ]; then
|
|
52
|
+
v="$(sed -n '1s/^version //p' "$folder/.devzone.version" 2>/dev/null | head -1 || true)"
|
|
53
|
+
if [ -n "$v" ]; then
|
|
54
|
+
printf '%s\n' "$v"
|
|
55
|
+
return 0
|
|
56
|
+
fi
|
|
57
|
+
fi
|
|
58
|
+
printf 'inconnue\n'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Checksum recorded in the manifest of a folder for one path; fails if absent
|
|
62
|
+
manifest_checksum() {
|
|
63
|
+
local folder="$1" target="$2" line h p
|
|
64
|
+
[ -f "$folder/.devzone.version" ] || return 1
|
|
65
|
+
while IFS= read -r line; do
|
|
66
|
+
case "$line" in
|
|
67
|
+
version\ * | '') continue ;;
|
|
68
|
+
esac
|
|
69
|
+
h="${line%% *}"
|
|
70
|
+
p="${line#* }"
|
|
71
|
+
if [ "$p" = "$target" ]; then
|
|
72
|
+
printf '%s\n' "$h"
|
|
73
|
+
return 0
|
|
74
|
+
fi
|
|
75
|
+
done <"$folder/.devzone.version"
|
|
76
|
+
return 1
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Paths listed in the manifest of a folder
|
|
80
|
+
manifest_files() {
|
|
81
|
+
local folder="$1" line
|
|
82
|
+
[ -f "$folder/.devzone.version" ] || return 0
|
|
83
|
+
while IFS= read -r line; do
|
|
84
|
+
case "$line" in
|
|
85
|
+
version\ * | '') continue ;;
|
|
86
|
+
esac
|
|
87
|
+
printf '%s\n' "${line#* }"
|
|
88
|
+
done <"$folder/.devzone.version"
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# A path read from the manifest is accepted only if it is relative and simple
|
|
92
|
+
# (no '..', '.', '//', newline or tab), under a folder managed by the package
|
|
93
|
+
# or a file at its root. Otherwise it is refused.
|
|
94
|
+
path_allowed() {
|
|
95
|
+
local rel="$1"
|
|
96
|
+
case "$rel" in
|
|
97
|
+
'' | /* | *//* | *$'\n'* | *$'\t'*) return 1 ;;
|
|
98
|
+
esac
|
|
99
|
+
case "/$rel/" in
|
|
100
|
+
*/../* | */./*) return 1 ;;
|
|
101
|
+
esac
|
|
102
|
+
case "$rel" in
|
|
103
|
+
.devcontainer/* | manage/* | core/* | scripts/* | \
|
|
104
|
+
Makefile | README.md | LICENSE | .gitattributes) return 0 ;;
|
|
105
|
+
esac
|
|
106
|
+
return 1
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Defense in depth: the real parent folder must stay under the real devzone
|
|
110
|
+
# folder (pwd -P), so a symbolic link leading out of it is refused.
|
|
111
|
+
inside_folder() {
|
|
112
|
+
local folder="$1" rel="$2" root parent
|
|
113
|
+
root="$(cd "$folder" && pwd -P)" || return 1
|
|
114
|
+
parent="$(cd "$folder/$(dirname "$rel")" 2>/dev/null && pwd -P)" || return 1
|
|
115
|
+
case "$parent" in
|
|
116
|
+
"$root" | "$root"/*) return 0 ;;
|
|
117
|
+
esac
|
|
118
|
+
return 1
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
# Never touched by update, even when an old manifest lists them
|
|
122
|
+
is_protected() {
|
|
123
|
+
case "$1" in
|
|
124
|
+
workspace | workspace/* | .devzone.version | .devzone.modules | .devzone.modules-* | \
|
|
125
|
+
.devzone.paquets | .password | .app | .devzone.log | .git | .git/*) return 0 ;;
|
|
126
|
+
esac
|
|
127
|
+
return 1
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# True when the whole line $2 is in the file $1
|
|
131
|
+
in_list() {
|
|
132
|
+
grep -Fqx -- "$2" "$1"
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# Old devzone layout (before manage/): core/ is recognized only by its marker
|
|
136
|
+
# files, scripts/ only by its two own files. Otherwise it is a folder of the
|
|
137
|
+
# user: never touched.
|
|
138
|
+
old_tree() {
|
|
139
|
+
local folder="$1" tree="$2"
|
|
140
|
+
case "$tree" in
|
|
141
|
+
core)
|
|
142
|
+
[ -f "$folder/core/devzone" ] || [ -f "$folder/core/scripts/desinstaller.sh" ]
|
|
143
|
+
;;
|
|
144
|
+
scripts)
|
|
145
|
+
[ -f "$folder/scripts/desinstaller.sh" ] && [ -f "$folder/scripts/lancer.sh" ]
|
|
146
|
+
;;
|
|
147
|
+
*) return 1 ;;
|
|
148
|
+
esac
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# File known from the old package: the names of manage/scripts/ moved into
|
|
152
|
+
# core/scripts/ or scripts/, core/devzone, and all of core/test/ and core/docs/.
|
|
153
|
+
known_old_file() {
|
|
154
|
+
local rel="$1" name
|
|
155
|
+
case "$rel" in
|
|
156
|
+
core/devzone | core/test/* | core/docs/*) return 0 ;;
|
|
157
|
+
core/scripts/*) name="${rel#core/scripts/}" ;;
|
|
158
|
+
scripts/*) name="${rel#scripts/}" ;;
|
|
159
|
+
*) return 1 ;;
|
|
160
|
+
esac
|
|
161
|
+
[ -f "$PAQUET/manage/scripts/$name" ]
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# Adds the missing lines of GITIGNORE_LINES to the .gitignore of a folder
|
|
165
|
+
complete_gitignore() {
|
|
166
|
+
local folder="$1" line
|
|
167
|
+
touch "$folder/.gitignore"
|
|
168
|
+
for line in "${GITIGNORE_LINES[@]}"; do
|
|
169
|
+
grep -qxF -- "$line" "$folder/.gitignore" || printf '%s\n' "$line" >>"$folder/.gitignore"
|
|
170
|
+
done
|
|
171
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Update of a devzone (devzone update [--yes] [--sans-reconstruire]): replaces
|
|
3
|
+
# the files of the package, backs up the replaced or removed ones, removes the
|
|
4
|
+
# old layout, then offers the rebuild. Sourced by manage/devzone, after
|
|
5
|
+
# devzone-manifest.sh, which provides the manifest helpers.
|
|
6
|
+
# shellcheck disable=SC2154 # PAQUET: set by manage/devzone
|
|
7
|
+
|
|
8
|
+
# Six steps of the update design (#349)
|
|
9
|
+
update_workstation() {
|
|
10
|
+
local assume_yes="" no_rebuild="" arg folder package installed package_list old_list
|
|
11
|
+
local missing rel current expected answer backup base n old f
|
|
12
|
+
for arg in "$@"; do
|
|
13
|
+
case "$arg" in
|
|
14
|
+
--yes) assume_yes=1 ;;
|
|
15
|
+
--sans-reconstruire) no_rebuild=1 ;;
|
|
16
|
+
*)
|
|
17
|
+
echo "✖ option inconnue : $arg (devzone update [--yes] [--sans-reconstruire])" >&2
|
|
18
|
+
exit 1
|
|
19
|
+
;;
|
|
20
|
+
esac
|
|
21
|
+
done
|
|
22
|
+
if [ ! -d .devcontainer ]; then
|
|
23
|
+
echo "✖ À lancer dans un dossier devzone (.devcontainer introuvable ici)." >&2
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
folder="$(pwd)"
|
|
28
|
+
package="$(version)"
|
|
29
|
+
installed="$(folder_version "$folder")"
|
|
30
|
+
work="$(mktemp -d)"
|
|
31
|
+
trap 'rm -rf "$work"' EXIT
|
|
32
|
+
package_list="$work/package-files"
|
|
33
|
+
old_list="$work/old-files"
|
|
34
|
+
relative_package_files >"$package_list"
|
|
35
|
+
manifest_files "$folder" | LC_ALL=C sort >"$old_list"
|
|
36
|
+
|
|
37
|
+
# 1. Versions and package files present
|
|
38
|
+
missing=""
|
|
39
|
+
while IFS= read -r rel; do
|
|
40
|
+
[ -f "$folder/$rel" ] || missing=1
|
|
41
|
+
done <"$package_list"
|
|
42
|
+
if [ "$installed" = "$package" ] && [ -z "$missing" ]; then
|
|
43
|
+
echo "✔ devzone $installed : déjà à jour."
|
|
44
|
+
echo "Pour la dernière version publiée : npx devzone@latest update"
|
|
45
|
+
return 0
|
|
46
|
+
fi
|
|
47
|
+
echo "devzone : dossier $installed, paquet $package"
|
|
48
|
+
|
|
49
|
+
# 2. Files modified locally (checksum different from the manifest; without
|
|
50
|
+
# a manifest, different from the one of the package)
|
|
51
|
+
: >"$work/modified"
|
|
52
|
+
: >"$work/to_save"
|
|
53
|
+
: >"$work/to_remove"
|
|
54
|
+
: >"$work/old_trees"
|
|
55
|
+
while IFS= read -r rel; do
|
|
56
|
+
[ -f "$folder/$rel" ] || continue
|
|
57
|
+
printf '%s\n' "$rel" >>"$work/to_save"
|
|
58
|
+
current="$(checksum "$folder/$rel")"
|
|
59
|
+
if expected="$(manifest_checksum "$folder" "$rel")"; then
|
|
60
|
+
:
|
|
61
|
+
else
|
|
62
|
+
expected="$(checksum "$PAQUET/$rel")"
|
|
63
|
+
fi
|
|
64
|
+
[ "$current" = "$expected" ] || printf '%s\n' "$rel" >>"$work/modified"
|
|
65
|
+
done <"$package_list"
|
|
66
|
+
while IFS= read -r rel; do
|
|
67
|
+
[ -n "$rel" ] || continue
|
|
68
|
+
if ! path_allowed "$rel"; then
|
|
69
|
+
echo "devzone : manifeste : chemin refusé : $rel" >&2
|
|
70
|
+
continue
|
|
71
|
+
fi
|
|
72
|
+
in_list "$package_list" "$rel" && continue
|
|
73
|
+
is_protected "$rel" && continue
|
|
74
|
+
if ! inside_folder "$folder" "$rel"; then
|
|
75
|
+
echo "devzone : manifeste : chemin refusé : $rel" >&2
|
|
76
|
+
continue
|
|
77
|
+
fi
|
|
78
|
+
printf '%s\n' "$rel" >>"$work/to_remove"
|
|
79
|
+
[ -f "$folder/$rel" ] || continue
|
|
80
|
+
printf '%s\n' "$rel" >>"$work/to_save"
|
|
81
|
+
if expected="$(manifest_checksum "$folder" "$rel")"; then
|
|
82
|
+
[ "$(checksum "$folder/$rel")" = "$expected" ] || printf '%s\n' "$rel" >>"$work/modified"
|
|
83
|
+
else
|
|
84
|
+
printf '%s\n' "$rel" >>"$work/modified"
|
|
85
|
+
fi
|
|
86
|
+
done <"$old_list"
|
|
87
|
+
for old in core scripts; do
|
|
88
|
+
[ -d "$folder/$old" ] || continue
|
|
89
|
+
old_tree "$folder" "$old" || continue
|
|
90
|
+
printf '%s\n' "$old" >>"$work/old_trees"
|
|
91
|
+
while IFS= read -r f; do
|
|
92
|
+
rel="${f#"$folder"/}"
|
|
93
|
+
if ! path_allowed "$rel"; then
|
|
94
|
+
echo "devzone : manifeste : chemin refusé : $rel" >&2
|
|
95
|
+
continue
|
|
96
|
+
fi
|
|
97
|
+
is_protected "$rel" && continue
|
|
98
|
+
# A file unknown to the old package belongs to the user
|
|
99
|
+
known_old_file "$rel" || continue
|
|
100
|
+
printf '%s\n' "$rel" >>"$work/to_remove"
|
|
101
|
+
printf '%s\n' "$rel" >>"$work/to_save"
|
|
102
|
+
# Always confirmed: removing a file of the old package is a change,
|
|
103
|
+
# even with a manifest
|
|
104
|
+
printf '%s\n' "$rel" >>"$work/modified"
|
|
105
|
+
done < <(find "$folder/$old" -type f -print)
|
|
106
|
+
done
|
|
107
|
+
LC_ALL=C sort -u "$work/modified" >"$work/modified.sorted"
|
|
108
|
+
mv "$work/modified.sorted" "$work/modified"
|
|
109
|
+
LC_ALL=C sort -u "$work/to_save" >"$work/to_save.sorted"
|
|
110
|
+
mv "$work/to_save.sorted" "$work/to_save"
|
|
111
|
+
|
|
112
|
+
if [ -s "$work/modified" ]; then
|
|
113
|
+
echo "Fichiers modifiés localement :"
|
|
114
|
+
while IFS= read -r rel; do
|
|
115
|
+
printf ' %s\n' "$rel"
|
|
116
|
+
done <"$work/modified"
|
|
117
|
+
if [ -z "$assume_yes" ]; then
|
|
118
|
+
if [ ! -t 0 ]; then
|
|
119
|
+
echo "✖ Fichiers modifiés localement : relance avec --yes pour les remplacer (sauvegarde dans .devzone.sauvegarde/)." >&2
|
|
120
|
+
exit 1
|
|
121
|
+
fi
|
|
122
|
+
printf 'Remplacer ces fichiers (sauvegarde dans .devzone.sauvegarde/) ? [o/N] ' >&2
|
|
123
|
+
read -r answer || answer=""
|
|
124
|
+
case "$answer" in
|
|
125
|
+
o | O | oui | Oui | OUI) ;;
|
|
126
|
+
*)
|
|
127
|
+
echo "Abandon : rien n'a été modifié."
|
|
128
|
+
return 1
|
|
129
|
+
;;
|
|
130
|
+
esac
|
|
131
|
+
fi
|
|
132
|
+
fi
|
|
133
|
+
|
|
134
|
+
# 3. Backup of every file replaced or removed
|
|
135
|
+
if [ -s "$work/to_save" ]; then
|
|
136
|
+
base="$folder/.devzone.sauvegarde/$(date +%Y%m%d-%H%M%S)"
|
|
137
|
+
backup="$base"
|
|
138
|
+
n=1
|
|
139
|
+
while [ -e "$backup" ]; do
|
|
140
|
+
n=$((n + 1))
|
|
141
|
+
backup="$base-$n"
|
|
142
|
+
done
|
|
143
|
+
while IFS= read -r rel; do
|
|
144
|
+
[ -f "$folder/$rel" ] || continue
|
|
145
|
+
if ! inside_folder "$folder" "$rel"; then
|
|
146
|
+
echo "devzone : manifeste : chemin refusé : $rel" >&2
|
|
147
|
+
continue
|
|
148
|
+
fi
|
|
149
|
+
mkdir -p "$backup/$(dirname "$rel")"
|
|
150
|
+
# -P: a link is backed up as it is, never its target
|
|
151
|
+
cp -P -p "$folder/$rel" "$backup/$rel"
|
|
152
|
+
done <"$work/to_save"
|
|
153
|
+
echo "Sauvegarde : $backup"
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
# 4. Replacement, removal of the old package and of the old layout,
|
|
157
|
+
# .gitignore completed without being overwritten
|
|
158
|
+
complete_gitignore "$folder"
|
|
159
|
+
while IFS= read -r rel; do
|
|
160
|
+
mkdir -p "$folder/$(dirname "$rel")"
|
|
161
|
+
if ! inside_folder "$folder" "$rel"; then
|
|
162
|
+
echo "devzone : manifeste : chemin refusé : $rel" >&2
|
|
163
|
+
continue
|
|
164
|
+
fi
|
|
165
|
+
# Never write through a link: the link (not its target) is removed
|
|
166
|
+
if [ -L "$folder/$rel" ]; then
|
|
167
|
+
rm -f -- "$folder/$rel"
|
|
168
|
+
echo "devzone : manifeste : lien remplacé : $rel" >&2
|
|
169
|
+
fi
|
|
170
|
+
cp -p "$PAQUET/$rel" "$folder/$rel"
|
|
171
|
+
if [ -x "$PAQUET/$rel" ]; then
|
|
172
|
+
chmod +x "$folder/$rel"
|
|
173
|
+
fi
|
|
174
|
+
done <"$package_list"
|
|
175
|
+
while IFS= read -r rel; do
|
|
176
|
+
[ -n "$rel" ] || continue
|
|
177
|
+
[ -f "$folder/$rel" ] || continue
|
|
178
|
+
if ! inside_folder "$folder" "$rel"; then
|
|
179
|
+
echo "devzone : manifeste : chemin refusé : $rel" >&2
|
|
180
|
+
continue
|
|
181
|
+
fi
|
|
182
|
+
# rm does not follow links: only the link is removed, never its target
|
|
183
|
+
rm -f -- "$folder/$rel"
|
|
184
|
+
done <"$work/to_remove"
|
|
185
|
+
while IFS= read -r old; do
|
|
186
|
+
[ -n "$old" ] || continue
|
|
187
|
+
[ -d "$folder/$old" ] || continue
|
|
188
|
+
# Only the folders that became empty are removed, never their content
|
|
189
|
+
find "$folder/$old" -depth -type d -empty -delete
|
|
190
|
+
done <"$work/old_trees"
|
|
191
|
+
|
|
192
|
+
# 6. New manifest, then rebuild offered
|
|
193
|
+
write_manifest "$folder"
|
|
194
|
+
echo "✔ devzone $package : mis à jour."
|
|
195
|
+
bash "$PAQUET/manage/scripts/poste.sh" conseil "$folder" || true
|
|
196
|
+
# the update never changes the workstation mode (#472)
|
|
197
|
+
if [ "$(grep -E '^workspace=' "$folder/.devzone.modules" 2>/dev/null | tail -1)" = "workspace=kubernetes" ]; then
|
|
198
|
+
return 0
|
|
199
|
+
fi
|
|
200
|
+
if [ -n "$no_rebuild" ]; then
|
|
201
|
+
echo "Reconstruction non lancée (--sans-reconstruire)."
|
|
202
|
+
return 0
|
|
203
|
+
fi
|
|
204
|
+
if [ ! -t 0 ]; then
|
|
205
|
+
echo "Reconstruction : make -C $folder rebuild (à lancer dans un terminal)"
|
|
206
|
+
return 0
|
|
207
|
+
fi
|
|
208
|
+
printf 'Reconstruire le conteneur maintenant (make rebuild) ? [o/N] ' >&2
|
|
209
|
+
read -r answer || answer=""
|
|
210
|
+
case "$answer" in
|
|
211
|
+
o | O | oui | Oui | OUI) ;;
|
|
212
|
+
*)
|
|
213
|
+
echo "Reconstruction non lancée : make -C $folder rebuild"
|
|
214
|
+
return 0
|
|
215
|
+
;;
|
|
216
|
+
esac
|
|
217
|
+
if [ -n "${DEVZONE_RECONSTRUIRE:-}" ]; then
|
|
218
|
+
sh -c "$DEVZONE_RECONSTRUIRE"
|
|
219
|
+
else
|
|
220
|
+
make -C "$folder" rebuild
|
|
221
|
+
fi
|
|
222
|
+
}
|