-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·159 lines (139 loc) · 4.61 KB
/
start.sh
File metadata and controls
executable file
·159 lines (139 loc) · 4.61 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# Chrome Monitor - Desktop Application Launcher
# Auto-installs Node.js and Chrome if needed
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="$SCRIPT_DIR/app"
echo ""
echo "╔════════════════════════════════════════╗"
echo "║ Chrome Monitor - Starting ║"
echo "╚════════════════════════════════════════╝"
echo ""
# Check if running as root/sudo
check_sudo() {
if [ "$EUID" -ne 0 ]; then
echo "[!] This script needs admin rights to install dependencies."
echo "[!] Please run with: sudo ./start.sh"
echo ""
exit 1
fi
}
# Install Node.js
install_nodejs() {
echo "[*] Installing Node.js 20..."
if command -v apt-get &> /dev/null; then
# Ubuntu/Debian
apt-get update
apt-get install -y ca-certificates curl gnupg
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get update
apt-get install -y nodejs
elif command -v dnf &> /dev/null; then
# Fedora/RHEL
dnf install -y nodejs
elif command -v yum &> /dev/null; then
# CentOS
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
yum install -y nodejs
elif command -v pacman &> /dev/null; then
# Arch
pacman -Sy --noconfirm nodejs npm
else
echo "[!] Could not detect package manager. Please install Node.js manually."
exit 1
fi
}
# Install Chrome
install_chrome() {
echo "[*] Installing Google Chrome..."
if command -v apt-get &> /dev/null; then
# Ubuntu/Debian
wget -q -O /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt-get install -y /tmp/chrome.deb || apt-get install -f -y
rm -f /tmp/chrome.deb
elif command -v dnf &> /dev/null; then
# Fedora
dnf install -y https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
elif command -v yum &> /dev/null; then
# CentOS
wget -q -O /tmp/chrome.rpm https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install -y /tmp/chrome.rpm
rm -f /tmp/chrome.rpm
elif command -v pacman &> /dev/null; then
# Arch - use chromium
pacman -Sy --noconfirm chromium
else
echo "[!] Could not install Chrome. Please install manually."
exit 1
fi
}
# Check Node.js
if ! command -v node &> /dev/null; then
check_sudo
install_nodejs
fi
if command -v node &> /dev/null; then
NODE_VERSION=$(node --version)
echo "[OK] Node.js $NODE_VERSION"
else
echo "[!] Node.js installation failed"
exit 1
fi
# Check Chrome
CHROME_OK=false
for cmd in google-chrome google-chrome-stable chromium chromium-browser; do
if command -v $cmd &> /dev/null; then
CHROME_OK=true
CHROME_CMD=$cmd
break
fi
done
if [ "$CHROME_OK" = false ]; then
check_sudo
install_chrome
# Check again
for cmd in google-chrome google-chrome-stable chromium chromium-browser; do
if command -v $cmd &> /dev/null; then
CHROME_OK=true
CHROME_CMD=$cmd
break
fi
done
fi
if [ "$CHROME_OK" = true ]; then
echo "[OK] Chrome ($CHROME_CMD)"
else
echo "[!] Chrome installation failed"
exit 1
fi
# Install app dependencies
echo "[*] Installing app dependencies..."
cd "$APP_DIR"
# Run npm install as regular user if we're root
if [ "$EUID" -eq 0 ] && [ -n "$SUDO_USER" ]; then
sudo -u "$SUDO_USER" npm install
else
npm install
fi
# Fix Electron sandbox permissions (required on Linux)
SANDBOX_PATH="$APP_DIR/node_modules/electron/dist/chrome-sandbox"
if [ -f "$SANDBOX_PATH" ]; then
echo "[*] Fixing Electron sandbox permissions..."
chown root:root "$SANDBOX_PATH" 2>/dev/null || true
chmod 4755 "$SANDBOX_PATH" 2>/dev/null || true
fi
echo "[OK] Dependencies installed"
echo ""
echo "Starting Chrome Monitor..."
echo ""
# Run the app as regular user if we're root
if [ "$EUID" -eq 0 ] && [ -n "$SUDO_USER" ]; then
# Get the user's home and display
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
# Run electron as the regular user
sudo -u "$SUDO_USER" npm start
else
npm start
fi