Skip to content

Commit 9f66c28

Browse files
committed
chore: add pack.sh script for regenerating extension.crx
1 parent 077b62c commit 9f66c28

File tree

1 file changed

+77
-0
lines changed
  • server/e2e/test-extension-enterprise

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
# Pack the test extension into a .crx file
3+
# Usage: ./pack.sh
4+
#
5+
# Requires: google-chrome (or chromium), openssl, python3
6+
#
7+
# This script:
8+
# 1. Packs the extension using Chrome's built-in packer
9+
# 2. Extracts and displays the extension ID from the private key
10+
#
11+
# The extension ID is derived from the public key, so as long as you use
12+
# the same private_key.pem, you'll get the same extension ID.
13+
14+
set -euo pipefail
15+
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
cd "$SCRIPT_DIR"
18+
19+
# Find Chrome binary
20+
CHROME=""
21+
for bin in google-chrome chromium chromium-browser; do
22+
if command -v "$bin" &> /dev/null; then
23+
CHROME="$bin"
24+
break
25+
fi
26+
done
27+
28+
if [ -z "$CHROME" ]; then
29+
echo "Error: Chrome/Chromium not found"
30+
exit 1
31+
fi
32+
33+
# Check for private key
34+
if [ ! -f "private_key.pem" ]; then
35+
echo "Generating new private key..."
36+
openssl genrsa -out private_key.pem 2048
37+
fi
38+
39+
# Chrome won't pack if the key is inside the extension directory
40+
mv private_key.pem /tmp/ext_key.pem
41+
trap 'mv /tmp/ext_key.pem private_key.pem 2>/dev/null || true' EXIT
42+
43+
# Pack the extension (Chrome creates .crx in parent directory)
44+
echo "Packing extension..."
45+
"$CHROME" --pack-extension="$SCRIPT_DIR" --pack-extension-key=/tmp/ext_key.pem --no-sandbox 2>&1 || true
46+
47+
# Move the .crx file into place
48+
PARENT_DIR="$(dirname "$SCRIPT_DIR")"
49+
CRX_NAME="$(basename "$SCRIPT_DIR").crx"
50+
if [ -f "$PARENT_DIR/$CRX_NAME" ]; then
51+
mv "$PARENT_DIR/$CRX_NAME" extension.crx
52+
echo "Created extension.crx"
53+
else
54+
echo "Error: Chrome did not create .crx file"
55+
exit 1
56+
fi
57+
58+
# Restore key before computing ID
59+
mv /tmp/ext_key.pem private_key.pem
60+
trap - EXIT
61+
62+
# Extract extension ID from the public key
63+
EXT_ID=$(python3 -c "
64+
import hashlib
65+
import subprocess
66+
result = subprocess.run(
67+
['openssl', 'rsa', '-in', 'private_key.pem', '-pubout', '-outform', 'DER'],
68+
stdout=subprocess.PIPE, stderr=subprocess.PIPE
69+
)
70+
sha = hashlib.sha256(result.stdout).digest()
71+
print(''.join(chr(ord('a') + (b >> 4)) + chr(ord('a') + (b & 0xf)) for b in sha[:16]))
72+
")
73+
74+
echo "Extension ID: $EXT_ID"
75+
echo ""
76+
echo "Make sure update.xml contains this appid:"
77+
echo " <app appid='$EXT_ID'>"

0 commit comments

Comments
 (0)