Skip to content

Commit ee6abbe

Browse files
committed
fix(installer): accept legacy release archive layout
Signed-off-by: cyphercodes <cyphercodes@users.noreply.github.com>
1 parent b377c62 commit ee6abbe

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

‎install.sh‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,55 @@ if [ "$EXPECTED" != "$ACTUAL" ]; then
220220
fi
221221
echo "Checksum verified."
222222

223+
# Validate the complete archive namespace before extraction. Current and legacy
224+
# release assets use the same four-member root layout; anything outside that
225+
# closed set is a release-integrity failure, not a sidecar to ignore.
226+
if [ "$OS" = "windows" ]; then
227+
ARCHIVE_BINARY="codebase-memory-mcp.exe"
228+
ARCHIVE_INSTALLER="install.ps1"
229+
else
230+
ARCHIVE_BINARY="codebase-memory-mcp"
231+
ARCHIVE_INSTALLER="install.sh"
232+
fi
233+
ARCHIVE_MEMBERS_FILE="$DLDIR/archive-members.txt"
234+
if [ "$EXT" = "zip" ]; then
235+
if ! unzip -Z1 "$DLDIR/$ARCHIVE" > "$ARCHIVE_MEMBERS_FILE"; then
236+
echo "error: could not enumerate release archive" >&2
237+
exit 1
238+
fi
239+
else
240+
if ! tar -tzf "$DLDIR/$ARCHIVE" > "$ARCHIVE_MEMBERS_FILE"; then
241+
echo "error: could not enumerate release archive" >&2
242+
exit 1
243+
fi
244+
fi
245+
246+
BINARY_MEMBERS=0
247+
LICENSE_MEMBERS=0
248+
INSTALLER_MEMBERS=0
249+
NOTICE_MEMBERS=0
250+
ARCHIVE_MEMBER_COUNT=0
251+
while IFS= read -r member || [ -n "$member" ]; do
252+
ARCHIVE_MEMBER_COUNT=$((ARCHIVE_MEMBER_COUNT + 1))
253+
case "$member" in
254+
"$ARCHIVE_BINARY") BINARY_MEMBERS=$((BINARY_MEMBERS + 1)) ;;
255+
LICENSE) LICENSE_MEMBERS=$((LICENSE_MEMBERS + 1)) ;;
256+
"$ARCHIVE_INSTALLER") INSTALLER_MEMBERS=$((INSTALLER_MEMBERS + 1)) ;;
257+
THIRD_PARTY_NOTICES.md) NOTICE_MEMBERS=$((NOTICE_MEMBERS + 1)) ;;
258+
*)
259+
echo "error: release archive contains unexpected member: $member" >&2
260+
exit 1
261+
;;
262+
esac
263+
done < "$ARCHIVE_MEMBERS_FILE"
264+
265+
if [ "$BINARY_MEMBERS" -ne 1 ] || [ "$LICENSE_MEMBERS" -ne 1 ] ||
266+
[ "$INSTALLER_MEMBERS" -ne 1 ] || [ "$NOTICE_MEMBERS" -ne 1 ] ||
267+
[ "$ARCHIVE_MEMBER_COUNT" -ne 4 ]; then
268+
echo "error: release archive does not match the exact member set" >&2
269+
exit 1
270+
fi
271+
223272
# Extract
224273
echo "Extracting..."
225274
if [ "$EXT" = "zip" ]; then
@@ -228,8 +277,16 @@ else
228277
tar --no-same-owner -xzf "$DLDIR/$ARCHIVE" -C "$DLDIR"
229278
fi
230279

231-
DLBIN="$DLDIR/codebase-memory-mcp"
232-
if [ ! -f "$DLBIN" ]; then
280+
for extracted_member in "$ARCHIVE_BINARY" LICENSE "$ARCHIVE_INSTALLER" \
281+
THIRD_PARTY_NOTICES.md; do
282+
if [ ! -f "$DLDIR/$extracted_member" ] || [ -L "$DLDIR/$extracted_member" ]; then
283+
echo "error: release member is not a regular file: $extracted_member" >&2
284+
exit 1
285+
fi
286+
done
287+
288+
DLBIN="$DLDIR/$ARCHIVE_BINARY"
289+
if [ ! -f "$DLBIN" ] || [ -L "$DLBIN" ]; then
233290
echo "error: binary not found after extraction" >&2
234291
exit 1
235292
fi

‎tests/test_smoke_fixture_contract.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ require(
142142
'tar --no-same-owner -xzf "$DLDIR/$ARCHIVE" -C "$DLDIR"' in install_script,
143143
"install.sh must not preserve release-builder ownership when extracting tar archives",
144144
)
145+
require(
146+
all(
147+
needle in install_script
148+
for needle in (
149+
"ARCHIVE_MEMBER_COUNT",
150+
"release archive contains unexpected member",
151+
"release archive does not match the exact member set",
152+
'for extracted_member in "$ARCHIVE_BINARY" LICENSE "$ARCHIVE_INSTALLER"',
153+
)
154+
)
155+
and "cbm-integrations.json" not in install_script,
156+
"install.sh must validate and accept the exact four-member release archive layout",
157+
)
145158
# One composition ships, so there is one archive name and no variant alias.
146159
require(
147160
"codebase-memory-mcp-${OS}-${ARCH}.tar.gz" in smoke_local

0 commit comments

Comments
 (0)