Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·2004 lines (1903 loc) · 101 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·2004 lines (1903 loc) · 101 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# =============================================================================================
# Harness Maxxing - one-line installer (Ubuntu / Debian with systemd, x86_64 or arm64, as root)
#
# Install from the public git repository (no key needed; updates come from git):
# curl --proto '=https' --tlsv1.2 -fsSL https://get.harness-maxxing.com | bash
# An Enterprise key (optional, companies only) can be given too: LICENSE=HM-XXXX-XXXX-XXXX-XXXX (recorded, nothing else changes)
# From a private fork or mirror (read token): GH_TOKEN=$T REPO=owner/name bash install.sh
# Install from a local copy of the code (an unpacked archive or a clone, web/dist built), no network
# for the code itself (updates then come from a new copy: SOURCE_DIR=... bash install.sh again):
# bash /path/to/harness-maxxing/install.sh (or SOURCE_DIR=/path/to/harness-maxxing bash install.sh)
# Options (pass them after `bash -s --` when piping):
# --check only look at this server and say what the install would do (changes nothing)
# --update update an existing install (= maxxing update)
# --uninstall remove service + integrations (= maxxing uninstall), keeps the workspace
# --purge ... also remove the code and the state directory
# --purge-workspace ... also remove the workspace (irreversible)
# -h, --help
#
# Unattended: answer with variables and ASSUME_YES=1, e.g.
# curl --proto '=https' --tlsv1.2 -fsSL https://get.harness-maxxing.com | ACCESS=domain DOMAIN=ui.example.com ASSUME_YES=1 bash
# Variables (default):
# LICENSE (optional: an Enterprise key, recorded - or later in Settings -> License) LICENSE_API (https://api.harness-maxxing.com)
# REPO (makushingu/harness-maxxing) BRANCH (stable) GH_TOKEN (private fork or mirror only) INSTALL_DIR (/opt/claude-maxxing)
# WORKSPACE (/root/maxxing) STATE_DIR (/var/lib/claude-maxxing) PORT (8787)
# ACCESS (domain|tailscale|local) DOMAIN ASSUME_YES (0)
# TIMEZONE (system zone - also chosen later in the web onboarding, which switches the system clock)
# RESTORE_FROM (owner/name of a memory backup repo) RESTORE_TOKEN (asked when not set)
# RESTORE_TRUST (0 - 1: turn on the restored jobs, extensions, hooks, MCP servers and customizations without asking)
# ALLOW_UNPROTECTED (0 - 1: go on when a protection fails to turn on: security updates, fail2ban, firewall)
# CLAUDE_TOKEN (output of `claude setup-token`, optional) ANTHROPIC_API_KEY (optional)
# VOICE (local - default: Whisper on this server, model downloaded in the background; under 3 GB of memory it is
# off unless you set VOICE=local and confirm | groq | openai | off)
# TOOLS (background - default: Node.js, Chromium, Remotion, Scrapling, the voice model are installed by
# `maxxing deps update` once the service runs | foreground: wait for them | 0: skip, `maxxing deps update` later)
# SWAP (auto - a 2 GB /swapfile when the server has under 4 GB of memory and no swap, on a fresh server only |
# 1 - the same on a server already in use | 0 never)
# SOURCE_DIR (a local copy of the code to install instead of a git download)
# CACHE_DIR (/var/cache/harness-maxxing - downloads kept until the install succeeds: a re-run does not download again)
# FIREWALL (auto - enabled only on a server with nothing else exposed | 1 always | 0 never)
# SSH_HARDEN (auto - SSH password logins are turned off only when this very session is proven to use a key
# | 1 also when a key is installed but the session cannot be checked | 0 never touch SSH)
# SYSTEM_CLOCK (auto | follow: the system zone follows yours | keep: never touch it - default on used servers)
# CLAUDE_DIR (~/.claude - another folder, e.g. /root/.claude-harness, keeps Harness Maxxing apart from a Claude
# Code already used here: its own skills, global CLAUDE.md, transcripts and sign-in. When Claude Code is
# already used and CLAUDE_DIR is not set, the installer asks: own folder ~/.claude-harness (default) or share)
#
# Re-runnable: every step keeps what exists. The server never listens on a public interface.
# Secrets (license key, tokens) are best typed at the prompts (hidden) or set with `read -rs NAME; export NAME`:
# never on the command line, where they stay in the shell history and are visible in `ps`.
# =============================================================================================
set -euo pipefail
umask 077 # everything the installer creates is private unless it says otherwise (chmod)
# a script run from a source tree (bash ./install.sh in an unpacked archive or a clone) installs that tree;
# resolved before the `cd /` below, or a relative ./install.sh would no longer be found
SELF_DIR=""
if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
SELF_DIR=$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" 2>/dev/null && pwd -P || true)
fi
cd / # never run from a directory another user controls
unset BASH_ENV ENV CDPATH PYTHONPATH PYTHONHOME PYTHONSTARTUP LD_PRELOAD LD_LIBRARY_PATH NODE_OPTIONS GIT_DIR GIT_WORK_TREE \
GIT_CONFIG_PARAMETERS GIT_CONFIG_COUNT 2>/dev/null || true
REPO="${REPO:-makushingu/harness-maxxing}"
# every install follows `stable` (published versions); an Enterprise key changes nothing there (2.0.0a88)
BRANCH="${BRANCH:-stable}"
GH_TOKEN="${GH_TOKEN:-}"
LICENSE="${LICENSE:-}"
LICENSE_API="${LICENSE_API:-https://api.harness-maxxing.com}"
LICENSED=0 # 1 = an install from before 2.0.0a87 still on signed archives: kept, it moves to git by itself
# ---- third-party downloads ------------------------------------------------------------------
# Versions, URLs and sha256 of uv, Claude Code, Node.js, Caddy's key... are in server/maxxing/deps.toml (the same
# manifest `maxxing deps` reads): `dep` below reads it from the code once it is here, and every download goes through
# fetch_verified (HTTPS, private work folder, sha256 checked before anything runs or is extracted).
INSTALL_DIR="${INSTALL_DIR:-/opt/claude-maxxing}"
WORKSPACE="${WORKSPACE:-/root/maxxing}"
STATE_DIR="${STATE_DIR:-/var/lib/claude-maxxing}"
PORT="${PORT:-8787}"
ACCESS="${ACCESS:-}"
DOMAIN="${DOMAIN:-}"
TIMEZONE="${TIMEZONE:-}"
ASSUME_YES="${ASSUME_YES:-0}"
RESTORE_FROM="${RESTORE_FROM:-}"
RESTORE_TOKEN="${RESTORE_TOKEN:-}"
CLAUDE_TOKEN="${CLAUDE_TOKEN:-}"
ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}"
VOICE_GIVEN="${VOICE:+1}" # set by the caller (not the default): a small server asks before taking it
VOICE="${VOICE:-local}"
SOURCE_DIR="${SOURCE_DIR:-}"
TOOLS="${TOOLS:-background}"
SWAP="${SWAP:-auto}"
MEMINFO=/proc/meminfo
FIREWALL="${FIREWALL:-auto}"
SSH_HARDEN="${SSH_HARDEN:-auto}"
SYSTEM_CLOCK="${SYSTEM_CLOCK:-auto}"
CLAUDE_DIR="${CLAUDE_DIR:-}"
RESTORE_TRUST="${RESTORE_TRUST:-0}"
ALLOW_UNPROTECTED="${ALLOW_UNPROTECTED:-0}"
# secrets stay in shell variables: no child process (apt, curl, npm, the Claude installer...) inherits them
export -n LICENSE GH_TOKEN RESTORE_TOKEN CLAUDE_TOKEN ANTHROPIC_API_KEY 2>/dev/null || true
unset MAXXING_GITHUB_TOKEN 2>/dev/null || true
WORK=$(mktemp -d /tmp/harness-install.XXXXXXXX) # every download, script and log of this run (removed at exit)
WORK0=$WORK # the one on_exit removes (tests point WORK elsewhere)
export TMPDIR="$WORK" # temporary files of apt, uv, npm, claude... go there too
SERVICE=claude-maxxing
UNIT=/etc/systemd/system/$SERVICE.service
CADDY_SITE=/etc/caddy/claude-maxxing.caddy
CADDYFILE=/etc/caddy/Caddyfile
SSHD_CONFIG=/etc/ssh/sshd_config
SSH_DROPIN=/etc/ssh/sshd_config.d/01-harness-maxxing.conf
BIN=/usr/local/bin/maxxing
DEFAULT_STATE=/var/lib/claude-maxxing
TOTAL=11
LOCAL=0 # 1 = code copied from SOURCE_DIR (no license, no git remote)
STEP=0
IN_STEP=0
SPIN_PID=""
STEP_LOG=""
declare -A BG_PID=() # background jobs of this run (bg_start / bg_wait): name -> PID
T_START=$SECONDS
BIND=127.0.0.1
PUBLIC_URL=""
AFTER=""
TOKEN_USED=0
# filled by detect_server (pre-flight check of a server that may already be in use)
EXISTING=0 # 1 = the server already runs other things: be careful
PRIOR=0 # 1 = Harness Maxxing was already installed here (a re-run)
PUBLIC_OTHER="" # other services listening on public interfaces ("port/process ...")
WEB_BUSY="" # process holding port 80/443 that is not Caddy (nginx, apache2, docker-proxy...)
FW_ACTIVE="" # ufw | nftables | "" (no firewall rules)
HAS_DOCKER=0
OTHER_CRON=0 # root crontab lines that are not ours
NODE_OLD="" # an older Node.js already installed (path) -> ours stays in <state>/tools/nodejs
BRIDGES="" # other Telegram bridges / agents found (process or unit names)
CLAUDE_SETUP="" # existing Claude Code setup (skills, CLAUDE.md, signed in)
# ---- output ---------------------------------------------------------------------------------
FANCY=0
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != dumb ]; then
FANCY=1
C_B=$'\033[1m'; C_D=$'\033[2m'; C_G=$'\033[38;5;42m'; C_Y=$'\033[38;5;214m'; C_R=$'\033[38;5;203m'
C_C=$'\033[38;5;75m'; C_A=$'\033[38;5;33m'; C_W=$'\033[97m'; C_0=$'\033[0m'
BLUES=(27 33 39 45 51 87)
else
C_B=""; C_D=""; C_G=""; C_Y=""; C_R=""; C_C=""; C_A=""; C_W=""; C_0=""
BLUES=()
fi
ok() { printf ' %s✔%s %s\n' "$C_G" "$C_0" "$*"; }
warn() { printf ' %s!%s %s\n' "$C_Y" "$C_0" "$*"; }
info() { printf ' %s%s%s\n' "$C_D" "$*" "$C_0"; }
die() { printf ' %s✘ %s%s\n' "$C_R" "$*" "$C_0" >&2; exit 1; }
section() { printf '\n %s◆%s %s%s%s\n' "$C_A" "$C_0" "$C_B" "$*" "$C_0"; }
fmt_secs() { local s=$1; if [ "$s" -ge 60 ]; then printf '%d min %02d s' $((s / 60)) $((s % 60)); else printf '%d s' "$s"; fi; }
logo() {
local lines=(
'███╗ ███╗ █████╗ ██╗ ██╗██╗ ██╗██╗███╗ ██╗ ██████╗ '
'████╗ ████║██╔══██╗╚██╗██╔╝╚██╗██╔╝██║████╗ ██║██╔════╝ '
'██╔████╔██║███████║ ╚███╔╝ ╚███╔╝ ██║██╔██╗ ██║██║ ███╗'
'██║╚██╔╝██║██╔══██║ ██╔██╗ ██╔██╗ ██║██║╚██╗██║██║ ██║'
'██║ ╚═╝ ██║██║ ██║██╔╝ ██╗██╔╝ ██╗██║██║ ╚████║╚██████╔╝'
'╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ')
echo
if [ "$FANCY" = 1 ] && [ "$(tput cols 2>/dev/null || echo 80)" -ge 64 ]; then
printf ' %s%sH A R N E S S%s\n' "$C_B" "$C_C" "$C_0"
local i
for i in "${!lines[@]}"; do printf ' \033[38;5;%sm%s%s\n' "${BLUES[$i]}" "${lines[$i]}" "$C_0"; done
else
printf ' %sHARNESS MAXXING%s\n' "$C_B" "$C_0"
fi
printf ' %sThe control room for Claude Code on your own server%s\n' "$C_D" "$C_0"
}
# step_begin "Title" - numbered step; its output is captured and shown once it ends, a spinner runs meanwhile
step_begin() {
STEP=$((STEP + 1)); STEP_TITLE=$1; STEP_T0=$SECONDS; IN_STEP=1
if [ "$FANCY" = 1 ]; then
STEP_LOG=$(mktemp "$WORK/step.XXXXXX")
exec 3>&1 4>&2
(
trap 'exit 0' TERM
f='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'; i=0; t0=$SECONDS
while :; do
printf '\r %s%s%s %s%d/%d%s %s %s%s%s\033[K' "$C_A" "${f:i%10:1}" "$C_0" "$C_D" "$STEP" "$TOTAL" "$C_0" \
"$STEP_TITLE" "$C_D" "$(fmt_secs $((SECONDS - t0)))" "$C_0" >&3
i=$((i + 1)); sleep 0.1
done
) &
SPIN_PID=$!
exec >"$STEP_LOG" 2>&1
else
printf '\n[%d/%d] %s\n' "$STEP" "$TOTAL" "$STEP_TITLE"
fi
}
step_end() { # step_end ok|fail
local status=${1:-ok} took=$((SECONDS - STEP_T0)) mark
IN_STEP=0
[ "$FANCY" = 1 ] || return 0
if [ -n "$SPIN_PID" ]; then kill "$SPIN_PID" 2>/dev/null; wait "$SPIN_PID" 2>/dev/null || true; SPIN_PID=""; fi
exec 1>&3 2>&4 3>&- 4>&-
if [ "$status" = ok ]; then mark="$C_G✔$C_0"; else mark="$C_R✘$C_0"; fi
printf '\r\033[K %s %s%d/%d%s %s%s%s %s%s%s\n' "$mark" "$C_D" "$STEP" "$TOTAL" "$C_0" "$C_B" "$STEP_TITLE" "$C_0" \
"$C_D" "$(fmt_secs "$took")" "$C_0"
if [ -s "$STEP_LOG" ]; then
if [ "$status" = ok ]; then cat "$STEP_LOG"; else tail -n 25 "$STEP_LOG"; fi
fi
rm -f "$STEP_LOG"
}
run_step() { # run_step "Title" function - runs in this shell (variables it sets are kept)
step_begin "$1"
"$2"
step_end ok
}
on_exit() {
local rc=$? keep=""
if [ "$IN_STEP" = 1 ]; then
step_end fail
printf '\n %sThe installation stopped.%s Fix the problem above, then run the same command again:\n' "$C_R$C_B" "$C_0"
printf ' %severy step keeps what is already done, downloads included.%s\n\n' "$C_D" "$C_0"
fi
# an apt job still running is waited for (dpkg cut halfway leaves the system to repair, and $WORK is its TMPDIR);
# background downloads of this run die with it
if [ -n "${BG_PID[apt]:-}" ] && kill -0 "${BG_PID[apt]}" 2>/dev/null; then
printf ' %swaiting for the system packages being installed to finish...%s\n' "$C_D" "$C_0"
wait "${BG_PID[apt]}" 2>/dev/null || true
fi
local j; for j in $(jobs -p 2>/dev/null); do kill_tree "$j"; done
if [ "$rc" != 0 ] && [ -d "$WORK" ] && ls "$WORK"/*.log >/dev/null 2>&1 && [ -d "$STATE_DIR" ]; then
keep="$STATE_DIR/logs/install-failed-$(date +%Y%m%d-%H%M%S)"
mkdir -p -m 700 "$STATE_DIR/logs" && mkdir -m 700 "$keep" && cp "$WORK"/*.log "$keep/" 2>/dev/null \
&& printf ' %slogs of this run: %s%s\n' "$C_D" "$keep" "$C_0"
fi
case "${WORK0:-}" in */harness-install.?*) rm -rf "$WORK0" ;; esac
exit "$rc"
}
trap on_exit EXIT
kill_tree() { # kill_tree PID - a background job and what it started (uv, curl...): none of them outlives the run
local c
for c in $(pgrep -P "$1" 2>/dev/null); do kill_tree "$c"; done
kill "$1" 2>/dev/null || true
}
# ---- questions (answers come from the terminal even when the script is piped) ---------------
has_tty() { [ "$ASSUME_YES" != 1 ] && (: </dev/tty) 2>/dev/null; }
# ask VAR "question" [default] - keeps a VAR that is already set
ask() {
local __v=$1 __q=$2 __d=${3:-} __a=""
[ -n "${!__v:-}" ] && return 0
if ! has_tty; then printf -v "$__v" '%s' "$__d"; return 0; fi
read -rp " $C_A?$C_0 $__q${__d:+ ${C_D}[$__d]$C_0}: " __a </dev/tty || true
printf -v "$__v" '%s' "${__a:-$__d}"
}
ask_secret() {
local __v=$1 __q=$2 __a=""
[ -n "${!__v:-}" ] && return 0
has_tty || return 0
read -rsp " $C_A?$C_0 $__q: " __a </dev/tty || true
echo
printf -v "$__v" '%s' "$__a"
}
# ask_yn "question" default(y|n) -> 0 = yes
ask_yn() {
local __a="" __d=${2:-n}
if ! has_tty; then [ "$__d" = y ]; return; fi
read -rp " $C_A?$C_0 $1 ${C_D}[$( [ "$__d" = y ] && echo Y/n || echo y/N )]$C_0: " __a </dev/tty || true
__a=${__a:-$__d}
case "$__a" in y|Y|yes|YES) return 0 ;; *) return 1 ;; esac
}
# ---- helpers --------------------------------------------------------------------------------
venv_py() { echo "$INSTALL_DIR/server/.venv/bin/python"; }
# cfg_get KEY - value from an existing config.json ("" when absent)
cfg_get() {
local py
py=$(venv_py)
[ -x "$py" ] || py=$(command -v python3 || true)
[ -n "$py" ] && [ -f "$STATE_DIR/config.json" ] || { echo ""; return 0; }
"$py" -I - "$STATE_DIR/config.json" "$1" <<'PY' 2>/dev/null || echo ""
import json, sys
v = json.load(open(sys.argv[1])).get(sys.argv[2], "")
print("" if v is None else v)
PY
}
# git_tok ARGS... - git with the read token in its environment (GIT_CONFIG_*), never in its command line: the
# arguments of every process are visible to every user (ps), its environment only to root
git_tok() {
if [ -n "$GH_TOKEN" ]; then
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraHeader \
GIT_CONFIG_VALUE_0="Authorization: Basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')" git "$@"
else
git "$@"
fi
}
# apt_get ARGS... - apt with the usual umask (package scripts create files other users must read). A fresh VPS often
# has unattended-upgrades or cloud-init holding the dpkg lock for minutes: wait for it (10 min max) instead of failing
apt_get() {
(umask 022; DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=600 -o Acquire::Retries=3 \
-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold "$@")
}
# ---- background jobs ------------------------------------------------------------------------
# The long independent parts run while the next steps go on: the tool, browser and security packages (one apt job:
# two apt/dpkg never run at the same time), the uv and Claude Code downloads, the Python environment (only network
# and uv). bg_start NAME CMD... - CMD in the background, its output in $WORK/bg-NAME.log (kept with the logs of a
# failed run); bg_wait NAME - waits for it, prints the end of its log when it failed, returns its exit code.
bg_start() {
local name=$1; shift
( set -e; "$@" ) >"$WORK/bg-$name.log" 2>&1 </dev/null 3>&- 4>&- &
BG_PID[$name]=$!
}
bg_wait() {
local name=$1 pid=${BG_PID[$1]:-} rc=0
[ -n "$pid" ] || return 0
wait "$pid" || rc=$?
unset "BG_PID[$name]"
[ "$rc" = 0 ] || tail -n 15 "$WORK/bg-$name.log" 2>/dev/null | sed 's/^/ | /'
return "$rc"
}
# reset_env - a root shell of its own: HOME and PATH of root, whatever the caller had (sudo -E, su without -)
reset_env() {
HOME=$(getent passwd root 2>/dev/null | cut -d: -f6)
HOME=${HOME:-/root}
export HOME
export PATH="$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}
# url_ok URL - https://, or plain http to this machine only (tests)
url_ok() {
case "$1" in
https://*) return 0 ;;
http://127.0.0.1:*|http://127.0.0.1/*|http://localhost:*|http://localhost/*) return 0 ;;
*) return 1 ;;
esac
}
# ---- the dependency manifest (server/maxxing/deps.toml) --------------------------------------
deps_toml() { echo "$INSTALL_DIR/server/maxxing/deps.toml"; }
# dep NAME KEY [SUBKEY] - a value of deps.toml (only the subset it uses: [name], key = "s", key = ["a"], key = { k = "v" })
dep() {
[ -f "$(deps_toml)" ] || return 1
python3 -I - "$(deps_toml)" "$@" <<'PY'
import re, sys
path, name, key = sys.argv[1:4]
sub = sys.argv[4] if len(sys.argv) > 4 else None
sec = None
for ln in open(path, encoding="utf-8"):
ln = ln.strip()
if not ln or ln.startswith("#"):
continue
m = re.fullmatch(r"\[([A-Za-z0-9_-]+)\]", ln)
if m:
sec = m.group(1)
continue
m = re.fullmatch(r"([A-Za-z0-9_]+)\s*=\s*(.+)", ln)
if sec != name or not m or m.group(1) != key:
continue
v = m.group(2)
if v.startswith('"'):
print(re.match(r'"([^"\\]*)"', v).group(1))
elif v.startswith("["):
print("\n".join(re.findall(r'"([^"\\]*)"', v)))
elif v.startswith("{"):
d = dict(re.findall(r'([A-Za-z0-9_]+)\s*=\s*"([^"\\]*)"', v))
if sub is None:
print("\n".join(k + "=" + x for k, x in d.items()))
elif sub in d:
print(d[sub])
else:
sys.exit(1)
sys.exit(0)
sys.exit(1)
PY
}
machine() { case "$(uname -m)" in x86_64|amd64) echo x86_64 ;; aarch64|arm64) echo aarch64 ;; *) uname -m ;; esac; }
# dep_url NAME - the download URL of a component for this machine
dep_url() {
local v a u
v=$(dep "$1" version) && a=$(dep "$1" arch "$(machine)") && u=$(dep "$1" url) || return 1
u=${u//\{version\}/$v}; printf '%s' "${u//\{arch\}/$a}"
}
# ---- download cache: a failed install run again does not download again --------------------------
# Every verified download is kept in CACHE_DIR under its sha256 until an install succeeds (then emptied): a re-run
# after a failure reuses it, or resumes a transfer that was cut. Root only (700); the sha256 is checked on every use.
CACHE_DIR="${CACHE_DIR:-/var/cache/harness-maxxing}"
cache_ready() { # the cache folder exists, is ours and is not a link (otherwise downloads go straight to $WORK)
[ ! -L "$CACHE_DIR" ] && mkdir -p -m 700 "$CACHE_DIR" 2>/dev/null && [ -d "$CACHE_DIR" ] && [ -O "$CACHE_DIR" ]
}
cache_clear() { # after a successful install: only the files fetch_verified wrote (<sha256>, <sha256>.part)
[ -d "$CACHE_DIR" ] && [ ! -L "$CACHE_DIR" ] || return 0
find "$CACHE_DIR" -maxdepth 1 -type f -regextype posix-extended -regex '.*/[0-9a-f]{64}(\.part)?' -delete 2>/dev/null || true
rmdir "$CACHE_DIR" 2>/dev/null || true
}
sha_of() { sha256sum "$1" | cut -d' ' -f1; }
# fetch_verified URL SHA256 DEST - THE way this installer downloads code: HTTPS only (plain http only to this
# machine, for tests), into DEST (inside $WORK), sha256 checked before the file is used; a mismatch deletes it
fetch_verified() {
local url=$1 sum=$2 dest=$3 proto='=https' keep="" part get
case "$url" in https://*) ;; *) url_ok "$url" || { warn "refused: $url is not HTTPS"; return 1; }; proto='=https,http' ;; esac
get=(curl -fsSL --proto "$proto" --retry 3 --retry-connrefused --connect-timeout 20 --speed-limit 10240 --speed-time 60)
printf '%s' "$sum" | grep -Eq '^[0-9a-f]{64}$' || { warn "no valid sha256 pinned for $url"; return 1; }
if [ -f "$dest" ] && [ "$(sha_of "$dest")" = "$sum" ]; then return 0; fi
cache_ready && keep="$CACHE_DIR/$sum"
if [ -n "$keep" ] && [ -f "$keep" ]; then # downloaded by an earlier run
if [ "$(sha_of "$keep")" = "$sum" ]; then ln -f "$keep" "$dest" 2>/dev/null || cp -f "$keep" "$dest"; return; fi
rm -f "$keep"
fi
part=${keep:-$dest}.part
# a transfer cut on an earlier run goes on where it stopped (-C -); a server that cannot resume: from the start
if ! { [ -n "$keep" ] && [ -s "$part" ] && "${get[@]}" -C - -o "$part" "$url" 2>/dev/null; }; then
rm -f "$part"
"${get[@]}" -o "$part" "$url" || { rm -f "$part"; warn "download failed: $url"; return 1; }
fi
if [ "$(sha_of "$part")" != "$sum" ]; then
rm -f "$part"; warn "checksum mismatch: $url (expected sha256 $sum)"; return 1
fi
if [ -n "$keep" ]; then mv -f "$part" "$keep"; ln -f "$keep" "$dest" 2>/dev/null || cp -f "$keep" "$dest"
else mv -f "$part" "$dest"; fi
}
# dep_fetch NAME DEST - fetch_verified with the URL and the sha256 of deps.toml for this machine
dep_fetch() {
local url sum
url=$(dep_url "$1") && sum=$(dep "$1" sha256 "$(machine)") || { warn "$1: no build pinned for $(machine) in deps.toml"; return 1; }
fetch_verified "$url" "$sum" "$2"
}
# ---- input checks (every value below ends up in files, units and commands run as root) --------
one_line() { case "$1" in *$'\n'*|*$'\r'*) return 1 ;; esac; } # the grep -E checks below test each line alone
not_system_dir() { # not_system_dir NAME VALUE - never / nor a system directory (chmod 700 on it, --purge deletes it)
local d=$2
while [[ $d == *//* ]]; do d=${d//\/\//\/}; done # //etc, /var//lib are /etc, /var/lib
while [[ $d == */./* ]]; do d=${d//\/.\//\/}; done # /./usr/lib, /home/./bob
while [ "${d%/}" != "$d" ] || [ "${d%/.}" != "$d" ]; do d=${d%/}; d=${d%/.}; done # /etc/, /etc/., /.
if [ -z "$d" ] || [[ $d =~ ^/(bin|boot|dev|etc|home|lib|lib32|lib64|libx32|media|mnt|opt|proc|root|run|sbin|snap|srv|sys|tmp|usr|var)$ ]] \
|| [[ $d =~ ^/(bin|boot|dev|etc|lib|lib32|lib64|libx32|proc|run|sbin|sys|usr)/ ]] \
|| [[ $d =~ ^/var/(lib|log|cache|tmp|spool|www|mail|backups|opt|local|run|lock)$ ]] || [[ $d =~ ^/home/[^/]+$ ]]; then
die "$1 cannot be / or a system directory (got '$2')"
fi
}
safe_path() { # safe_path NAME VALUE - absolute, no whitespace, quotes, %, $, backslash, backtick or ..
case "$2" in
/*) ;;
*) die "$1 must be an absolute path (got '$2')" ;;
esac
case "$2" in
*[[:space:]]*|*\"*|*\'*|*%*|*\$*|*\\*|*\`*|*/../*|*/..) die "$1 contains a character that is not allowed: '$2'" ;;
esac
}
check_inputs() {
safe_path INSTALL_DIR "$INSTALL_DIR"; safe_path WORKSPACE "$WORKSPACE"; safe_path STATE_DIR "$STATE_DIR"
[ -z "$CLAUDE_DIR" ] || safe_path CLAUDE_DIR "$CLAUDE_DIR"
not_system_dir INSTALL_DIR "$INSTALL_DIR"; not_system_dir WORKSPACE "$WORKSPACE"; not_system_dir STATE_DIR "$STATE_DIR"
[ -z "$CLAUDE_DIR" ] || not_system_dir CLAUDE_DIR "$CLAUDE_DIR"
local v
for v in BRANCH REPO RESTORE_FROM TIMEZONE DOMAIN LICENSE_API; do
one_line "${!v:-}" || die "$v must be on one line"
done
case "$PORT" in ''|*[!0-9]*) die "PORT must be a number" ;; esac
[ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ] || die "PORT must be between 1 and 65535"
case "$BRANCH" in -*|*..*|*//*|/*|*/) die "BRANCH is not a valid branch name (got '$BRANCH')" ;; esac
printf '%s' "$BRANCH" | grep -Eq '^[A-Za-z0-9._/-]+$' || die "BRANCH may only contain letters, digits, . _ / - (got '$BRANCH')"
printf '%s' "$REPO" | grep -Eq '^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$' || die "REPO must be owner/name (got '$REPO')"
if [ -n "$RESTORE_FROM" ] && ! printf '%s' "$RESTORE_FROM" | grep -Eq '^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$'; then
die "RESTORE_FROM must be owner/name (got '$RESTORE_FROM')"
fi
url_ok "$LICENSE_API" || die "LICENSE_API must be an https:// address (got '$LICENSE_API')"
case "$RESTORE_TRUST" in 0|1) ;; *) die "RESTORE_TRUST must be 0 or 1" ;; esac
case "$ALLOW_UNPROTECTED" in 0|1) ;; *) die "ALLOW_UNPROTECTED must be 0 or 1" ;; esac
case "$FIREWALL" in auto|add|0|1) ;; *) die "FIREWALL must be auto, 1 or 0" ;; esac
case "$SSH_HARDEN" in auto|0|1) ;; *) die "SSH_HARDEN must be auto, 1 or 0" ;; esac
case "$TOOLS" in background|foreground|0) ;; *) die "TOOLS must be background, foreground or 0" ;; esac
case "$SWAP" in auto|0|1) ;; *) die "SWAP must be auto, 1 or 0" ;; esac
[ -z "$SOURCE_DIR" ] || safe_path SOURCE_DIR "$SOURCE_DIR"
safe_path CACHE_DIR "$CACHE_DIR"; not_system_dir CACHE_DIR "$CACHE_DIR"
[ -z "$TIMEZONE" ] || valid_tz_name "$TIMEZONE" || die "TIMEZONE is not a time zone name (got '$TIMEZONE')"
}
valid_tz_name() { one_line "$1" || return 1; case "$1" in ""|/*|*..*) return 1 ;; esac; printf '%s' "$1" | grep -Eq '^[A-Za-z0-9_+-]+(/[A-Za-z0-9_+-]+)*$'; }
valid_domain() { one_line "$1" && [ ${#1} -le 253 ] && printf '%s' "$1" | grep -Eq '^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,61}[a-z0-9]$'; }
valid_tz() {
case "$1" in UTC|Etc/UTC) return 0 ;; esac
valid_tz_name "$1" && [ -f "/usr/share/zoneinfo/$1" ]
}
mx() { MAXXING_STATE="$STATE_DIR" "$BIN" "$@"; }
usage() {
cat <<'USAGE'
Harness Maxxing installer
curl --proto '=https' --tlsv1.2 -fsSL https://get.harness-maxxing.com | bash install or repair from the public git repository (re-runnable)
... | LICENSE=HM-XXXX-XXXX-XXXX-XXXX bash the same, recording an Enterprise key (companies only)
GH_TOKEN=<token> REPO=owner/name bash install.sh from a private fork or mirror
bash /opt/claude-maxxing/install.sh --update update (= maxxing update)
bash /opt/claude-maxxing/install.sh --uninstall [--purge] [--purge-workspace]
bash /opt/claude-maxxing/install.sh --tools (re)install Node.js, Chromium, Remotion, Scrapling (= maxxing deps update)
bash ./install.sh from an unpacked copy of the code (or SOURCE_DIR=DIR)
bash /opt/claude-maxxing/install.sh --secure security updates, SSH by key, fail2ban, firewall (FIREWALL=0, SSH_HARDEN=0)
curl --proto '=https' --tlsv1.2 -fsSL https://get.harness-maxxing.com | bash -s -- --check look at this server first, change nothing
Variables: LICENSE LICENSE_API REPO BRANCH GH_TOKEN INSTALL_DIR WORKSPACE STATE_DIR PORT ACCESS(domain|tailscale|local)
FIREWALL(auto|1|0) SSH_HARDEN(auto|1|0) SYSTEM_CLOCK(auto|follow|keep) DOMAIN TIMEZONE ASSUME_YES=1 RESTORE_FROM RESTORE_TOKEN
CLAUDE_TOKEN ANTHROPIC_API_KEY CLAUDE_DIR (own Claude Code folder, default ~/.claude) VOICE TOOLS SWAP SOURCE_DIR CACHE_DIR
USAGE
}
# ---- checks ---------------------------------------------------------------------------------
check_system() {
section "Server"
[ "$(id -u)" = 0 ] || die "Run as root (sudo -i, then the command again)."
command -v apt-get >/dev/null 2>&1 || die "Ubuntu or Debian required (apt-get not found)."
if [ -r /etc/os-release ]; then
local ids pretty
# shellcheck disable=SC1091
ids=$(. /etc/os-release && echo " ${ID:-} ${ID_LIKE:-} ")
# shellcheck disable=SC1091
pretty=$(. /etc/os-release && echo "${PRETTY_NAME:-${ID:-unknown}}")
case "$ids" in
*" debian "*|*" ubuntu "*) ok "$pretty" ;;
*) warn "untested distribution ($pretty) - continuing because apt is present" ;;
esac
fi
[ -d /run/systemd/system ] || die "systemd must be running (sessions and the service are systemd units)."
case "$(uname -m)" in
x86_64|amd64|aarch64|arm64) ok "architecture $(uname -m), systemd running" ;;
*) die "unsupported architecture $(uname -m) (x86_64 or arm64 required)" ;;
esac
check_inputs
}
# ---- pre-flight check: is this server already in use? ----------------------------------------
# Nothing is changed here: detect_server fills the variables above, preflight prints them and says
# what the installer will do differently. `install.sh --check` stops after it.
manifest() { # remember what the installer changed on this server (read by maxxing uninstall)
mkdir -p "$STATE_DIR"
grep -qxF "$1" "$STATE_DIR/install-manifest" 2>/dev/null || echo "$1" >> "$STATE_DIR/install-manifest"
}
our_unit_active() { systemctl is-active -q "$SERVICE" 2>/dev/null; }
listeners() { # "addr port process" for every listening TCP socket
command -v ss >/dev/null 2>&1 || return 0
ss -ltnpH 2>/dev/null | awk '{
a=$4; p=a; sub(/.*:/, "", p); sub(/:[0-9]+$/, "", a); gsub(/[\[\]]/, "", a)
n="?"; if (match($0, /users:\(\("[^"]+"/)) { n=substr($0, RSTART+9, RLENGTH-10) }
print a, p, n }'
}
udp_listeners() { # "addr port process" for every UDP socket bound for listening
command -v ss >/dev/null 2>&1 || return 0
ss -lunpH 2>/dev/null | awk '{
a=$4; p=a; sub(/.*:/, "", p); sub(/:[0-9]+$/, "", a); sub(/%.*/, "", a); gsub(/[\[\]]/, "", a)
n="?"; if (match($0, /users:\(\("[^"]+"/)) { n=substr($0, RSTART+9, RLENGTH-10) }
print a, p, n }'
}
detect_server() {
local addr port name ssh_p seen=" " proxy_p
ssh_p=" $(ssh_ports | tr '\n' ' ') "
proxy_p=$(cfg_get proxy_listen); proxy_p=${proxy_p##*:}
while read -r addr port name; do
[ -n "$port" ] || continue
case "$addr" in 127.*|::1|localhost|100.*|fd7a:115c:a1e0:*) continue ;; esac # loopback, Tailscale
[ "$name" = tailscaled ] && continue
case "$ssh_p" in *" $port "*) continue ;; esac
case "$port:$name" in 53:systemd-resolve|5355:systemd-resolve) continue ;; esac # DNS stub, LLMNR (Debian)
if [ "$port" = "$PORT" ] && our_unit_active; then continue; fi
if [ -n "$proxy_p" ] && [ "$port" = "$proxy_p" ] && our_unit_active; then continue; fi # maxxing proxy on
case "$port" in
80|443) case "$name" in caddy) [ -f "$CADDY_SITE" ] && continue ;; *) WEB_BUSY=${WEB_BUSY:-$name} ;; esac ;;
esac
case "$seen" in *" $port "*) continue ;; esac
seen="$seen$port "
if [ "$name" = "?" ]; then PUBLIC_OTHER="${PUBLIC_OTHER:+$PUBLIC_OTHER }$port"
else PUBLIC_OTHER="${PUBLIC_OTHER:+$PUBLIC_OTHER }$port/$name"; fi
done < <(listeners)
while read -r addr port name; do # UDP: a VPN (WireGuard, OpenVPN), DNS, a game server...
[ -n "$port" ] || continue
case "$addr" in 127.*|::1|localhost|100.*|fd7a:115c:a1e0:*|fe80:*) continue ;; esac
case "$name" in tailscaled|chronyd|ntpd|systemd-timesyn|dhclient|systemd-network|avahi-daemon|systemd-resolve|caddy) continue ;; esac
case "$port" in 68|546|123|323|5353|5355) continue ;; esac # DHCP, time, mDNS / LLMNR
case "$seen" in *" $port/udp "*) continue ;; esac
seen="$seen$port/udp "
PUBLIC_OTHER="${PUBLIC_OTHER:+$PUBLIC_OTHER }$port/udp${name:+/$name}"
done < <(udp_listeners)
# a Caddy that is not ours on 80/443 is fine: our site is added with an import line
case "$WEB_BUSY" in caddy) WEB_BUSY="" ;; "?") WEB_BUSY="another web server" ;; esac
if command -v ufw >/dev/null 2>&1 && ufw status 2>/dev/null | grep -q '^Status: active'; then
FW_ACTIVE=ufw
elif command -v nft >/dev/null 2>&1 && [ "$(nft list ruleset 2>/dev/null | grep -c 'chain ')" -gt 0 ]; then
FW_ACTIVE=nftables
fi
if command -v docker >/dev/null 2>&1 || systemctl is-active -q docker 2>/dev/null; then HAS_DOCKER=1; fi
if crontab -l 2>/dev/null | sed "/^# >>> claude-maxxing/,/^# <<< claude-maxxing/d" \
| grep -vE '^[[:space:]]*(#|$|[A-Za-z_]+=)' | grep . >/dev/null; then OTHER_CRON=1; fi
local nv np
np=$(command -v node 2>/dev/null || true)
if [ -n "$np" ]; then
nv=$(node --version 2>/dev/null | sed 's/^v//; s/\..*//')
if [ -n "$nv" ] && [ "$nv" -lt 20 ] 2>/dev/null; then NODE_OLD="$np (v$nv)"; fi
fi
local pat='telegram|hermes|openclaw|claudegram|ccbot'
BRIDGES=$( { systemctl list-units --type=service --all --no-legend --plain 2>/dev/null | awk '{print $1}' | sed 's/\.service$//';
ps -eo args= 2>/dev/null | awk '{for (i = 1; i <= 2 && i <= NF; i++) { n = $i; sub(/.*\//, "", n); print n }}'; } \
| grep -iE "$pat" | grep -vE "^($SERVICE|maxxing-)" | sort -u | head -n 5 | tr '\n' ' ' | sed 's/ $//' || true)
local sk=0
[ -d "$HOME/.claude/skills" ] && sk=$(ls -A "$HOME/.claude/skills/" 2>/dev/null | wc -l)
local parts=()
[ -f "$HOME/.claude/.credentials.json" ] && parts+=("signed in")
[ "$sk" -gt 0 ] && parts+=("$sk skill(s)")
[ -f "$HOME/.claude/CLAUDE.md" ] && parts+=("~/.claude/CLAUDE.md")
local conv=0
[ -d "$HOME/.claude/projects" ] && conv=$(ls -A "$HOME/.claude/projects/" 2>/dev/null | wc -l)
[ "$conv" -gt 0 ] && parts+=("conversations in $conv folder(s)")
[ ${#parts[@]} -gt 0 ] && CLAUDE_SETUP=$(IFS=,; echo "${parts[*]}" | sed 's/,/, /g')
[ -f "$STATE_DIR/config.json" ] && CLAUDE_SETUP="" # a re-run: that setup is Harness Maxxing's own (its skills)
[ -f "$STATE_DIR/config.json" ] && PRIOR=1
if [ -n "$PUBLIC_OTHER$WEB_BUSY$BRIDGES" ] || [ "$HAS_DOCKER" = 1 ] || [ "$OTHER_CRON" = 1 ] \
|| [ -n "$FW_ACTIVE" ] || [ -n "$CLAUDE_SETUP" ]; then EXISTING=1; fi
# port of the web server: another program already on it -> the next free one
if [ ! -d "$INSTALL_DIR/.git" ] && ! our_unit_active; then
local p=$PORT
while listeners | awk -v p="$p" '$2==p {f=1} END {exit !f}'; do p=$((p + 1)); done
PORT_MOVED_FROM=""
[ "$p" = "$PORT" ] || { PORT_MOVED_FROM=$PORT; PORT=$p; }
fi
if [ "$SYSTEM_CLOCK" = auto ]; then
SYSTEM_CLOCK=$(cfg_get system_clock)
[ -n "$SYSTEM_CLOCK" ] || { [ "$EXISTING" = 1 ] && SYSTEM_CLOCK=keep || SYSTEM_CLOCK=follow; }
fi
if [ "$FIREWALL" = auto ]; then
if [ -n "$FW_ACTIVE" ]; then FIREWALL=add # keep theirs, only add our rules
elif [ -n "$PUBLIC_OTHER" ] || [ "$HAS_DOCKER" = 1 ]; then FIREWALL=0
else FIREWALL=1; fi
fi
}
preflight() {
section "Server check"
local free_gb mem_gb
free_gb=$(df -Pk / 2>/dev/null | awk 'NR==2{printf "%d", $4/1048576}')
mem_gb=$(awk '/MemTotal/{printf "%.1f", $2/1048576}' /proc/meminfo 2>/dev/null)
if [ "${free_gb:-0}" -lt 5 ]; then warn "only ${free_gb} GB free on / - about 4 GB are needed (tools, voice model)"
else ok "${free_gb} GB free, ${mem_gb} GB of memory"; fi
local sp
sp=$(ssh_plan)
case "$sp" in
done) ok "SSH: logins by key only" ;;
apply) ok "SSH: this session uses a key - password logins will be turned off (open sessions stay connected; SSH_HARDEN=0 keeps them)" ;;
*) info "SSH: ${sp#skip:}" ;;
esac
if [ "$EXISTING" = 0 ]; then
ok "fresh server: nothing else runs here"
return 0
fi
info "this server is already in use - the installer adapts:"
if [ -n "$PUBLIC_OTHER" ]; then
warn "other services reachable from outside: $PUBLIC_OTHER"
fi
case "$FIREWALL:$FW_ACTIVE" in
add:ufw) ok "firewall: your ufw rules are kept - only the ports Harness Maxxing needs are added" ;;
add:*) ok "firewall: your $FW_ACTIVE rules are left as they are (open 80/443 yourself for a domain)" ;;
0:*) warn "firewall: not enabled, it could cut these services off (to force it: FIREWALL=1 install.sh --secure)" ;;
esac
[ "$HAS_DOCKER" = 1 ] && info "Docker found: its published ports bypass ufw - the firewall is left alone"
if [ -n "$WEB_BUSY" ]; then
warn "$WEB_BUSY already serves ports 80/443: Caddy is not installed; with a domain you get a ready-made"
warn "reverse-proxy block to paste into $WEB_BUSY (or pick tailscale / local)"
fi
[ -n "${PORT_MOVED_FROM:-}" ] && warn "port $PORT_MOVED_FROM is taken by another program: Harness Maxxing uses $PORT"
if [ "$SYSTEM_CLOCK" = keep ]; then
ok "server clock: left as it is ($(system_tz)) - your jobs still run at the times you choose"
fi
[ -n "$NODE_OLD" ] && ok "Node.js: your $NODE_OLD is kept, the pinned one goes to $STATE_DIR/tools/nodejs for Harness Maxxing only"
if [ -n "$CLAUDE_DIR" ]; then
ok "Claude Code folder for Harness Maxxing: $CLAUDE_DIR (your ~/.claude is not used nor touched)"
elif [ -n "$CLAUDE_SETUP" ]; then
ok "Claude Code already used on this server ($CLAUDE_SETUP): kept as it is"
if [ -f "$STATE_DIR/config.json" ]; then
info "Harness Maxxing already shares it - its setting is kept"
else
info "next question: give Harness Maxxing its own Claude Code folder, or share this one"
fi
fi
if [ -n "$BRIDGES" ]; then
warn "other Telegram bridge / agent running: $BRIDGES"
warn "give Harness Maxxing a NEW bot (BotFather): one bot token can only be read by one program"
fi
[ "$OTHER_CRON" = 1 ] && ok "your crontab lines are kept (Harness Maxxing only edits its own block)"
info "nothing else is touched: your files, services and settings stay as they are"
}
# ---- choices (asked up front, then everything runs unattended) ------------------------------
# Claude Code folder. Asked only when Claude Code is already used on this server (sign-in, skills, CLAUDE.md or
# conversations in ~/.claude) and Harness Maxxing is not installed yet: its own folder (default) keeps that setup
# untouched; sharing makes the existing skills and global instructions apply to Harness Maxxing sessions.
# An existing installation keeps its setting (switching would lose its sign-in and its conversations).
CLAUDE_DIR_DEFAULT_NAME=".claude-harness"
choose_claude_dir() {
[ -n "$CLAUDE_DIR" ] && return 0
if [ -f "$STATE_DIR/config.json" ]; then
CLAUDE_DIR=$(cfg_get claude_dir)
return 0
fi
[ -n "$CLAUDE_SETUP" ] || return 0
local own="$HOME/$CLAUDE_DIR_DEFAULT_NAME" n=1
if has_tty; then
echo " Claude Code is already used on this server ($CLAUDE_SETUP)."
printf ' %s1%s %sown folder%s %s - your ~/.claude is not touched %s(recommended)%s\n' "$C_A$C_B" "$C_0" "$C_B" "$C_0" "$own" "$C_G" "$C_0"
printf ' %s2%s %sshare%s ~/.claude - your skills, CLAUDE.md and sign-in also apply to Harness Maxxing\n' "$C_A$C_B" "$C_0" "$C_B" "$C_0"
ask CDIR "Choice (1/2)" "$n"
case "${CDIR:-$n}" in 2|share|shared) CLAUDE_DIR="" ;; *) CLAUDE_DIR=$own ;; esac
else
CLAUDE_DIR=$own
fi
if [ -n "$CLAUDE_DIR" ]; then
ok "Claude Code folder for Harness Maxxing: $CLAUDE_DIR (sign in again in the web setup; bring skills over later)"
else
ok "Claude Code folder shared with your existing setup (~/.claude)"
fi
}
# choose_source - where the code comes from: an existing install keeps its source; a new one uses a local copy
# (SOURCE_DIR / the folder of this script), otherwise the public git repository (no token: updates come from git).
# An install still on signed archives (before 2.0.0a87) keeps them until it moves to git by itself.
choose_source() {
if [ -d "$INSTALL_DIR/.git" ]; then
if [ -f "$STATE_DIR/secrets.json" ] && grep -q '"license_token"' "$STATE_DIR/secrets.json" 2>/dev/null; then LICENSED=1
elif [ -n "$SOURCE_DIR" ] || ! git -C "$INSTALL_DIR" remote get-url origin >/dev/null 2>&1; then LOCAL=1; fi
elif [ -z "$GH_TOKEN" ] && local_source; then
LOCAL=1
ok "code: the local copy in $SOURCE_DIR (no download - updates: a newer copy, then this again)"
else
ok "code: the git repository github.com/$REPO ($BRANCH) - updates come from git"
fi
}
choose_access() {
section "Setup"
local cur_url cur_bind def=local
cur_url=$(cfg_get public_url)
cur_bind=$(cfg_get bind)
if [ -z "$ACCESS" ]; then
case "$cur_url" in
https://*) def=domain; [ -n "$DOMAIN" ] || DOMAIN=$(printf '%s' "$cur_url" | sed -E 's#^https://([^/:]+).*#\1#') ;;
*) case "$cur_bind" in
100.*) def=tailscale ;;
*) if [ -z "$cur_url$cur_bind" ] && has_tty; then def=domain; fi ;;
esac ;;
esac
if has_tty; then
echo " How will you reach the web UI?"
if [ -n "$WEB_BUSY" ]; then
printf ' %s1%s %sdomain%s https://ui.example.com - through your %s (block to paste)\n' "$C_A$C_B" "$C_0" "$C_B" "$C_0" "$WEB_BUSY"
else
printf ' %s1%s %sdomain%s https://ui.example.com - automatic HTTPS %s(recommended)%s\n' "$C_A$C_B" "$C_0" "$C_B" "$C_0" "$C_G" "$C_0"
fi
printf ' %s2%s %stailscale%s http://<tailscale-ip>:%s - your Tailscale devices only\n' "$C_A$C_B" "$C_0" "$C_B" "$C_0" "$PORT"
printf ' %s3%s %slocal%s 127.0.0.1 only - through an SSH tunnel\n' "$C_A$C_B" "$C_0" "$C_B" "$C_0"
local n
case "$def" in domain) n=1 ;; tailscale) n=2 ;; *) n=3 ;; esac
ask ACC "Choice (1/2/3)" "$n"
case "${ACC:-$n}" in 1|domain) ACCESS=domain ;; 2|tailscale) ACCESS=tailscale ;; *) ACCESS=local ;; esac
else
ACCESS=$def
fi
fi
case "$ACCESS" in
domain)
ask DOMAIN "Domain name (its DNS A/AAAA record must point to this server)" ""
DOMAIN=$(printf '%s' "$DOMAIN" | sed -E 's#^https?://##; s#/.*$##' | tr '[:upper:]' '[:lower:]')
[ -n "$DOMAIN" ] || die "ACCESS=domain needs DOMAIN=ui.example.com"
valid_domain "$DOMAIN" || die "'$DOMAIN' is not a valid domain name (e.g. ui.example.com)"
PUBLIC_URL="https://$DOMAIN"; BIND=127.0.0.1 ;;
tailscale)
command -v tailscale >/dev/null 2>&1 || die "Tailscale is not installed: install it (https://tailscale.com/download/linux), run tailscale up, then this again"
BIND=$(tailscale ip -4 2>/dev/null | head -n1 || true)
[ -n "$BIND" ] || die "Tailscale is not connected (run: tailscale up)."
PUBLIC_URL="http://$BIND:$PORT"; AFTER=" tailscaled.service" ;;
local)
PUBLIC_URL=""; BIND=127.0.0.1 ;;
*) die "ACCESS must be domain, tailscale or local" ;;
esac
ok "access: $ACCESS${PUBLIC_URL:+ ($PUBLIC_URL)}, server bound to $BIND:$PORT"
if [ -z "$RESTORE_FROM" ] && [ ! -f "$WORKSPACE/memory.md" ] && has_tty; then
if ask_yn "Restore your memory from an existing Harness Maxxing GitHub backup?" n; then
ask RESTORE_FROM "Backup repository (owner/name)" ""
fi
fi
if [ -n "$RESTORE_FROM" ]; then
ask_secret RESTORE_TOKEN "GitHub token with read access to $RESTORE_FROM"
[ -n "$RESTORE_TOKEN" ] || die "RESTORE_FROM needs RESTORE_TOKEN"
ok "restore from $RESTORE_FROM after the installation"
fi
choose_claude_dir
if [ "$SSH_HARDEN" = auto ] && has_tty && [ "$(ssh_plan)" = apply ]; then
ask_yn "You are connected with an SSH key: turn SSH password logins off (open sessions stay connected)?" y || SSH_HARDEN=0
fi
case "$VOICE" in ""|off|local|groq|openai) ;; *) die "VOICE must be local, groq, openai or off" ;; esac
voice_memory_check
[ "$VOICE" = off ] || ok "voice messages: $VOICE (change it later in Settings -> Voice)"
choose_source
[ "$ACCESS" = domain ] && dns_check
SYS_TZ=$(system_tz)
[ -n "$TIMEZONE" ] || TIMEZONE=$(cfg_get timezone)
[ -n "$TIMEZONE" ] || TIMEZONE=$SYS_TZ # chosen in the web onboarding
if [ ! -d /usr/share/zoneinfo ] || [ ! -e /usr/share/zoneinfo/UTC ]; then # minimal images ship without tzdata
apt_get update -qq >/dev/null 2>&1; apt_get install -y -qq tzdata >/dev/null 2>&1 || true
fi
valid_tz "$TIMEZONE" || die "unknown time zone '$TIMEZONE' (see: timedatectl list-timezones)"
if [ "$TIMEZONE" != "$SYS_TZ" ] && [ "$SYSTEM_CLOCK" = keep ]; then
ok "time zone: $TIMEZONE (the server clock stays at $SYS_TZ, jobs follow your zone)"
elif [ "$TIMEZONE" != "$SYS_TZ" ]; then
ok "time zone: $TIMEZONE (the server clock is switched from $SYS_TZ so jobs fire at the times you see)"
else
ok "time zone: $TIMEZONE for now - you pick yours in the web onboarding"
fi
}
# local_source - a source tree to install: SOURCE_DIR, or the folder this script was run from (not the install itself)
local_source() {
if [ -n "$SOURCE_DIR" ]; then return 0; fi
[ -n "$SELF_DIR" ] && [ -f "$SELF_DIR/server/maxxing/__init__.py" ] && [ -f "$SELF_DIR/install.sh" ] || return 1
[ "$SELF_DIR" != "$(cd "$INSTALL_DIR" 2>/dev/null && pwd -P)" ] || return 1
safe_path SOURCE_DIR "$SELF_DIR"
SOURCE_DIR=$SELF_DIR
}
mem_mb() { awk '/MemTotal/{print int($2/1024)}' "$MEMINFO" 2>/dev/null || echo 0; }
swap_kb() { awk '/SwapTotal/{print $2}' "$MEMINFO" 2>/dev/null || echo 0; }
VOICE_MIN_MB=2800 # a "3 GB" server reports a bit less; local Whisper + a browser + Claude turns need that much
# voice_memory_check - local Whisper on a small server: off by default, refused unless confirmed
voice_memory_check() {
[ "$VOICE" = local ] || return 0
[ -f "$STATE_DIR/voice/extra-installed" ] && return 0 # chosen before on this server: kept
local m
m=$(mem_mb)
[ "${m:-0}" -ge "$VOICE_MIN_MB" ] && return 0
if [ -z "$VOICE_GIVEN" ]; then
VOICE=off
info "voice messages: off - local Whisper needs about 3 GB of memory, this server has ${m} MB (Settings -> Voice: Groq or OpenAI)"
return 0
fi
if has_tty; then
ask_yn "Local voice (Whisper) needs about 3 GB of memory and this server has ${m} MB - use it anyway?" n && return 0
VOICE=off; info "voice messages: off (Settings -> Voice: Groq or OpenAI)"; return 0
fi
die "VOICE=local needs about 3 GB of memory (this server: ${m} MB) - set VOICE=off, groq or openai, or run in a terminal to confirm"
}
# system_tz - the zone the cron daemon uses
system_tz() {
local z=""
z=$(timedatectl show -p Timezone --value 2>/dev/null || true)
[ -n "$z" ] || z=$(cat /etc/timezone 2>/dev/null || true)
[ -n "$z" ] || z=$(readlink /etc/localtime 2>/dev/null | sed 's#.*/zoneinfo/##' || true)
echo "${z:-UTC}"
}
# align_tz - cron fires in the system zone: make it equal to the configured one
align_tz() {
local cur
cur=$(system_tz)
[ "$TIMEZONE" = "$cur" ] && return 0
[ "$SYSTEM_CLOCK" = keep ] && return 0
if timedatectl set-timezone "$TIMEZONE" 2>/dev/null; then
systemctl restart cron >/dev/null 2>&1 || true
manifest "timezone $cur"
ok "system time zone set to $TIMEZONE (was $cur), cron restarted"
else
warn "could not set the system time zone - run: timedatectl set-timezone $TIMEZONE && systemctl restart cron"
fi
}
# ---- packages -------------------------------------------------------------------------------
# Checked first (nothing to do on a re-run when all of it is there). The base packages the next steps need (git, curl,
# python3...) are installed right away; the tool, browser and security ones in ONE background apt job, while the code,
# uv, Python and Claude Code are set up: apt_wait waits for it before anything else uses apt (Caddy, the security
# step). Each "a:b" entry takes the first name this release knows (Ubuntu 24.04 renamed libraries to *t64).
BASE_PKGS="git curl ca-certificates cron openssl python3 gnupg openssh-client xz-utils tzdata"
TOOL_PKGS="ffmpeg zip unzip jq ripgrep imagemagick poppler-utils"
SEC_PKGS="unattended-upgrades fail2ban python3-systemd"
BROWSER_PKGS="libnss3 libnspr4 libdbus-1-3 libatk1.0-0t64:libatk1.0-0 libatk-bridge2.0-0t64:libatk-bridge2.0-0 libgbm1
libasound2t64:libasound2 libxrandr2 libxkbcommon0 libxfixes3 libxcomposite1 libxdamage1 libdrm2 libpango-1.0-0
libcairo2 libcups2t64:libcups2 libatspi2.0-0t64:libatspi2.0-0 fonts-liberation fonts-noto-color-emoji"
pkg_installed() { dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q 'install ok installed'; }
pkg_known() { apt-cache show -q=0 "$1" >/dev/null 2>&1; }
APT_UPDATED=0
# ubuntu_universe - ffmpeg, jq, ripgrep, fail2ban... are in Ubuntu's universe component: turned on when an image
# shipped without it (otherwise every one of them silently fails)
ubuntu_universe() {
# shellcheck disable=SC1091
[ "$(. /etc/os-release 2>/dev/null && echo "${ID:-}")" = ubuntu ] || return 0
grep -rhsE '^[[:space:]]*(deb|Components:)' /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null | grep -w universe >/dev/null && return 0 # no -q: an early exit fails the pipe
local f=/etc/apt/sources.list.d/ubuntu.sources
if [ -f "$f" ] && grep -q '^Components:' "$f"; then
cp -p "$f" "$WORK/ubuntu.sources.bak"
sed -i -E '/^Components:/{/universe/!s/$/ universe/}' "$f"
manifest "universe enabled"
ok "Ubuntu's universe component turned on ($f)"
elif command -v add-apt-repository >/dev/null 2>&1; then
add-apt-repository -y universe >>"$WORK/apt.log" 2>&1 && manifest "universe enabled" && ok "Ubuntu's universe component turned on"
else
warn "Ubuntu's universe component is off: ffmpeg, jq, ripgrep, fail2ban may be missing (turn it on in /etc/apt/sources.list)"
fi
}
# apt_install PKG... - one apt-get install, without the recommended packages first (smaller), with them if that fails
apt_install() {
apt_get install -y -qq --no-install-recommends "$@" || apt_get install -y -qq "$@"
}
install_packages() {
local p n missing=() opt_missing=()
local wants_fw=0
ensure_swap # first: apt, uv and the Claude Code install then run side by side
[ "$FIREWALL" = 1 ] && ! systemd-detect-virt -cq 2>/dev/null && wants_fw=1
for p in $BASE_PKGS; do pkg_installed "$p" || missing+=("$p"); done
for p in $TOOL_PKGS $SEC_PKGS $BROWSER_PKGS $([ "$wants_fw" = 1 ] && echo ufw); do
for n in ${p//:/ }; do pkg_installed "$n" && continue 2; done
opt_missing+=("$p")
done
if [ ${#missing[@]} -eq 0 ] && [ ${#opt_missing[@]} -eq 0 ]; then
ok "system packages already installed"
else
ubuntu_universe
if [ ${#missing[@]} -gt 0 ]; then
apt_get update -qq >>"$WORK/apt.log" 2>&1 || warn "apt-get update reported errors (see below if something is missing)"
APT_UPDATED=1
apt_install "${missing[@]}" >>"$WORK/apt.log" 2>&1 || { tail -n 15 "$WORK/apt.log"; die "apt-get install failed"; }
ok "${#missing[@]} base package(s) installed"
fi
if [ ${#opt_missing[@]} -gt 0 ]; then
bg_start apt apt_tools "${opt_missing[@]}"
ok "${#opt_missing[@]} more (tools, browser libraries, security) installing in the background"
fi
fi
[ -n "${BG_PID[apt]:-}" ] || command -v ffmpeg >/dev/null 2>&1 \
|| warn "ffmpeg not installed: no video thumbnails in Files, no voice messages"
systemctl enable --now cron >/dev/null 2>&1 || warn "could not start the cron service"
}
# apt_tools ENTRY... - the background apt job: names this release knows, one install; skipped ones and the count
# are left in $WORK for apt_wait to report
apt_tools() {
local p n want=() skipped=()
[ "$APT_UPDATED" = 1 ] || apt_get update -qq || echo "apt-get update reported errors"
for p in "$@"; do
for n in ${p//:/ }; do
if pkg_known "$n"; then want+=("$n"); continue 2; fi
done
skipped+=("${p%%:*}")
done
printf '%s' "${skipped[*]}" > "$WORK/apt-skipped"
if [ ${#want[@]} -gt 0 ]; then apt_install "${want[@]}" || return 1; fi
printf '%s' "${#want[@]}" > "$WORK/apt-count"
}
# apt_wait - the background apt job is done (called before any other apt use, and by the security step); stops the
# install when it failed, like an apt failure in the foreground did
apt_wait() {
[ -n "${BG_PID[apt]:-}" ] || return 0
bg_wait apt || die "apt-get install failed (log above) - fix it, then run the same command again"
[ ! -s "$WORK/apt-skipped" ] || warn "not available on this system: $(cat "$WORK/apt-skipped")"
ok "$(cat "$WORK/apt-count" 2>/dev/null || echo 0) system package(s) installed in the background"
command -v ffmpeg >/dev/null 2>&1 || warn "ffmpeg not installed: no video thumbnails in Files, no voice messages"
}
# ensure_swap - a small server without swap is killed by the first big turn: 2 GB /swapfile under 4 GB of memory
ensure_swap() {
local m sw f=/swapfile free_mb
[ "$SWAP" = 0 ] && return 0
m=$(mem_mb); sw=$(swap_kb)
[ "${m:-0}" -lt 4096 ] && [ "${sw:-0}" -eq 0 ] || return 0
if [ "$SWAP" = auto ] && { [ "$EXISTING" = 1 ] || [ "$PRIOR" = 1 ]; }; then # a server in use: no swap may be deliberate
info "${m} MB of memory and no swap - SWAP=1 adds a 2 GB /swapfile"; return 0
fi
if systemd-detect-virt -cq 2>/dev/null; then