Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·145 lines (127 loc) · 7.14 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·145 lines (127 loc) · 7.14 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
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
# install.sh — installs Chrome Isolation Manager as a proper GNOME desktop app.
# Run as the target user (no sudo needed; installs to ~/.local/).
set -euo pipefail
# ── Config ────────────────────────────────────────────────────────────────────
APP_NAME="chrome-isolation"
APP_DISPLAY_NAME="Chrome Isolation Manager"
INSTALL_DIR="$HOME/.local/share/chrome-isolation-manager"
BIN_DIR="$HOME/.local/bin"
DESKTOP_DIR="$HOME/.local/share/applications"
ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps"
AUTOSTART_DIR="$HOME/.config/autostart"
OLD_SERVICE="chrome-manager.service"
# Source directory (where this script lives)
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ── Helpers ───────────────────────────────────────────────────────────────────
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; }
# ── Preflight ─────────────────────────────────────────────────────────────────
[[ -f "$SRC_DIR/package.json" ]] || die "Run this script from the project root."
command -v node >/dev/null 2>&1 || die "node not found. Install Node.js first."
command -v npm >/dev/null 2>&1 || die "npm not found."
command -v docker >/dev/null 2>&1 || die "Docker not found. Install Docker first."
[[ -d "$SRC_DIR/node_modules" ]] || { info "Installing npm deps..."; npm --prefix "$SRC_DIR" install; }
# ── Stop old Flask service (S3: remove localhost attack surface) ───────────────
if systemctl --user is-active --quiet "$OLD_SERVICE" 2>/dev/null; then
info "Stopping old chrome-manager.service..."
systemctl --user disable --now "$OLD_SERVICE" 2>/dev/null || true
success "Old service stopped and disabled."
elif systemctl is-active --quiet "$OLD_SERVICE" 2>/dev/null; then
warn "System-wide $OLD_SERVICE found. Stopping it requires sudo — skipping."
fi
# ── Create directories ────────────────────────────────────────────────────────
mkdir -p "$INSTALL_DIR" "$BIN_DIR" "$DESKTOP_DIR" "$ICON_DIR"
# ── Copy application files ─────────────────────────────────────────────────────
info "Copying application to $INSTALL_DIR..."
rsync -a --delete \
--exclude '.git' \
--exclude 'node_modules/.cache' \
--exclude '*.pyc' \
--exclude '__pycache__' \
"$SRC_DIR/electron/" "$INSTALL_DIR/electron/"
rsync -a --delete \
"$SRC_DIR/backend/" "$INSTALL_DIR/backend/"
rsync -a --delete \
"$SRC_DIR/scripts/" "$INSTALL_DIR/scripts/"
rsync -a --delete \
"$SRC_DIR/assets/" "$INSTALL_DIR/assets/"
cp "$SRC_DIR/Dockerfile" "$INSTALL_DIR/Dockerfile"
cp "$SRC_DIR/.dockerignore" "$INSTALL_DIR/.dockerignore"
cp "$SRC_DIR/package.json" "$INSTALL_DIR/package.json"
# Copy node_modules (symlink or rsync depending on available space)
if [[ ! -d "$INSTALL_DIR/node_modules" ]]; then
info "Copying node_modules..."
rsync -a "$SRC_DIR/node_modules/" "$INSTALL_DIR/node_modules/"
fi
success "Files copied."
# ── Build Docker image ────────────────────────────────────────────────────────
info "Building isolated-chrome Docker image (this may take a few minutes)..."
docker build \
--build-arg "USER_ID=$(id -u)" \
--build-arg "GROUP_ID=$(id -g)" \
-t isolated-chrome \
"$INSTALL_DIR"
success "Docker image built."
# ── Launcher script ────────────────────────────────────────────────────────────
info "Creating launcher at $BIN_DIR/$APP_NAME..."
# Sanitize electron path.txt — npm writes a trailing newline that breaks the
# .bin/electron wrapper (Node reads "electron\n", spawns with ENOENT).
PATH_TXT="$INSTALL_DIR/node_modules/electron/path.txt"
if [[ -f "$PATH_TXT" ]]; then
printf '%s' "$(cat "$PATH_TXT")" > "$PATH_TXT"
success "Sanitized $PATH_TXT (stripped trailing newline)."
fi
cat > "$BIN_DIR/$APP_NAME" <<LAUNCHER
#!/usr/bin/env bash
# Chrome Isolation Manager launcher
exec "$INSTALL_DIR/node_modules/electron/dist/electron" "$INSTALL_DIR" "\$@"
LAUNCHER
chmod +x "$BIN_DIR/$APP_NAME"
success "Launcher created."
# ── Icon ──────────────────────────────────────────────────────────────────────
cp "$SRC_DIR/assets/icons/icon.png" "$ICON_DIR/$APP_NAME.png"
# backend/desktop_manager.py expects the icon at APP_DATA_DIR/icon.png
cp "$SRC_DIR/assets/icons/icon.png" "$INSTALL_DIR/icon.png"
success "Icon installed."
# ── .desktop entry ────────────────────────────────────────────────────────────
info "Creating .desktop entry..."
cat > "$DESKTOP_DIR/$APP_NAME.desktop" <<DESKTOP
[Desktop Entry]
Type=Application
Name=$APP_DISPLAY_NAME
GenericName=Browser Profile Manager
Comment=Manage isolated Chrome browser profiles in Docker containers
Exec=$BIN_DIR/$APP_NAME %u
Icon=$APP_NAME
Terminal=false
Categories=Network;WebBrowser;Utility;
Keywords=chrome;browser;privacy;isolation;docker;
StartupNotify=true
StartupWMClass=chrome-isolation
DESKTOP
chmod 644 "$DESKTOP_DIR/$APP_NAME.desktop"
success ".desktop entry created."
# ── Update icon / desktop caches ──────────────────────────────────────────────
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache -q -t -f "$HOME/.local/share/icons/hicolor" 2>/dev/null || true
fi
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database "$DESKTOP_DIR" 2>/dev/null || true
fi
if command -v xdg-desktop-menu >/dev/null 2>&1; then
xdg-desktop-menu forceupdate 2>/dev/null || true
fi
success "Desktop caches updated."
# ── Make sure ~/.local/bin is on PATH ─────────────────────────────────────────
if ! echo "$PATH" | grep -q "$BIN_DIR"; then
warn "'$BIN_DIR' is not in your PATH."
warn "Add this to your ~/.bashrc or ~/.profile:"
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
echo ""
success "Installation complete!"
printf ' Run with: %s\n' "$APP_NAME"
printf ' Or launch from GNOME application grid.\n\n'