devzone 0.59.0 → 1.1.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-erreurs.sh +72 -56
- package/.devcontainer/agent-etat-json.sh +45 -43
- package/.devcontainer/agent-modele.sh +3 -3
- package/.devcontainer/agent-session.sh +122 -125
- package/.devcontainer/agent-workspace.sh +53 -53
- package/.devcontainer/agent.sh +107 -109
- package/.devcontainer/argocd/argocd.sh +4 -16
- package/.devcontainer/catalogue/app.sh +1 -1
- package/.devcontainer/catalogue/catalogue-veilleur.sh +2 -2
- package/.devcontainer/catalogue/mysql/mysql.sh +1 -13
- package/.devcontainer/catalogue.sh +4 -16
- package/.devcontainer/cluster.sh +1 -1
- package/.devcontainer/command-aliases.sh +78 -114
- package/.devcontainer/devzone +34 -48
- package/.devcontainer/etat-json.sh +162 -162
- package/.devcontainer/etat-verrou.sh +25 -24
- package/.devcontainer/etat.sh +122 -123
- package/.devcontainer/gitlab/gitlab.sh +1 -13
- package/.devcontainer/gitlab/installation.sh +3 -3
- package/.devcontainer/gitlab/secrets.sh +1 -1
- package/.devcontainer/gitlab/test-gitlab.sh +1 -1
- package/.devcontainer/help.sh +4 -3
- package/.devcontainer/memoire.sh +58 -58
- package/.devcontainer/metrics-server.sh +52 -51
- package/.devcontainer/paquets.sh +0 -12
- package/.devcontainer/password.sh +88 -87
- package/.devcontainer/ports-auto.sh +6 -6
- package/.devcontainer/ports.sh +1 -13
- package/.devcontainer/postgres/postgres.sh +1 -13
- package/.devcontainer/services-admin.sh +3 -3
- package/.devcontainer/skills/devzone/SKILL.md +2 -2
- package/README.md +13 -3
- package/charts/devzone-workspace/templates/statefulset.yaml +3 -0
- package/manage/devzone +61 -569
- package/manage/scripts/argocd-services.sh +2 -2
- 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,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
|
+
}
|
package/manage/scripts/migrer.sh
CHANGED
|
@@ -33,14 +33,10 @@ fail() {
|
|
|
33
33
|
# Reads the single accepted flag ($1) from following args ($3…): prints 1 if
|
|
34
34
|
# present, 0 otherwise; any other flag: error with usage ($2), exit code 1.
|
|
35
35
|
read_flag() {
|
|
36
|
-
local flag="$1" usage="$2" a found=0
|
|
36
|
+
local flag="$1" usage="$2" a found=0
|
|
37
37
|
shift 2
|
|
38
|
-
case "$flag" in
|
|
39
|
-
--yes) legacy="--oui" ;;
|
|
40
|
-
--bring-back) legacy="--rapatrier" ;;
|
|
41
|
-
esac
|
|
42
38
|
for a in "$@"; do
|
|
43
|
-
if [ "$a" = "$flag" ]
|
|
39
|
+
if [ "$a" = "$flag" ]; then found=1; continue; fi
|
|
44
40
|
fail "unknown option: $a (devzone workspace $usage)"
|
|
45
41
|
return 1
|
|
46
42
|
done
|
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
# sourced by manage/workspace.sh
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# compatibility aliases of the renamed functions, kept until lot 4 (#509)
|
|
7
|
-
# Why: command_canonical (.devcontainer/command-aliases.sh) still gives the
|
|
8
|
-
# French name; workspace.sh switches on the English ones. bash 3.2 (macOS).
|
|
9
|
-
|
|
10
|
-
workspace_command() {
|
|
11
|
-
case "${1:-}" in
|
|
12
|
-
demarrer) echo start ;;
|
|
13
|
-
mettre-a-jour) echo update ;;
|
|
14
|
-
arreter) echo stop ;;
|
|
15
|
-
etat) echo status ;;
|
|
16
|
-
copier-vers) echo copy-to ;;
|
|
17
|
-
copier-depuis) echo copy-from ;;
|
|
18
|
-
migrer) echo migrate ;;
|
|
19
|
-
revenir) echo revert ;;
|
|
20
|
-
nettoyer-docker) echo clean-docker ;;
|
|
21
|
-
*) echo "${1:-}" ;;
|
|
22
|
-
esac
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
workspace_ports_command() {
|
|
26
|
-
case "${1:-}" in
|
|
27
|
-
demarrer) echo start ;;
|
|
28
|
-
arreter) echo stop ;;
|
|
29
|
-
etat) echo status ;;
|
|
30
|
-
*) echo "${1:-}" ;;
|
|
31
|
-
esac
|
|
32
|
-
}
|
|
2
|
+
# Compatibility aliases of the workspace functions renamed during the English
|
|
3
|
+
# migration (#502, lot 3), sourced by manage/workspace.sh. The old French names
|
|
4
|
+
# of the subcommands are refused by reject_renamed (.devcontainer/command-aliases.sh, #695).
|
|
5
|
+
# bash 3.2 (macOS).
|
|
33
6
|
|
|
34
7
|
# compatibility aliases, removed with lot 4 (#509); RACINE and ICI are still
|
|
35
8
|
# read by the scripts of the lot 5 files (argocd-*.sh, services-workspace.sh)
|
package/manage/workspace.sh
CHANGED
|
@@ -192,24 +192,19 @@ copy_from() {
|
|
|
192
192
|
# shellcheck source=manage/scripts/workspace-egress.sh
|
|
193
193
|
. "$HERE/scripts/workspace-egress.sh"
|
|
194
194
|
|
|
195
|
-
#
|
|
196
|
-
#
|
|
195
|
+
# Renamed names (#695): an old French name is refused before anything runs, with
|
|
196
|
+
# its English name (« devzone workspace start »). A copied devzone may miss the
|
|
197
|
+
# aliases file: then no check.
|
|
197
198
|
# shellcheck source=../.devcontainer/command-aliases.sh
|
|
198
199
|
# shellcheck disable=SC1091
|
|
199
200
|
if [ -f "$ROOT/.devcontainer/command-aliases.sh" ]; then
|
|
200
201
|
. "$ROOT/.devcontainer/command-aliases.sh"
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
fi
|
|
205
|
-
set -- "$(command_canonical "$1")" "${@:2}"
|
|
202
|
+
reject_renamed workspace "$@" || exit 1
|
|
203
|
+
if [ "${1:-}" = ports ] && [ "$#" -gt 1 ]; then
|
|
204
|
+
reject_renamed "workspace ports" "${@:2}" || exit 1
|
|
206
205
|
fi
|
|
207
206
|
fi
|
|
208
207
|
|
|
209
|
-
if [ "$#" -gt 0 ]; then set -- "$(workspace_command "$1")" "${@:2}"; fi
|
|
210
|
-
if [ "${1:-}" = "ports" ] && [ "$#" -gt 1 ]; then
|
|
211
|
-
set -- "$1" "$(workspace_ports_command "$2")" "${@:3}"
|
|
212
|
-
fi
|
|
213
208
|
|
|
214
209
|
case "${1:-}" in
|
|
215
210
|
start) start_workspace "${@:2}" ;;
|
|
@@ -228,7 +223,7 @@ case "${1:-}" in
|
|
|
228
223
|
services) services "${@:2}" ;;
|
|
229
224
|
argocd) argocd_cmd "${@:2}" ;;
|
|
230
225
|
egress) egress_workspace "${@:2}" ;;
|
|
231
|
-
'' | -h | --help |
|
|
226
|
+
'' | -h | --help | help)
|
|
232
227
|
echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker|update|egress"
|
|
233
228
|
echo " start [--image repository:tag] install workspace (image for devzone version by default)"
|
|
234
229
|
echo " update [--version X.Y.Z] [--yes] move to the latest stable release (or X.Y.Z); the pod is recreated"
|