Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·134 lines (119 loc) · 6.08 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·134 lines (119 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────────────
# build.sh — Build Chrome Isolation Manager as a standalone AppImage + .deb
#
# What it does:
# 1. Checks / installs build deps (PyInstaller, electron-builder, fuse2)
# 2. Bundles the Python bridge into a single self-contained binary via PyInstaller
# 3. Builds the Electron app as:
# dist/Chrome-Isolation-<version>.AppImage (runs on any Linux)
# dist/Chrome-Isolation-<version>.deb (Debian/Ubuntu)
#
# Requirements (on the build machine):
# - Node.js ≥ 18, npm
# - Python ≥ 3.10, pip
# - fuse2 / libfuse2 (for AppImage)
#
# Usage:
# bash build.sh [--appimage-only] [--deb-only] [--skip-bridge]
# ──────────────────────────────────────────────────────────────────────────────
set -euo pipefail
SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SRC"
# ── Colours ───────────────────────────────────────────────────────────────────
info() { printf '\033[1;34m→ %s\033[0m\n' "$*"; }
success() { printf '\033[1;32m✓ %s\033[0m\n' "$*"; }
warn() { printf '\033[1;33m! %s\033[0m\n' "$*"; }
die() { printf '\033[1;31m✗ %s\033[0m\n' "$*" >&2; exit 1; }
# Install a pip package, retrying with --break-system-packages on PEP 668
# distros (Arch, Fedora 39+, Ubuntu 23.04+) where pip refuses to touch the
# system environment.
pip_install() {
if pip install --quiet "$@"; then
return 0
fi
info "pip install failed (PEP 668 externally-managed environment?) — retrying with --break-system-packages..."
pip install --quiet --break-system-packages "$@"
}
# ── Args ──────────────────────────────────────────────────────────────────────
BUILD_APPIMAGE=1
BUILD_DEB=1
BUILD_RPM=1
SKIP_BRIDGE=0
for arg in "$@"; do
case "$arg" in
--appimage-only) BUILD_DEB=0; BUILD_RPM=0 ;;
--deb-only) BUILD_APPIMAGE=0; BUILD_RPM=0 ;;
--rpm-only) BUILD_APPIMAGE=0; BUILD_DEB=0 ;;
--skip-bridge) SKIP_BRIDGE=1 ;;
esac
done
# ── Step 1: Verify Node.js / npm ──────────────────────────────────────────────
info "Checking Node.js..."
command -v node >/dev/null 2>&1 || die "Node.js not found. Run: bash setup.sh"
command -v npm >/dev/null 2>&1 || die "npm not found. Run: bash setup.sh"
NODE_VER=$(node --version)
info "Node.js $NODE_VER"
# ── Step 2: Install npm deps (including electron-builder) ─────────────────────
info "Installing npm dependencies..."
npm install --include=dev
success "npm deps installed."
# ── Step 3: Bundle Python bridge with PyInstaller ─────────────────────────────
if [[ "$SKIP_BRIDGE" -eq 0 ]]; then
info "Checking Python / pip..."
command -v python3 >/dev/null 2>&1 || die "python3 not found. Run: bash setup.sh"
# Install PyInstaller + docker client if not present
if ! python3 -c "import PyInstaller" 2>/dev/null; then
info "Installing PyInstaller..."
pip_install pyinstaller
fi
if ! python3 -c "import docker" 2>/dev/null; then
info "Installing python-docker..."
pip_install docker
fi
info "Bundling Python bridge (PyInstaller)..."
python3 -m PyInstaller \
--clean \
--distpath dist/bridge-bin \
--workpath /tmp/ci-pyinstaller \
bridge.spec
[[ -f dist/bridge-bin/bridge ]] || die "PyInstaller failed — dist/bridge-bin/bridge not found."
chmod +x dist/bridge-bin/bridge
success "Bridge binary: dist/bridge-bin/bridge ($(du -sh dist/bridge-bin/bridge | cut -f1))"
else
warn "--skip-bridge: skipping PyInstaller step"
if [[ ! -f dist/bridge-bin/bridge ]]; then
die "dist/bridge-bin/bridge is missing and --skip-bridge was set. Cannot continue."
fi
fi
# ── Step 4: Check fuse2 (required to mount AppImage at build time) ────────────
if [[ "$BUILD_APPIMAGE" -eq 1 ]]; then
if ! ldconfig -p 2>/dev/null | grep -q libfuse || ! command -v fusermount >/dev/null 2>&1; then
warn "fuse2/libfuse2 may not be installed."
warn "If the AppImage build fails, install it:"
warn " Arch: sudo pacman -S fuse2"
warn " Debian: sudo apt-get install fuse libfuse2"
warn " RHEL: sudo dnf install fuse fuse-libs"
warn " Or set: APPIMAGE_EXTRACT_AND_RUN=1 (already set below)"
fi
# Suppress FUSE requirement for building in environments without it
export APPIMAGE_EXTRACT_AND_RUN=1
fi
# ── Step 5: Build AppImage / .deb ─────────────────────────────────────────────
BUILD_TARGETS=""
[[ "$BUILD_APPIMAGE" -eq 1 ]] && BUILD_TARGETS="$BUILD_TARGETS --linux AppImage"
[[ "$BUILD_DEB" -eq 1 ]] && BUILD_TARGETS="$BUILD_TARGETS --linux deb"
[[ "$BUILD_RPM" -eq 1 ]] && BUILD_TARGETS="$BUILD_TARGETS --linux rpm"
info "Building Electron packages: $BUILD_TARGETS"
npx electron-builder $BUILD_TARGETS
# ── Step 6: Report ────────────────────────────────────────────────────────────
echo ""
success "Build complete! Output:"
find dist/ -maxdepth 1 \( -name "*.AppImage" -o -name "*.deb" -o -name "*.rpm" \) -print | while read -r f; do
printf ' %-55s %s\n' "$f" "$(du -sh "$f" | cut -f1)"
done
echo ""
info "To run the AppImage:"
echo " chmod +x dist/*.AppImage && ./dist/*.AppImage"
info "To install the .deb:"
echo " sudo dpkg -i dist/*.deb && sudo apt-get install -f"