@puddle-code/cli 0.3.14 → 0.4.2
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/CHANGELOG.md +15 -5
- package/README.md +33 -19
- package/dist/host-control.mjs +1980 -133
- package/dist/index.js +4342 -970
- package/dist/install.sh +401 -40
- package/dist/public/assets/App-CbjV_eCr.js +19 -0
- package/dist/public/assets/{CompilationCommandForm-8ipw9M-Z.js → CompilationCommandForm-C71yC-_B.js} +1 -1
- package/dist/public/assets/Dashboard-CaVEQBQm.js +1 -0
- package/dist/public/assets/{EditorTabClose-o1L4BgTN.js → EditorTabClose-CHZNbZkD.js} +1 -1
- package/dist/public/assets/{FindWidget-CVH9U-_P.js → FindWidget-CaVwYvST.js} +1 -1
- package/dist/public/assets/LazyTerminal-BvZY-D0f.js +2 -0
- package/dist/public/assets/{ModelRefcount-0o8MEOUT.js → ModelRefcount-R_PJzn4E.js} +1 -1
- package/dist/public/assets/NewProjectDialog-B6wof57i.js +1 -0
- package/dist/public/assets/{NotebookWidget-Ci7TAuWd.js → NotebookWidget-D6vzMCnH.js} +1 -1
- package/dist/public/assets/PaneEditorBody-Bn8cmN5i.js +284 -0
- package/dist/public/assets/PdfViewer-C-dXDOjG.js +2 -0
- package/dist/public/assets/ReleaseNotesDialog-Z7jtCZYz.js +1 -0
- package/dist/public/assets/SettingsDialog-lSPFdtsX.js +8 -0
- package/dist/public/assets/{Terminal-B3Iw783s.js → Terminal-C9fEeTMx.js} +5 -5
- package/dist/public/assets/Workspace-DleYwgSG.js +20 -0
- package/dist/public/assets/api-BOuyloUi.js +1 -0
- package/dist/public/assets/auth-olLlgxc3.js +64 -0
- package/dist/public/assets/{buffer-store-B2nYD11t.js → buffer-store-DeLu2KS4.js} +1 -1
- package/dist/public/assets/button-q0ardkfx.js +1 -0
- package/dist/public/assets/{chevron-down--sjpQEHH.js → chevron-down-HQLVE6o5.js} +1 -1
- package/dist/public/assets/chevron-right-BP2NLwlG.js +1 -0
- package/dist/public/assets/code-Cf4ftdOa.js +1 -0
- package/dist/public/assets/command-BkdEYC1b.js +1 -0
- package/dist/public/assets/{context-CwZ4epwz.js → context-C3-WejyN.js} +1 -1
- package/dist/public/assets/context-menu-C0cOAj0E.js +1 -0
- package/dist/public/assets/control-tray-D7OXXkAy.css +1 -0
- package/dist/public/assets/control-tray-OJfh0_ml.js +1 -0
- package/dist/public/assets/{copy-CGsu8426.js → copy-D0Theg4Q.js} +1 -1
- package/dist/public/assets/createLucideIcon-C9A1vLE-.js +1 -0
- package/dist/public/assets/dialog-IU2fjIs9.js +41 -0
- package/dist/public/assets/{dist-Cde1E3eV.js → dist-BHBQY7ao.js} +1 -1
- package/dist/public/assets/{dist-CBag2On7.js → dist-CGlwr6Pc.js} +1 -1
- package/dist/public/assets/dist-eLNGMhYC.js +1 -0
- package/dist/public/assets/{forward-link-C-8Xn8gf.js → forward-link-DMvLf0Xw.js} +1 -1
- package/dist/public/assets/{hotkeys-DOpJ1a7g.js → hotkeys-Cu0t6sbz.js} +1 -1
- package/dist/public/assets/index-C3TPFFMc.css +2 -0
- package/dist/public/assets/{index-B9DFgBft.js → index-DK1twGI0.js} +3 -3
- package/dist/public/assets/markdown-CMSzQtLp.js +8 -0
- package/dist/public/assets/markdown-it-CWoG9_Dn.js +13 -0
- package/dist/public/assets/{markdown-mermaid-CZnHoKN5.js → markdown-mermaid-B648xTNp.js} +1 -1
- package/dist/public/assets/media-refresh-store-CHPkX-XV.js +1 -0
- package/dist/public/assets/notification-delivery-BlvH2Ojs.js +1 -0
- package/dist/public/assets/popover-B5Bw2ljC.js +1 -0
- package/dist/public/assets/{preview-kind-DiWpvEc0.js → preview-kind-CPkO-rSz.js} +1 -1
- package/dist/public/assets/protocol-support-CsLR9u7d.js +1 -0
- package/dist/public/assets/queue-BlrQxHDl.js +3 -0
- package/dist/public/assets/{rotate-ccw-CNjR2LSi.js → rotate-ccw-BI2k_h3A.js} +1 -1
- package/dist/public/assets/{scroll-restoration-gKZDDamc.js → scroll-restoration-CwXbvZvT.js} +1 -1
- package/dist/public/assets/{select-9OADuw7W.js → select-C0UTbo8D.js} +1 -1
- package/dist/public/assets/selection-actions-BLoNrxbO.js +1 -0
- package/dist/public/assets/session-order-2oedrwDu.js +1 -0
- package/dist/public/assets/switch-DihTSmnc.js +1 -0
- package/dist/public/assets/{use-ui-state-CQp93ZE4.js → use-ui-state-e6mUjW-H.js} +1 -1
- package/dist/public/assets/{view-state-store-CVAUWqnG.js → view-state-store-Cy9sQJoZ.js} +1 -1
- package/dist/public/assets/{whole-word-2m2pmAFT.js → whole-word-BJjKpISQ.js} +1 -1
- package/dist/public/assets/ws-BX1iQbeP.js +1 -0
- package/dist/public/assets/x-Dq6POV20.js +1 -0
- package/dist/public/file-icons/material/LICENSE +8 -0
- package/dist/public/file-icons/material/SOURCE.txt +4 -0
- package/dist/public/file-icons/material/astro.svg +1 -0
- package/dist/public/file-icons/material/audio.svg +1 -0
- package/dist/public/file-icons/material/c.svg +1 -0
- package/dist/public/file-icons/material/console.svg +1 -0
- package/dist/public/file-icons/material/cpp.svg +1 -0
- package/dist/public/file-icons/material/csharp.svg +1 -0
- package/dist/public/file-icons/material/css.svg +1 -0
- package/dist/public/file-icons/material/dart.svg +1 -0
- package/dist/public/file-icons/material/database.svg +1 -0
- package/dist/public/file-icons/material/docker.svg +1 -0
- package/dist/public/file-icons/material/document.svg +1 -0
- package/dist/public/file-icons/material/eslint.svg +1 -0
- package/dist/public/file-icons/material/font.svg +1 -0
- package/dist/public/file-icons/material/git.svg +1 -0
- package/dist/public/file-icons/material/go-mod.svg +1 -0
- package/dist/public/file-icons/material/go.svg +1 -0
- package/dist/public/file-icons/material/h.svg +1 -0
- package/dist/public/file-icons/material/hpp.svg +1 -0
- package/dist/public/file-icons/material/html.svg +1 -0
- package/dist/public/file-icons/material/image.svg +1 -0
- package/dist/public/file-icons/material/java.svg +1 -0
- package/dist/public/file-icons/material/javascript.svg +1 -0
- package/dist/public/file-icons/material/json.svg +1 -0
- package/dist/public/file-icons/material/jupyter.svg +1 -0
- package/dist/public/file-icons/material/kotlin.svg +1 -0
- package/dist/public/file-icons/material/less.svg +1 -0
- package/dist/public/file-icons/material/license.svg +1 -0
- package/dist/public/file-icons/material/lock.svg +1 -0
- package/dist/public/file-icons/material/markdown.svg +1 -0
- package/dist/public/file-icons/material/npm.svg +1 -0
- package/dist/public/file-icons/material/pdf.svg +1 -0
- package/dist/public/file-icons/material/php.svg +1 -0
- package/dist/public/file-icons/material/pnpm.svg +1 -0
- package/dist/public/file-icons/material/prettier.svg +1 -0
- package/dist/public/file-icons/material/python.svg +1 -0
- package/dist/public/file-icons/material/react.svg +1 -0
- package/dist/public/file-icons/material/react_ts.svg +1 -0
- package/dist/public/file-icons/material/readme.svg +1 -0
- package/dist/public/file-icons/material/ruby.svg +1 -0
- package/dist/public/file-icons/material/rust.svg +1 -0
- package/dist/public/file-icons/material/sass.svg +1 -0
- package/dist/public/file-icons/material/settings.svg +1 -0
- package/dist/public/file-icons/material/svelte.svg +1 -0
- package/dist/public/file-icons/material/svg.svg +1 -0
- package/dist/public/file-icons/material/swift.svg +1 -0
- package/dist/public/file-icons/material/table.svg +1 -0
- package/dist/public/file-icons/material/toml.svg +1 -0
- package/dist/public/file-icons/material/tune.svg +1 -0
- package/dist/public/file-icons/material/typescript-def.svg +1 -0
- package/dist/public/file-icons/material/typescript.svg +1 -0
- package/dist/public/file-icons/material/video.svg +1 -0
- package/dist/public/file-icons/material/vite.svg +1 -0
- package/dist/public/file-icons/material/vitest.svg +1 -0
- package/dist/public/file-icons/material/vue.svg +1 -0
- package/dist/public/file-icons/material/xml.svg +1 -0
- package/dist/public/file-icons/material/yaml.svg +1 -0
- package/dist/public/file-icons/material/yarn.svg +1 -0
- package/dist/public/file-icons/material/zip.svg +1 -0
- package/dist/public/index.html +3 -3
- package/dist/pudl.js +1996 -183
- package/package.json +1 -1
- package/dist/public/assets/App-5QiKmUI_.js +0 -2
- package/dist/public/assets/Dashboard-B9v8mQKk.js +0 -1
- package/dist/public/assets/LazyTerminal-Crwcrh-K.js +0 -2
- package/dist/public/assets/NewProjectDialog-qFDLTphH.js +0 -1
- package/dist/public/assets/PaneEditorBody-C8uTV9yU.js +0 -303
- package/dist/public/assets/PdfViewer-BoFsXAue.js +0 -2
- package/dist/public/assets/SettingsDialog-tW18Y_Wr.js +0 -8
- package/dist/public/assets/Workspace-D2IYXJV2.js +0 -20
- package/dist/public/assets/api-CfmzEbQ_.js +0 -1
- package/dist/public/assets/auth-CIb9G2C5.js +0 -64
- package/dist/public/assets/button-9AVMLaMQ.js +0 -1
- package/dist/public/assets/chevron-right-BRjnLYaO.js +0 -1
- package/dist/public/assets/code-DRWf9a5s.js +0 -1
- package/dist/public/assets/command-BUOkDmUW.js +0 -1
- package/dist/public/assets/context-menu-D-5BvS0X.js +0 -1
- package/dist/public/assets/createLucideIcon-DyMAgLa3.js +0 -1
- package/dist/public/assets/dialog-BMWRC2HO.js +0 -41
- package/dist/public/assets/dist-CcLyf3-2.js +0 -1
- package/dist/public/assets/errors-DTaodZDR.js +0 -1
- package/dist/public/assets/index-DwtrJj9v.css +0 -2
- package/dist/public/assets/media-refresh-store-DDvrEM5K.js +0 -1
- package/dist/public/assets/notification-delivery-DdTD40aA.js +0 -1
- package/dist/public/assets/popover-CtxJVkPi.js +0 -1
- package/dist/public/assets/protocol-support-BGk73LFk.js +0 -1
- package/dist/public/assets/selection-actions-BjVj7hXw.js +0 -1
- package/dist/public/assets/session-order-SN_zG4Us.js +0 -1
- package/dist/public/assets/switch-iVuj74VW.js +0 -1
- package/dist/public/assets/ws-CspBmo8M.js +0 -1
- package/dist/public/assets/x-DCpy1q13.js +0 -1
package/dist/install.sh
CHANGED
|
@@ -20,11 +20,22 @@ SUMS=""
|
|
|
20
20
|
SUPERVISOR=1
|
|
21
21
|
START=1
|
|
22
22
|
FORCE=0
|
|
23
|
+
COMPONENT=daemon
|
|
24
|
+
SELECTOR=current
|
|
25
|
+
OTHER_SELECTOR=runtime-current
|
|
26
|
+
EXECUTABLE=puddled
|
|
27
|
+
STAGE_ONLY=0
|
|
28
|
+
SELECT_ONLY=0
|
|
29
|
+
ACTIVATE=""
|
|
30
|
+
STAGE_DIGEST=""
|
|
31
|
+
CHECKSUM_VERIFIED=0
|
|
23
32
|
|
|
24
33
|
usage() {
|
|
25
34
|
cat <<'EOF'
|
|
26
35
|
usage: install.sh [--version X.Y.Z] [--tarball <path>] [--sums <path>]
|
|
27
36
|
[--repo owner/repo] [--no-supervisor] [--no-start] [--force]
|
|
37
|
+
[--component daemon|runtime]
|
|
38
|
+
[--stage-only | --activate-generation <name> --stage-digest <sha256>]
|
|
28
39
|
|
|
29
40
|
--version release to install (default: the repo's latest release)
|
|
30
41
|
--tarball use a pre-delivered tarball instead of fetching (scp
|
|
@@ -35,11 +46,19 @@ usage: install.sh [--version X.Y.Z] [--tarball <path>] [--sums <path>]
|
|
|
35
46
|
--no-supervisor unpack + symlink only
|
|
36
47
|
--no-start install the supervisor but do not start the daemon
|
|
37
48
|
--force reinstall even if this version is already present
|
|
49
|
+
--component select daemon (default) or the build for new runtimes;
|
|
50
|
+
runtime installation does not start or restart any service
|
|
51
|
+
--stage-only verify a fresh generation and emit its receipt without activation
|
|
52
|
+
--select-only activate an exact stage without changing supervisor configuration
|
|
53
|
+
or starting/restarting services (requires --activate-generation)
|
|
54
|
+
--activate-generation
|
|
55
|
+
activate an exact previously staged generation, without fetching
|
|
56
|
+
--stage-digest expected staged receipt digest (requires --version and --component)
|
|
38
57
|
EOF
|
|
39
58
|
}
|
|
40
59
|
|
|
41
|
-
say() { printf '
|
|
42
|
-
die() { printf '
|
|
60
|
+
say() { printf '%s install: %s\n' "$EXECUTABLE" "$1"; }
|
|
61
|
+
die() { printf '%s install: error: %s\n' "$EXECUTABLE" "$1" >&2; exit 1; }
|
|
43
62
|
|
|
44
63
|
while [ $# -gt 0 ]; do
|
|
45
64
|
case "$1" in
|
|
@@ -50,10 +69,38 @@ while [ $# -gt 0 ]; do
|
|
|
50
69
|
--no-supervisor) SUPERVISOR=0; shift ;;
|
|
51
70
|
--no-start) START=0; shift ;;
|
|
52
71
|
--force) FORCE=1; shift ;;
|
|
72
|
+
--component) COMPONENT="$2"; shift 2 ;;
|
|
73
|
+
--stage-only) STAGE_ONLY=1; shift ;;
|
|
74
|
+
--select-only) SELECT_ONLY=1; shift ;;
|
|
75
|
+
--activate-generation) ACTIVATE="$2"; shift 2 ;;
|
|
76
|
+
--stage-digest) STAGE_DIGEST="$2"; shift 2 ;;
|
|
53
77
|
-h|--help) usage; exit 0 ;;
|
|
54
78
|
*) die "unknown flag $1 (see --help)" ;;
|
|
55
79
|
esac
|
|
56
80
|
done
|
|
81
|
+
case "$COMPONENT" in
|
|
82
|
+
daemon) ;;
|
|
83
|
+
runtime) SELECTOR=runtime-current; OTHER_SELECTOR=current; EXECUTABLE=puddler ;;
|
|
84
|
+
*) die "unknown host component: $COMPONENT" ;;
|
|
85
|
+
esac
|
|
86
|
+
if [ -n "$ACTIVATE" ]; then
|
|
87
|
+
[ "$STAGE_ONLY" -eq 0 ] && [ "$FORCE" -eq 0 ] && [ -z "$TARBALL" ] && [ -z "$SUMS" ] \
|
|
88
|
+
|| die "activation cannot fetch, stage or force a repair"
|
|
89
|
+
[ -n "$VERSION" ] || die "activation requires an exact version"
|
|
90
|
+
case "$ACTIVATE" in ''|*[!0-9A-Za-z.+~_-]*) die "invalid staged generation" ;; esac
|
|
91
|
+
printf '%s\n' "$ACTIVATE" | LC_ALL=C grep -Eq '^.+~[A-Za-z0-9]{6}$' \
|
|
92
|
+
|| die "invalid staged generation"
|
|
93
|
+
[ "${#ACTIVATE}" -le 135 ] || die "staged generation is too long"
|
|
94
|
+
[ "${#STAGE_DIGEST}" -eq 64 ] || die "activation requires a stage digest"
|
|
95
|
+
case "$STAGE_DIGEST" in *[!0-9a-f]*) die "invalid stage digest" ;; esac
|
|
96
|
+
elif [ -n "$STAGE_DIGEST" ]; then
|
|
97
|
+
die "a stage digest requires activation"
|
|
98
|
+
fi
|
|
99
|
+
if [ "$SELECT_ONLY" -eq 1 ]; then
|
|
100
|
+
[ -n "$ACTIVATE" ] && [ "$SUPERVISOR" -eq 1 ] && [ "$START" -eq 1 ] \
|
|
101
|
+
|| die "selection-only requires exact activation without supervisor flags"
|
|
102
|
+
fi
|
|
103
|
+
if [ "$STAGE_ONLY" -eq 1 ]; then FORCE=1; fi
|
|
57
104
|
|
|
58
105
|
# --- platform ---------------------------------------------------------------
|
|
59
106
|
OS=$(uname -s)
|
|
@@ -86,9 +133,77 @@ esac
|
|
|
86
133
|
[ "$DIR_OWNER" = "$(id -u)" ] || die "Puddle home must be owned by the current user: $HOME_DIR"
|
|
87
134
|
[ "$((0$DIR_MODE & 0022))" -eq 0 ] || die "Puddle home must not be writable by other users: $HOME_DIR"
|
|
88
135
|
chmod 700 "$HOME_DIR"
|
|
136
|
+
HOME_DIR=$(CDPATH= cd -- "$HOME_DIR" && pwd -P)
|
|
137
|
+
umask 077
|
|
89
138
|
BIN_DIR="$HOME_DIR/bin"
|
|
90
139
|
CACHE_DIR="$HOME_DIR/cache"
|
|
140
|
+
for DIRECTORY in "$BIN_DIR" "$BIN_DIR/versions" "$CACHE_DIR"; do
|
|
141
|
+
[ ! -L "$DIRECTORY" ] || die "installation directory must not be a symlink: $DIRECTORY"
|
|
142
|
+
done
|
|
91
143
|
mkdir -p "$BIN_DIR/versions" "$CACHE_DIR" "$HOME_DIR/logs"
|
|
144
|
+
# A permanent regular file also fences older installers, whose mkdir must fail.
|
|
145
|
+
# Keep this inode: flock is inherited by children and releases after all references
|
|
146
|
+
# close, including after SIGKILL. Match daemon host/installation/lock.ts.
|
|
147
|
+
LOCK="$BIN_DIR/.install-lock"
|
|
148
|
+
[ ! -L "$LOCK" ] || die "installation lock must not be a symlink"
|
|
149
|
+
[ ! -d "$LOCK" ] || die "another installer is running, or a legacy installation lock needs inspection"
|
|
150
|
+
if [ ! -e "$LOCK" ]; then
|
|
151
|
+
(set -C; : > "$LOCK") 2>/dev/null || [ -f "$LOCK" ] || die "cannot create installation lock"
|
|
152
|
+
fi
|
|
153
|
+
[ -f "$LOCK" ] && [ ! -L "$LOCK" ] || die "installation lock must be a regular file"
|
|
154
|
+
case "$OS" in
|
|
155
|
+
darwin) LOCK_INFO=$(stat -f '%u %Lp %l %z' "$LOCK") ;;
|
|
156
|
+
linux) LOCK_INFO=$(stat -c '%u %a %h %s' "$LOCK") ;;
|
|
157
|
+
esac
|
|
158
|
+
set -- $LOCK_INFO
|
|
159
|
+
[ "$1" = "$(id -u)" ] && [ "$((0$2 & 0077))" -eq 0 ] && [ "$3" = 1 ] && [ "$4" = 0 ] \
|
|
160
|
+
|| die "unsafe installation lock"
|
|
161
|
+
exec 9>> "$LOCK"
|
|
162
|
+
case "$OS" in
|
|
163
|
+
darwin)
|
|
164
|
+
/usr/bin/env -i PATH=/usr/bin:/bin /usr/bin/perl -e \
|
|
165
|
+
'use Fcntl qw(LOCK_EX LOCK_NB); open(my $lock, ">&=$ARGV[0]") or exit 74; flock($lock, LOCK_EX|LOCK_NB) or exit 75;' 9 \
|
|
166
|
+
|| die "another installer is running or installation locking is unavailable" ;;
|
|
167
|
+
linux)
|
|
168
|
+
/usr/bin/env -i PATH=/usr/bin:/bin flock -E 75 -n 9 \
|
|
169
|
+
|| die "another installer is running or installation locking is unavailable" ;;
|
|
170
|
+
esac
|
|
171
|
+
STAGE=""
|
|
172
|
+
WORK=""
|
|
173
|
+
# Keep the same passive removal fence as shared/node/installation/removal.ts.
|
|
174
|
+
# A malformed record is still evidence of an unresolved removal, never permission
|
|
175
|
+
# to overwrite the selected release or recreate a service.
|
|
176
|
+
for REMOVAL_DIR in "$HOME_DIR/installation" "$HOME_DIR/installation/removal"; do
|
|
177
|
+
[ ! -L "$REMOVAL_DIR" ] || die "unsafe host removal directory"
|
|
178
|
+
if [ -e "$REMOVAL_DIR" ]; then
|
|
179
|
+
[ -d "$REMOVAL_DIR" ] || die "unsafe host removal directory"
|
|
180
|
+
case "$OS" in
|
|
181
|
+
darwin) REMOVAL_INFO=$(stat -f '%u %Lp' "$REMOVAL_DIR") ;;
|
|
182
|
+
linux) REMOVAL_INFO=$(stat -c '%u %a' "$REMOVAL_DIR") ;;
|
|
183
|
+
esac
|
|
184
|
+
set -- $REMOVAL_INFO
|
|
185
|
+
[ "$1" = "$(id -u)" ] && [ "$((0$2 & 0077))" -eq 0 ] || die "unsafe host removal directory"
|
|
186
|
+
fi
|
|
187
|
+
done
|
|
188
|
+
if [ -e "$HOME_DIR/installation/removal/services.json" ] || [ -L "$HOME_DIR/installation/removal/services.json" ] ||
|
|
189
|
+
[ -e "$HOME_DIR/installation/removal/purge.json" ] || [ -L "$HOME_DIR/installation/removal/purge.json" ]; then
|
|
190
|
+
die "resolve the recorded host removal before installing or updating this host"
|
|
191
|
+
fi
|
|
192
|
+
cleanup() {
|
|
193
|
+
if [ -n "$STAGE" ] &&
|
|
194
|
+
[ "$(readlink "$BIN_DIR/current" 2>/dev/null || true)" != "versions/$(basename "$STAGE")" ] &&
|
|
195
|
+
[ "$(readlink "$BIN_DIR/runtime-current" 2>/dev/null || true)" != "versions/$(basename "$STAGE")" ]; then
|
|
196
|
+
rm -rf "$STAGE"
|
|
197
|
+
fi
|
|
198
|
+
if [ -n "$WORK" ]; then rm -rf "$WORK"; fi
|
|
199
|
+
}
|
|
200
|
+
trap cleanup 0
|
|
201
|
+
trap 'exit 1' 1 2 3 15
|
|
202
|
+
valid_version() {
|
|
203
|
+
case "$VERSION" in ''|*[!0-9A-Za-z.+-]*) die "invalid release version: $VERSION" ;; esac
|
|
204
|
+
[ "${#VERSION}" -le 128 ] && printf '%s\n' "$VERSION" | LC_ALL=C grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([+-][A-Za-z0-9.-]+)?$' \
|
|
205
|
+
|| die "invalid release version: $VERSION"
|
|
206
|
+
}
|
|
92
207
|
|
|
93
208
|
# --- resolve version / fetch -------------------------------------------------
|
|
94
209
|
sha_tool() {
|
|
@@ -97,22 +212,21 @@ sha_tool() {
|
|
|
97
212
|
else echo ""
|
|
98
213
|
fi
|
|
99
214
|
}
|
|
215
|
+
prune_cache() {
|
|
216
|
+
# Keep the current download and one previous archive; published trees stay intact.
|
|
217
|
+
ls -1t "$CACHE_DIR"/puddled-v*.tar.gz 2>/dev/null | tail -n +3 | while read -r old; do rm -f "$old"; done
|
|
218
|
+
}
|
|
100
219
|
|
|
101
|
-
if [ -n "$
|
|
220
|
+
if [ -n "$ACTIVATE" ]; then
|
|
221
|
+
: # The verified generation is already on this host; never fetch a replacement.
|
|
222
|
+
elif [ -n "$TARBALL" ]; then
|
|
102
223
|
[ -f "$TARBALL" ] || die "tarball not found: $TARBALL"
|
|
103
224
|
# Derive the version from the file name when not given explicitly.
|
|
104
225
|
if [ -z "$VERSION" ]; then
|
|
105
226
|
VERSION=$(basename "$TARBALL" | sed -n 's/^puddled-v\([0-9][^-]*\)-.*$/\1/p')
|
|
106
227
|
[ -n "$VERSION" ] || die "cannot derive a version from $(basename "$TARBALL"); pass --version"
|
|
107
228
|
fi
|
|
108
|
-
|
|
109
|
-
TOOL=$(sha_tool)
|
|
110
|
-
[ -n "$TOOL" ] || die "no sha256sum or shasum on this host to verify --sums"
|
|
111
|
-
( cd "$(dirname "$TARBALL")" && grep " $(basename "$TARBALL")\$" "$SUMS" | $TOOL ) \
|
|
112
|
-
|| die "checksum mismatch for $TARBALL"
|
|
113
|
-
else
|
|
114
|
-
say "warning: --tarball without --sums — checksum verification skipped"
|
|
115
|
-
fi
|
|
229
|
+
|
|
116
230
|
else
|
|
117
231
|
case "$REPO" in *@@*) die "no repository baked in; pass --repo owner/repo or set PUDDLE_REPO" ;; esac
|
|
118
232
|
command -v curl >/dev/null 2>&1 || die "curl is required to fetch releases (or pre-deliver with --tarball)"
|
|
@@ -123,53 +237,300 @@ else
|
|
|
123
237
|
VERSION=$(printf '%s' "$LATEST" | sed -n 's#.*/tag/v\{0,1\}##p')
|
|
124
238
|
[ -n "$VERSION" ] || die "could not resolve the latest release of $REPO; pass --version"
|
|
125
239
|
fi
|
|
240
|
+
valid_version
|
|
126
241
|
FILE="puddled-v$VERSION-$OS-$ARCH.tar.gz"
|
|
127
242
|
BASE="https://github.com/$REPO/releases/download/v$VERSION"
|
|
128
243
|
TARBALL="$CACHE_DIR/$FILE"
|
|
129
244
|
say "fetching $BASE/$FILE"
|
|
130
245
|
curl -fSL --progress-bar -o "$TARBALL" "$BASE/$FILE" || die "download failed"
|
|
131
246
|
curl -fsSL -o "$CACHE_DIR/SHA256SUMS" "$BASE/SHA256SUMS" || die "checksums download failed"
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
247
|
+
SUMS="$CACHE_DIR/SHA256SUMS"
|
|
248
|
+
fi
|
|
249
|
+
valid_version
|
|
250
|
+
if [ -z "$ACTIVATE" ]; then
|
|
251
|
+
# Resolve before changing directory, including SSH-delivered relative sums.
|
|
252
|
+
TARBALL="$(CDPATH= cd -- "$(dirname "$TARBALL")" && pwd -P)/$(basename "$TARBALL")"
|
|
253
|
+
if [ -n "$SUMS" ]; then
|
|
254
|
+
SUMS="$(CDPATH= cd -- "$(dirname "$SUMS")" && pwd -P)/$(basename "$SUMS")"
|
|
255
|
+
fi
|
|
256
|
+
# Checksum verification, extraction and receipt hashing must observe the same
|
|
257
|
+
# private archive snapshot, including ordinary bootstrap from a caller's file.
|
|
258
|
+
[ ! -L "$CACHE_DIR/install" ] || die "installation cache must not be a symlink"
|
|
259
|
+
mkdir -p "$CACHE_DIR/install"
|
|
260
|
+
WORK=$(mktemp -d "$CACHE_DIR/install/stage.XXXXXX")
|
|
261
|
+
cp "$TARBALL" "$WORK/$(basename "$TARBALL")"
|
|
262
|
+
TARBALL="$WORK/$(basename "$TARBALL")"
|
|
263
|
+
if [ -n "$SUMS" ]; then cp "$SUMS" "$WORK/SHA256SUMS"; SUMS="$WORK/SHA256SUMS"; fi
|
|
264
|
+
if [ -n "$SUMS" ]; then
|
|
265
|
+
TOOL=$(sha_tool)
|
|
266
|
+
[ -n "$TOOL" ] || die "no sha256sum or shasum on this host to verify --sums"
|
|
267
|
+
( cd "$(dirname "$TARBALL")" && grep " $(basename "$TARBALL")\$" "$SUMS" | $TOOL ) \
|
|
268
|
+
|| die "checksum mismatch for $TARBALL"
|
|
269
|
+
CHECKSUM_VERIFIED=1
|
|
270
|
+
else
|
|
271
|
+
say "warning: --tarball without --sums — checksum verification skipped"
|
|
272
|
+
fi
|
|
138
273
|
fi
|
|
139
274
|
|
|
140
275
|
# --- unpack + symlink flip ---------------------------------------------------
|
|
141
|
-
|
|
276
|
+
smoke() {
|
|
277
|
+
"$1/bin/node" --input-type=commonjs - "$1" "${2:-$EXECUTABLE}" "$VERSION" "$STAGE_ONLY" "$ACTIVATE" <<'NODE'
|
|
278
|
+
const fs = require('node:fs'), path = require('node:path');
|
|
279
|
+
const { spawnSync } = require('node:child_process');
|
|
280
|
+
const [root, executable, version, stageOnly, activate] = process.argv.slice(2);
|
|
281
|
+
let expected;
|
|
282
|
+
if (executable === 'puddler' || stageOnly === '1' || activate) {
|
|
283
|
+
const file = path.join(root, executable === 'puddler' ? 'RUNTIME_PROTOCOL' : 'PROTOCOL');
|
|
284
|
+
const stat = fs.lstatSync(file);
|
|
285
|
+
if (!stat.isFile() || stat.size > 33) throw Error('Invalid runtime protocol metadata');
|
|
286
|
+
const protocol = fs.readFileSync(file, 'utf8').trim();
|
|
287
|
+
if (!/^[0-9]+\.[0-9]+$/.test(protocol) || !protocol.split('.').every((part) => Number.isSafeInteger(Number(part))))
|
|
288
|
+
throw Error('Invalid runtime protocol metadata');
|
|
289
|
+
expected = `${executable} ${version} (${executable === 'puddler' ? 'runtime protocol' : 'protocol'} ${protocol})`;
|
|
290
|
+
}
|
|
291
|
+
const result = spawnSync(path.join(root, executable), ['--version'], { encoding: 'utf8', timeout: 5000, maxBuffer: 64 * 1024 });
|
|
292
|
+
if (result.error || result.status !== 0 || (expected !== undefined && result.stdout.trim() !== expected)) {
|
|
293
|
+
process.stderr.write(String(result.error || result.stderr || 'Version smoke test failed'));
|
|
294
|
+
process.exit(1);
|
|
295
|
+
}
|
|
296
|
+
NODE
|
|
297
|
+
}
|
|
298
|
+
DEST=""
|
|
142
299
|
SMOKE_LOG="$HOME_DIR/logs/install-smoke.log"
|
|
143
300
|
NEED_INSTALL=1
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
301
|
+
# Reuse a selected generation (both components can share it), or a legacy
|
|
302
|
+
# fixed-version tree. Never repair either in place: a runtime, helper, daemon or
|
|
303
|
+
# connector may still pin it.
|
|
304
|
+
if [ -n "$ACTIVATE" ]; then
|
|
305
|
+
DEST="$BIN_DIR/versions/$ACTIVATE"
|
|
306
|
+
[ -d "$DEST" ] && [ ! -L "$DEST" ] || die "staged generation is missing"
|
|
307
|
+
[ "$(head -c 130 "$DEST/VERSION")" = "$VERSION" ] || die "staged version mismatch"
|
|
308
|
+
NEED_INSTALL=0
|
|
309
|
+
else
|
|
310
|
+
for CANDIDATE in "$SELECTOR" "$OTHER_SELECTOR"; do
|
|
311
|
+
CURRENT=$(readlink "$BIN_DIR/$CANDIDATE" 2>/dev/null || true)
|
|
312
|
+
case "$CURRENT" in
|
|
313
|
+
versions/*)
|
|
314
|
+
NAME=${CURRENT#versions/}
|
|
315
|
+
case "$NAME" in
|
|
316
|
+
''|.|..|*/*) ;;
|
|
317
|
+
*)
|
|
318
|
+
if [ -f "$BIN_DIR/$CURRENT/VERSION" ] && [ "$(head -c 130 "$BIN_DIR/$CURRENT/VERSION")" = "$VERSION" ]; then
|
|
319
|
+
DEST="$BIN_DIR/$CURRENT"
|
|
320
|
+
fi ;;
|
|
321
|
+
esac ;;
|
|
322
|
+
esac
|
|
323
|
+
[ -z "$DEST" ] || break
|
|
324
|
+
done
|
|
325
|
+
if [ -z "$DEST" ]; then DEST="$BIN_DIR/versions/$VERSION"; fi
|
|
326
|
+
if [ -d "$DEST" ] && [ ! -L "$DEST" ] && [ "$FORCE" -eq 0 ] && [ -x "$DEST/$EXECUTABLE" ] \
|
|
327
|
+
&& { [ ! -e "$DEST/VERSION" ] || [ "$(head -c 130 "$DEST/VERSION")" = "$VERSION" ]; }; then
|
|
328
|
+
if smoke "$DEST" >/dev/null 2>"$SMOKE_LOG"; then
|
|
329
|
+
NEED_INSTALL=0
|
|
330
|
+
rm -f "$SMOKE_LOG"
|
|
331
|
+
say "version $VERSION already installed"
|
|
332
|
+
else
|
|
333
|
+
say "existing version $VERSION failed validation — staging a new generation"
|
|
334
|
+
fi
|
|
335
|
+
fi
|
|
336
|
+
if [ "$NEED_INSTALL" -eq 1 ]; then
|
|
337
|
+
# '~' cannot be mistaken for part of a legacy release/prerelease version.
|
|
338
|
+
STAGE=$(mktemp -d "$BIN_DIR/versions/$VERSION~XXXXXX")
|
|
339
|
+
DEST="$STAGE"
|
|
340
|
+
tar -xzf "$TARBALL" --strip-components=1 -C "$DEST" || die "extraction failed"
|
|
341
|
+
[ -f "$DEST/VERSION" ] && [ "$(head -c 130 "$DEST/VERSION")" = "$VERSION" ] \
|
|
342
|
+
|| die "archive version metadata mismatch"
|
|
343
|
+
if ! smoke "$DEST" >/dev/null 2>"$SMOKE_LOG"; then
|
|
344
|
+
die "installed tree fails its own --version smoke test (details: $SMOKE_LOG)"
|
|
345
|
+
fi
|
|
147
346
|
rm -f "$SMOKE_LOG"
|
|
148
|
-
say "version $VERSION already installed"
|
|
149
|
-
else
|
|
150
|
-
say "existing version $VERSION failed validation — reinstalling"
|
|
151
|
-
rm -rf "$DEST"
|
|
152
347
|
fi
|
|
153
348
|
fi
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
349
|
+
CREATE_RECEIPT="$STAGE_ONLY"
|
|
350
|
+
if [ -n "$STAGE" ] && [ -z "$ACTIVATE" ] &&
|
|
351
|
+
{ [ -e "$DEST/PROTOCOL" ] || [ -L "$DEST/PROTOCOL" ] ||
|
|
352
|
+
[ -e "$DEST/HOST_CAPABILITIES.json" ] || [ -L "$DEST/HOST_CAPABILITIES.json" ] ||
|
|
353
|
+
[ -e "$DEST/RUNTIME_PROTOCOL" ] || [ -L "$DEST/RUNTIME_PROTOCOL" ] ||
|
|
354
|
+
[ -e "$DEST/puddler" ] || [ -L "$DEST/puddler" ]; }; then
|
|
355
|
+
CREATE_RECEIPT=1
|
|
356
|
+
fi
|
|
357
|
+
if [ "$CREATE_RECEIPT" -eq 1 ] || [ -n "$ACTIVATE" ]; then
|
|
358
|
+
# The immutable receipt binds the complete tree, including native dependencies
|
|
359
|
+
# and symlink targets. Newly extracted ordinary installs use the same proof;
|
|
360
|
+
# reused/legacy trees are never retrospectively attested. Activation only verifies.
|
|
361
|
+
RECEIPT=$("$DEST/bin/node" --input-type=commonjs - "$DEST" "$COMPONENT" "$VERSION" "$TARBALL" "$CHECKSUM_VERIFIED" "$CREATE_RECEIPT" "$STAGE_DIGEST" <<'NODE'
|
|
362
|
+
const fs = require('node:fs'), path = require('node:path'), crypto = require('node:crypto');
|
|
363
|
+
const [root, component, version, archive, verified, createReceipt, expectedDigest] = process.argv.slice(2);
|
|
364
|
+
const marker = '.puddle-stage.json';
|
|
365
|
+
const digest = (value) => crypto.createHash('sha256').update(value).digest('hex');
|
|
366
|
+
const deadline = Date.now() + 30_000;
|
|
367
|
+
let files = 0, bytes = 0;
|
|
368
|
+
const check = () => {
|
|
369
|
+
if (files > 100_000 || bytes > 2 * 1024 ** 3 || Date.now() > deadline) throw Error('Stage verification limit exceeded');
|
|
370
|
+
};
|
|
371
|
+
async function contents(file, hash) {
|
|
372
|
+
const stat = await fs.promises.stat(file);
|
|
373
|
+
if (!stat.isFile() || bytes + stat.size > 2 * 1024 ** 3) throw Error('Stage verification limit exceeded');
|
|
374
|
+
for await (const chunk of fs.createReadStream(file)) {
|
|
375
|
+
bytes += chunk.length;
|
|
376
|
+
check();
|
|
377
|
+
hash.update(chunk);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async function tree(directory, relative, hash) {
|
|
381
|
+
const entries = (await fs.promises.readdir(directory)).sort();
|
|
382
|
+
for (const entry of entries) {
|
|
383
|
+
if (!relative && entry === marker) continue;
|
|
384
|
+
files++;
|
|
385
|
+
check();
|
|
386
|
+
const name = relative ? relative + '/' + entry : entry;
|
|
387
|
+
const file = path.join(directory, entry);
|
|
388
|
+
const stat = await fs.promises.lstat(file);
|
|
389
|
+
const type = stat.isDirectory() ? 'directory' : stat.isFile() ? 'file' : stat.isSymbolicLink() ? 'symlink' : null;
|
|
390
|
+
if (!type) throw Error('Unsupported staged file type');
|
|
391
|
+
hash.update(JSON.stringify([name, type, stat.mode & 0o777, stat.isFile() ? stat.size : null]));
|
|
392
|
+
if (stat.isDirectory()) await tree(file, name, hash);
|
|
393
|
+
else if (stat.isFile()) await contents(file, hash);
|
|
394
|
+
else hash.update(await fs.promises.readlink(file));
|
|
395
|
+
hash.update('\0');
|
|
396
|
+
const after = await fs.promises.lstat(file);
|
|
397
|
+
if (stat.ino !== after.ino || stat.size !== after.size || stat.mtimeMs !== after.mtimeMs || stat.ctimeMs !== after.ctimeMs)
|
|
398
|
+
throw Error('Staged tree changed during verification');
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async function main() {
|
|
402
|
+
const before = fs.lstatSync(root);
|
|
403
|
+
const hash = crypto.createHash('sha256');
|
|
404
|
+
hash.update(JSON.stringify(['', 'directory', before.mode & 0o777, null]));
|
|
405
|
+
await tree(root, '', hash);
|
|
406
|
+
const after = fs.lstatSync(root);
|
|
407
|
+
if (before.ino !== after.ino || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs)
|
|
408
|
+
throw Error('Staged tree changed during verification');
|
|
409
|
+
const treeDigest = hash.digest('hex');
|
|
410
|
+
const file = path.join(root, marker);
|
|
411
|
+
if (createReceipt !== '1') {
|
|
412
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
413
|
+
let body;
|
|
414
|
+
try {
|
|
415
|
+
const stat = fs.fstatSync(fd);
|
|
416
|
+
if (!stat.isFile() || stat.size > 4096 || (stat.mode & 0o077) !== 0 || stat.uid !== process.getuid()) throw Error('Invalid stage receipt');
|
|
417
|
+
const buffer = Buffer.alloc(4097);
|
|
418
|
+
const size = fs.readSync(fd, buffer, 0, buffer.length, 0);
|
|
419
|
+
if (size > 4096) throw Error('Stage receipt exceeds its limit');
|
|
420
|
+
body = buffer.subarray(0, size);
|
|
421
|
+
} finally { fs.closeSync(fd); }
|
|
422
|
+
if (digest(body) !== expectedDigest) throw Error('Stage receipt digest mismatch');
|
|
423
|
+
const record = JSON.parse(body.toString('utf8'));
|
|
424
|
+
if (record.format !== 1 || record.generation !== path.basename(root) || record.component !== component || record.version !== version || record.tree_sha256 !== treeDigest)
|
|
425
|
+
throw Error('Staged release no longer matches its receipt');
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const protocolFile = path.join(root, component === 'runtime' ? 'RUNTIME_PROTOCOL' : 'PROTOCOL');
|
|
429
|
+
const stat = fs.lstatSync(protocolFile);
|
|
430
|
+
if (!stat.isFile() || stat.size > 33) throw Error('Invalid stage protocol metadata');
|
|
431
|
+
const match = /^(\d+)\.(\d+)$/.exec(fs.readFileSync(protocolFile, 'utf8').trim());
|
|
432
|
+
if (!match || !match.slice(1).every((part) => Number.isSafeInteger(Number(part)))) throw Error('Invalid stage protocol metadata');
|
|
433
|
+
const archiveHash = crypto.createHash('sha256');
|
|
434
|
+
await contents(archive, archiveHash);
|
|
435
|
+
const record = {
|
|
436
|
+
format: 1, component, generation: path.basename(root), version,
|
|
437
|
+
protocol: { major: Number(match[1]), minor: Number(match[2]) },
|
|
438
|
+
archive_sha256: archiveHash.digest('hex'), tree_sha256: treeDigest,
|
|
439
|
+
checksum_verified: verified === '1',
|
|
440
|
+
};
|
|
441
|
+
const body = JSON.stringify(record) + '\n';
|
|
442
|
+
const fd = fs.openSync(file, 'wx', 0o600);
|
|
443
|
+
try { fs.writeFileSync(fd, body); fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
|
|
444
|
+
for (const directory of [root, path.dirname(root)]) {
|
|
445
|
+
const fd = fs.openSync(directory, 'r');
|
|
446
|
+
try { fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
|
|
447
|
+
}
|
|
448
|
+
process.stdout.write(JSON.stringify({ record, digest: digest(body) }));
|
|
449
|
+
}
|
|
450
|
+
main().catch((error) => { console.error(error.message); process.exitCode = 1; });
|
|
451
|
+
NODE
|
|
452
|
+
) || die "staged release verification failed"
|
|
453
|
+
if [ "$CREATE_RECEIPT" -eq 1 ]; then
|
|
454
|
+
# Once proof is durable, retain the immutable generation even if later
|
|
455
|
+
# publication fails. Reference-aware collection can reclaim it after retention.
|
|
456
|
+
STAGE=""
|
|
457
|
+
fi
|
|
458
|
+
if [ "$STAGE_ONLY" -eq 1 ]; then
|
|
459
|
+
prune_cache
|
|
460
|
+
printf 'PUDDLE_HOST_STAGE %s\n' "$RECEIPT"
|
|
461
|
+
exit 0
|
|
462
|
+
fi
|
|
463
|
+
if [ -n "$ACTIVATE" ] && ! smoke "$DEST" >/dev/null 2>"$SMOKE_LOG"; then
|
|
464
|
+
die "staged tree fails its own --version smoke test (details: $SMOKE_LOG)"
|
|
465
|
+
fi
|
|
466
|
+
rm -f "$SMOKE_LOG"
|
|
467
|
+
fi
|
|
468
|
+
# Fresh installs and legacy upgrades need the mandatory runtime default before
|
|
469
|
+
# starting the daemon. Existing pins remain independent; staged transactions
|
|
470
|
+
# select only their explicitly reviewed components.
|
|
471
|
+
INITIAL_RUNTIME=0
|
|
472
|
+
if [ "$COMPONENT" = daemon ] && [ -z "$ACTIVATE" ] &&
|
|
473
|
+
[ ! -e "$BIN_DIR/runtime-current" ] && [ ! -L "$BIN_DIR/runtime-current" ] &&
|
|
474
|
+
{ [ -e "$DEST/HOST_CAPABILITIES.json" ] || [ -L "$DEST/HOST_CAPABILITIES.json" ] ||
|
|
475
|
+
[ -e "$DEST/RUNTIME_PROTOCOL" ] || [ -L "$DEST/RUNTIME_PROTOCOL" ] ||
|
|
476
|
+
[ -e "$DEST/puddler" ] || [ -L "$DEST/puddler" ]; }; then
|
|
477
|
+
if ! smoke "$DEST" puddler >/dev/null 2>"$SMOKE_LOG"; then
|
|
478
|
+
die "initial runtime fails its own --version smoke test (details: $SMOKE_LOG)"
|
|
161
479
|
fi
|
|
162
480
|
rm -f "$SMOKE_LOG"
|
|
481
|
+
INITIAL_RUNTIME=1
|
|
163
482
|
fi
|
|
164
|
-
|
|
483
|
+
# Use the archive's Node as the standalone CLI installer does: rename replaces
|
|
484
|
+
# the symlink itself atomically on both platforms, without following it as mv
|
|
485
|
+
# can. Publish the wrapper first; an unsuccessful activation retains current.
|
|
486
|
+
"$DEST/bin/node" --input-type=commonjs - "$BIN_DIR" "$DEST" "$SELECTOR" "$EXECUTABLE" "$INITIAL_RUNTIME" <<'NODE'
|
|
487
|
+
const fs = require('node:fs'), path = require('node:path');
|
|
488
|
+
const [root, destination, selector, executable, initialRuntime] = process.argv.slice(2);
|
|
489
|
+
const syncDirectory = () => {
|
|
490
|
+
const directory = fs.openSync(root, fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW);
|
|
491
|
+
try { fs.fsyncSync(directory); } finally { fs.closeSync(directory); }
|
|
492
|
+
};
|
|
493
|
+
function publish(selector, executable, initial = false) {
|
|
494
|
+
const current = path.join(root, selector);
|
|
495
|
+
try {
|
|
496
|
+
if (initial) { fs.lstatSync(current); throw Error('Initial runtime selection changed'); }
|
|
497
|
+
if (!fs.lstatSync(current).isSymbolicLink()) throw Error(selector + ' must be a symlink');
|
|
498
|
+
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
499
|
+
const launcher = path.join(root, executable);
|
|
500
|
+
const quote = (s) => "'" + s.replaceAll("'", "'\\''") + "'";
|
|
501
|
+
// The archive launcher resolves its own directory; retain an exec wrapper.
|
|
502
|
+
const wrapper = '#!/bin/sh\nexec ' + quote(path.join(current, executable)) + ' "$@"\n';
|
|
503
|
+
const suffix = '.new-' + process.pid;
|
|
504
|
+
try {
|
|
505
|
+
const fd = fs.openSync(launcher + suffix, 'wx', 0o755);
|
|
506
|
+
try { fs.writeFileSync(fd, wrapper); fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
|
|
507
|
+
fs.symlinkSync(path.relative(root, destination), current + suffix);
|
|
508
|
+
fs.renameSync(launcher + suffix, launcher);
|
|
509
|
+
fs.renameSync(current + suffix, current);
|
|
510
|
+
syncDirectory();
|
|
511
|
+
} finally {
|
|
512
|
+
fs.rmSync(launcher + suffix, { force: true });
|
|
513
|
+
fs.rmSync(current + suffix, { force: true });
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
// Publish and sync this first: an interrupted bootstrap must not start the new
|
|
517
|
+
// daemon with no runtime default. Cleanup retains either selected generation.
|
|
518
|
+
if (initialRuntime === '1') publish('runtime-current', 'puddler', true);
|
|
519
|
+
publish(selector, executable);
|
|
520
|
+
NODE
|
|
521
|
+
STAGE="" # Published generations are retained until reference-aware collection.
|
|
522
|
+
|
|
523
|
+
prune_cache
|
|
165
524
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
525
|
+
if [ "$SELECT_ONLY" -eq 1 ]; then
|
|
526
|
+
say "selected $COMPONENT $VERSION (supervisor configuration and services unchanged)"
|
|
527
|
+
exit 0
|
|
528
|
+
fi
|
|
170
529
|
|
|
171
|
-
|
|
172
|
-
|
|
530
|
+
if [ "$COMPONENT" = runtime ]; then
|
|
531
|
+
say "selected runtime $VERSION for new launches (existing services unchanged)"
|
|
532
|
+
exit 0
|
|
533
|
+
fi
|
|
173
534
|
|
|
174
535
|
if [ "$SUPERVISOR" -eq 0 ]; then
|
|
175
536
|
printf '%s\n' none > "$HOME_DIR/supervisor"
|
|
@@ -246,7 +607,7 @@ else
|
|
|
246
607
|
kill "$(cat "$HOME_DIR/puddled.pid")" || true
|
|
247
608
|
sleep 1
|
|
248
609
|
fi
|
|
249
|
-
nohup "$BIN_DIR/current/puddled" >> "$HOME_DIR/logs/puddled.out.log" 2>&1 &
|
|
610
|
+
nohup "$BIN_DIR/current/puddled" 9>&- >> "$HOME_DIR/logs/puddled.out.log" 2>&1 &
|
|
250
611
|
printf '%s\n' "$!" > "$HOME_DIR/puddled.pid"
|
|
251
612
|
fi
|
|
252
613
|
say "warning: no systemd or launchd found — using nohup; puddled will NOT auto-start after a reboot"
|