-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·227 lines (193 loc) · 8.64 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·227 lines (193 loc) · 8.64 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env bash
# =============================================================================
# setup.sh — GrokAuto Installation Script
#
# Usage: bash setup.sh
#
# This script will:
# 1. Create the GrokAuto configuration directory
# 2. Generate a default config.json template
# 3. Check and optionally install dependencies
# 4. Print next-step instructions
# =============================================================================
set -euo pipefail
# ── Colours ─────────────────────────────────────────────────────────────────
G="\033[92m"; Y="\033[93m"; R="\033[91m"; C="\033[96m"; B="\033[1m"; X="\033[0m"
# ── Paths ───────────────────────────────────────────────────────────────────
GROK_DIR="${HOME}/.config/grokauto"
CONFIG_FILE="${GROK_DIR}/config.json"
OUTPUT_DIR="${HOME}/grokauto_outputs"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ── Helpers ─────────────────────────────────────────────────────────────────
info() { echo -e "${C}▶${X} $*"; }
ok() { echo -e "${G}✓${X} $*"; }
warn() { echo -e "${Y}◆${X} $*"; }
err() { echo -e "${R}✗${X} $*"; }
banner() {
echo -e "\n${B}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${X}"
echo -e " ${C}$*${X}"
echo -e "${B}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${X}\n"
}
# ── 1. Welcome ─────────────────────────────────────────────────────────────
banner "GrokAuto Setup"
echo -e " This script will set up the Grok.com Automation Capability.\n"
# ── 2. Create directories ──────────────────────────────────────────────────
info "Creating GrokAuto directories..."
mkdir -p "${GROK_DIR}"
mkdir -p "${OUTPUT_DIR}"
chmod 700 "${GROK_DIR}"
chmod 700 "${OUTPUT_DIR}"
ok "Directories created with restrictive permissions."
# ── 3. Detect Chrome binary ────────────────────────────────────────────────
detect_chrome() {
for bin in google-chrome-stable google-chrome chromium-browser chromium; do
if command -v "$bin" &>/dev/null; then
command -v "$bin"
return
fi
done
echo ""
}
CHROME_BIN=$(detect_chrome)
if [[ -n "$CHROME_BIN" ]]; then
ok "Detected Chrome/Chromium: ${CHROME_BIN}"
else
warn "No Chrome/Chromium detected."
fi
# ── 4. Detect profile path ─────────────────────────────────────────────────
detect_profile() {
local profile=""
if [[ -d "${HOME}/.config/chromium/Default" ]]; then
profile="${HOME}/.config/chromium/Default"
elif [[ -d "${HOME}/.config/google-chrome/Default" ]]; then
profile="${HOME}/.config/google-chrome/Default"
fi
echo "$profile"
}
PROFILE_PATH=$(detect_profile)
if [[ -n "$PROFILE_PATH" ]]; then
ok "Detected Chrome profile: ${PROFILE_PATH}"
# Harden profile parent directory permissions
PROFILE_PARENT="$(dirname "$PROFILE_PATH")"
if [[ -d "$PROFILE_PARENT" ]]; then
chmod 700 "$PROFILE_PARENT" 2>/dev/null || true
fi
else
warn "No Chrome profile found. Launch Chrome manually first."
PROFILE_PATH="${HOME}/.config/chromium/Default"
fi
# ── 5. Write config.json template ──────────────────────────────────────────
info "Creating config.json template..."
cat > "${CONFIG_FILE}" <<EOF
{
"chrome_profile_path": "${PROFILE_PATH}",
"chrome_binary": "${CHROME_BIN:-/usr/bin/chromium-browser}",
"debug_port": 9222,
"headless": true,
"xvfb_display": ":99",
"output_dir": "${OUTPUT_DIR}",
"tasks": [
{
"id": "example_001",
"prompt": "What are the latest developments in AI?",
"wait_for_complete": true,
"timeout_seconds": 120
}
]
}
EOF
ok "Config written to: ${CONFIG_FILE}"
# ── 6. Dependency checks ───────────────────────────────────────────────────
banner "Dependency Check"
# Python 3
if command -v python3 &>/dev/null; then
PYVER=$(python3 --version 2>&1)
ok "Python: ${PYVER}"
else
err "Python 3 not found."
warn "Fix: sudo apt update && sudo apt install -y python3 python3-pip"
fi
# Chrome
if [[ -n "$CHROME_BIN" ]]; then
ok "Browser: ${CHROME_BIN}"
else
err "Chrome/Chromium not found."
warn "Fix: sudo apt install -y chromium-browser"
warn " OR: wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo dpkg -i google-chrome-stable_current_amd64.deb"
fi
# pip packages
PIP_OK=true
for pkg in websocket requests; do
if python3 -c "import ${pkg}" 2>/dev/null; then
ok "pip package: ${pkg}"
else
warn "Missing pip package: ${pkg}"
PIP_OK=false
fi
done
if [[ "$PIP_OK" == false ]]; then
warn "Fix: pip3 install websocket-client requests"
fi
# Xvfb
if command -v Xvfb &>/dev/null || command -v xvfb-run &>/dev/null; then
ok "Xvfb: available"
else
warn "Xvfb not found (optional, for headless server use)"
warn "Fix: sudo apt install -y xvfb"
fi
# Cron
if command -v crontab &>/dev/null; then
ok "Cron: crontab available"
else
warn "Cron not found"
warn "Fix: sudo apt install -y cron && sudo systemctl enable --now cron"
fi
# ── 7. Offer pip install ──────────────────────────────────────────────────
if [[ "$PIP_OK" == false ]]; then
echo ""
read -rp "Install missing pip packages now? [Y/n]: " answer
answer=${answer:-Y}
if [[ "$answer" =~ ^[Yy] ]]; then
info "Installing: pip3 install websocket-client requests"
pip3 install --user websocket-client requests || pip3 install websocket-client requests
ok "Packages installed."
fi
fi
# ── 8. Create symlink or wrapper ───────────────────────────────────────────
GROK_BIN="${HOME}/.local/bin/grokauto"
mkdir -p "$(dirname "$GROK_BIN")"
cat > "$GROK_BIN" <<EOF
#!/bin/bash
# Wrapper script for GrokAuto
exec python3 "${SCRIPT_DIR}/main.py" "\$@"
EOF
chmod +x "$GROK_BIN"
ok "Created wrapper: ${GROK_BIN}"
# Add to PATH if needed
if [[ ":$PATH:" != *":${HOME}/.local/bin:"* ]]; then
warn "${HOME}/.local/bin is not in your PATH."
info "Add this line to ~/.bashrc or ~/.profile:"
echo -e " ${B}export PATH=\"\\$HOME/.local/bin:\$PATH\"${X}"
fi
# ── 9. Final instructions ──────────────────────────────────────────────────
cat <<INSTRUCTIONS
${B}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${X}
${B} Setup Complete!${X}
${B}Next steps:${X}
1. Edit your configuration:
${C}nano ${CONFIG_FILE}${X}
2. Log in to grok.com manually (one-time):
${C}${CHROME_BIN:-chromium-browser} --remote-debugging-port=9222${X}
Navigate to https://grok.com and sign in.
3. Run a quick test:
${C}python3 ${SCRIPT_DIR}/main.py --diagnose${X}
4. Run a single prompt:
${C}python3 ${SCRIPT_DIR}/main.py --prompt "Hello Grok"${X}
5. Run tasks from config:
${C}python3 ${SCRIPT_DIR}/main.py --run${X}
6. Schedule with cron (daily at 9 AM):
${C}python3 ${SCRIPT_DIR}/main.py --setup-cron "0 9 * * *"${X}
${B}Documentation:${X} See the HTML overview document in ${SCRIPT_DIR}/
${B}Test cycle:${X} Run the guided test script: bash ${SCRIPT_DIR}/test_cycle.sh
${B}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${X}
INSTRUCTIONS