Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·673 lines (559 loc) · 20 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·673 lines (559 loc) · 20 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
#!/bin/sh
# Overridden variables from Go template: {{.Overrides}}
# Pairing mode (empty TENANT_ID) is only supported by the container methods in
# agent mode; every other path still requires a tenant.
require_tenant() {
[ -z "$TENANT_ID" ] && {
echo "ERROR: TENANT_ID is required for this installation method."
exit 1
}
}
# Installs the shellhub-agent wrapper that proxies commands into the agent
# container. The agent itself cannot open the host's browser from inside the
# container, so for 'login' the wrapper scans the output for the accept-device
# URL and opens it on the host; native (non-container) agents open it directly.
install_agent_wrapper() {
_RUNTIME="$1"
_FSUDO=""
[ "$(id -u)" -ne 0 ] && _FSUDO="sudo"
WRAPPER_PATH="${INSTALL_DIR:-/usr/local/bin}/shellhub-agent"
if ! cat <<EOF | $_FSUDO tee "$WRAPPER_PATH" > /dev/null
#!/bin/sh
_containers=\$($_RUNTIME ps --filter label=shellhub.role=agent --format '{{.Names}}')
if [ -z "\$_containers" ]; then
echo "shellhub-agent: no running agent container found" >&2
echo "Start the agent or run 'install.sh uninstall' to remove this wrapper" >&2
exit 1
fi
if [ "\$(printf '%s\n' "\$_containers" | wc -l)" -gt 1 ]; then
echo "shellhub-agent: multiple agent containers found, stop all but one:" >&2
printf '%s\n' "\$_containers" | sed 's/^/ /' >&2
exit 1
fi
if [ "\$1" = "login" ] && command -v xdg-open > /dev/null 2>&1; then
_STATUS_FILE=\$(mktemp)
trap 'rm -f "\$_STATUS_FILE"' EXIT
{ $_RUNTIME exec "\$_containers" agent "\$@" 2>&1; echo \$? > "\$_STATUS_FILE"; } | while IFS= read -r _LINE; do
printf '%s\n' "\$_LINE"
case "\$_LINE" in
*"/accept-device?code="*)
_URL=\$(printf '%s' "\$_LINE" | tr -d ' ')
{ xdg-open "\$_URL" > /dev/null 2>&1 && printf '%s\n' "(opened in your browser)"; } &
;;
esac
done
read -r _CODE < "\$_STATUS_FILE" || _CODE=1
exit "\${_CODE:-1}"
fi
exec $_RUNTIME exec "\$_containers" agent "\$@"
EOF
then
echo "❌ Failed to install shellhub-agent wrapper at $WRAPPER_PATH."
exit 1
fi
$_FSUDO chmod +x "$WRAPPER_PATH"
echo "✅ Installed shellhub-agent wrapper at $WRAPPER_PATH."
}
# Enrolls a freshly installed agent. Without a tenant the device does not belong
# to any namespace yet, so we run the login flow in the foreground: it prints the
# accept URL (opening the browser when possible) and waits until a user accepts
# the device into a namespace — no second command, no pending list to dig
# through. With a tenant (fleet install) the device shows up pending and is
# accepted in the console as before.
#
# $1: command that runs the agent, invoked as "<cmd> login". For container
# methods this is the wrapper (which execs into the container); for native
# methods it is the agent binary itself, possibly prefixed with sudo.
# $2: host-visible path of the agent key to wait for before pairing.
enroll_agent_interactively() {
_AGENT_CMD="$1"
_WAIT_KEY="$2"
if [ -n "$CODE" ]; then
echo ""
echo "The device is pre-authorized and will be accepted automatically once it connects."
return 0
fi
if [ -n "$INSTALL_KEY" ]; then
echo ""
echo "The device will be accepted automatically via the install key."
return 0
fi
if [ -n "$TENANT_ID" ]; then
echo ""
echo "The device will appear as pending in the console — accept it there."
return 0
fi
# Wait for the agent to generate its key so the login flow reuses it instead
# of racing the daemon to create one.
_i=0
while [ "$_i" -lt 30 ] && [ ! -f "$_WAIT_KEY" ]; do
sleep 1
_i=$((_i + 1))
done
echo ""
$_AGENT_CMD login || true
}
podman_install() {
[ -n "${KEEPALIVE_INTERVAL}" ] && ARGS="$ARGS -e SHELLHUB_KEEPALIVE_INTERVAL=$KEEPALIVE_INTERVAL"
[ -n "${PREFERRED_HOSTNAME}" ] && ARGS="$ARGS -e SHELLHUB_PREFERRED_HOSTNAME=$PREFERRED_HOSTNAME"
[ -n "${PREFERRED_IDENTITY}" ] && ARGS="$ARGS -e SHELLHUB_PREFERRED_IDENTITY=$PREFERRED_IDENTITY"
[ -n "${CODE}" ] && ARGS="$ARGS -e SHELLHUB_PAIRING_CODE=$CODE"
[ -n "${INSTALL_KEY}" ] && ARGS="$ARGS -e SHELLHUB_INSTALL_KEY=$INSTALL_KEY"
if [ -n "$AGENT_IMAGE_OVERRIDDEN" ]; then
echo "📦 Using image $AGENT_IMAGE (skipping pull)..."
else
echo "📥 Downloading ShellHub container image..."
{
$SUDO podman pull -q "$AGENT_IMAGE"
} || {
echo "❌ Failed to download shellhub container image."
exit 1
}
fi
MODE=""
DEFAULT_CONTAINER_NAME="shellhub"
case "$1" in
"") ;;
"agent")
shift 1
;;
"connector")
require_tenant
MODE="connector"
DEFAULT_CONTAINER_NAME="shellhub-connector"
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEYS=${PRIVATE_KEYS:-/host/etc/shellhub/connector/keys}"
ARGS="$ARGS -e SHELLHUB_CONNECTOR_LABEL=${CONNECTOR_LABEL}"
echo "🚀 Starting ShellHub container in Docker Connector mode..."
shift 1
;;
*)
echo "❌ Invalid mode: $2"
exit 1
;;
esac
if [ -z "$MODE" ]; then
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEY=${PRIVATE_KEY:-/host/etc/shellhub.key}"
echo "🚀 Starting ShellHub container in Agent mode..."
fi
CONTAINER_NAME="${CONTAINER_NAME:-$DEFAULT_CONTAINER_NAME}"
LABEL_ARGS=""
[ -z "$MODE" ] && LABEL_ARGS="--label shellhub.role=agent"
$SUDO podman run -d \
--name=$CONTAINER_NAME \
--replace \
--restart=on-failure \
--privileged \
--pid=host \
--security-opt label=disable \
--network host \
-v /:/host \
-v /dev:/dev \
-v /var/run/podman/podman.sock:/var/run/docker.sock \
-v /proc:/proc \
-v /var/run:/var/run \
-v /var/log:/var/log \
-v /tmp:/tmp \
-e SHELLHUB_SERVER_ADDRESS=$SERVER_ADDRESS \
-e SHELLHUB_TENANT_ID=$TENANT_ID \
$ARGS \
$LABEL_ARGS \
"$AGENT_IMAGE" \
$MODE
if [ -z "$MODE" ]; then
install_agent_wrapper "podman"
# The key path is under /host (the agent mounts the host root there); strip
# that prefix so the installer waits on the real host path.
_CKEY="${PRIVATE_KEY:-/host/etc/shellhub.key}"
enroll_agent_interactively "$WRAPPER_PATH" "${_CKEY#/host}"
fi
}
docker_install() {
[ -n "${KEEPALIVE_INTERVAL}" ] && ARGS="$ARGS -e SHELLHUB_KEEPALIVE_INTERVAL=$KEEPALIVE_INTERVAL"
[ -n "${PREFERRED_HOSTNAME}" ] && ARGS="$ARGS -e SHELLHUB_PREFERRED_HOSTNAME=$PREFERRED_HOSTNAME"
[ -n "${PREFERRED_IDENTITY}" ] && ARGS="$ARGS -e SHELLHUB_PREFERRED_IDENTITY=$PREFERRED_IDENTITY"
[ -n "${CODE}" ] && ARGS="$ARGS -e SHELLHUB_PAIRING_CODE=$CODE"
[ -n "${INSTALL_KEY}" ] && ARGS="$ARGS -e SHELLHUB_INSTALL_KEY=$INSTALL_KEY"
if [ -n "$AGENT_IMAGE_OVERRIDDEN" ]; then
echo "📦 Using image $AGENT_IMAGE (skipping pull)..."
else
echo "📥 Downloading ShellHub container image..."
{
docker pull -q "$AGENT_IMAGE"
} || {
echo "❌ Failed to download shellhub container image."
exit 1
}
fi
MODE=""
DEFAULT_CONTAINER_NAME="shellhub"
case "$1" in
"") ;;
"agent")
shift 1
;;
"connector")
require_tenant
MODE="connector"
DEFAULT_CONTAINER_NAME="shellhub-connector"
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEYS=${PRIVATE_KEYS:-/host/etc/shellhub/connector/keys}"
ARGS="$ARGS -e SHELLHUB_CONNECTOR_LABEL=${CONNECTOR_LABEL}"
echo "🚀 Starting ShellHub container in Docker Connector mode..."
shift 1
;;
*)
echo "❌ Invalid mode: $2"
exit 1
;;
esac
if [ -z "$MODE" ]; then
ARGS="$ARGS -e SHELLHUB_PRIVATE_KEY=${PRIVATE_KEY:-/host/etc/shellhub.key}"
echo "🚀 Starting ShellHub container in Agent mode..."
fi
CONTAINER_NAME="${CONTAINER_NAME:-$DEFAULT_CONTAINER_NAME}"
LABEL_ARGS=""
[ -z "$MODE" ] && LABEL_ARGS="--label shellhub.role=agent"
# Remove any existing container so the new one gets the shellhub.role=agent label.
$SUDO docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
$SUDO docker run -d \
--name=$CONTAINER_NAME \
--restart=on-failure \
--privileged \
--net=host \
--pid=host \
-v /:/host \
-v /dev:/dev \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/resolv.conf:/etc/resolv.conf \
-v /var/run:/var/run \
-v /var/log:/var/log \
-v /tmp:/tmp \
-e SHELLHUB_SERVER_ADDRESS=$SERVER_ADDRESS \
-e SHELLHUB_TENANT_ID=$TENANT_ID \
$ARGS \
$LABEL_ARGS \
"$AGENT_IMAGE" \
$MODE
if [ -z "$MODE" ]; then
install_agent_wrapper "docker"
# The key path is under /host (the agent mounts the host root there); strip
# that prefix so the installer waits on the real host path.
_CKEY="${PRIVATE_KEY:-/host/etc/shellhub.key}"
enroll_agent_interactively "$WRAPPER_PATH" "${_CKEY#/host}"
fi
}
snap_install() {
require_tenant
if ! type snap >/dev/null 2>&1; then
echo "❌ Snap is not installed or not supported on this system."
exit 1
fi
echo "📥 Downloading ShellHub snap package..."
{
sudo snap install --classic --channel=latest/stable shellhub
} || {
echo "❌ Failed to download and install ShellHub snap package."
exit 1
}
echo "🚀 Starting ShellHub snap service..."
{
if [ -n "${PREFERRED_HOSTNAME}" ]; then
sudo snap set shellhub preferred-hostname="${PREFERRED_HOSTNAME}"
fi
if [ -n "${PREFERRED_IDENTITY}" ]; then
sudo snap set shellhub preferred-identity="${PREFERRED_IDENTITY}"
fi
if [ -n "${KEEPALIVE_INTERVAL}" ]; then
sudo snap set shellhub keepalive-interval="${KEEPALIVE_INTERVAL}"
fi
sudo snap set shellhub server-address="$SERVER_ADDRESS"
sudo snap set shellhub tenant-id="$TENANT_ID"
sudo snap set shellhub private-key="${PRIVATE_KEY:-/etc/shellhub.key}"
sudo snap start shellhub
} || {
echo "❌ Failed to start ShellHub snap service."
exit 1
}
}
standalone_install() {
if [ "$(id -u)" -ne 0 ]; then
printf "⚠️ NOTE: This install method requires root privileges.\n"
SUDO="sudo"
fi
INSTALL_BIN="$INSTALL_DIR/shellhub-agent"
$SUDO mkdir -p "$INSTALL_DIR"
if [ -n "${AGENT_BINARY}" ]; then
echo "📂 Using local binary: $AGENT_BINARY"
$SUDO cp "$AGENT_BINARY" "$INSTALL_BIN"
$SUDO chmod 755 "$INSTALL_BIN"
else
echo "📥 Downloading ShellHub agent binary..."
{
download "https://github.com/shellhub-io/shellhub/releases/download/$AGENT_VERSION/shellhub-agent-linux-$BINARY_ARCH.gz" "$TMP_DIR/shellhub-agent.gz"
} || { rm -rf "$TMP_DIR" && echo "❌ Failed to download agent binary." && exit 1; }
echo "📂 Extracting binary..."
gzip -d "$TMP_DIR/shellhub-agent.gz"
chmod 755 "$TMP_DIR/shellhub-agent"
$SUDO mv "$TMP_DIR/shellhub-agent" "$INSTALL_BIN"
fi
echo "🚀 Installing ShellHub system service..."
INSTALL_ARGS="--server-address=$SERVER_ADDRESS --tenant-id=$TENANT_ID"
[ -n "${PREFERRED_HOSTNAME}" ] && INSTALL_ARGS="$INSTALL_ARGS --preferred-hostname=$PREFERRED_HOSTNAME"
[ -n "${PREFERRED_IDENTITY}" ] && INSTALL_ARGS="$INSTALL_ARGS --preferred-identity=$PREFERRED_IDENTITY"
[ -n "${KEEPALIVE_INTERVAL}" ] && INSTALL_ARGS="$INSTALL_ARGS --keepalive-interval=$KEEPALIVE_INTERVAL"
$SUDO "$INSTALL_BIN" install $INSTALL_ARGS || {
echo "❌ Failed to install ShellHub agent service."
$SUDO rm -f "$INSTALL_BIN"
exit 1
}
echo "✅ ShellHub agent installed and started."
# Native install: the binary is the command and opens the browser itself, so
# no wrapper is needed — enroll by invoking it directly. Reads the root-owned
# key, hence $SUDO.
enroll_agent_interactively "$SUDO $INSTALL_BIN" "${PRIVATE_KEY:-/etc/shellhub.key}"
rm -rf "$TMP_DIR"
}
docker_uninstall() {
_FSUDO=""
[ "$(id -u)" -ne 0 ] && _FSUDO="sudo"
SUDO="${SUDO:-$_FSUDO}"
CONTAINER_NAME="${CONTAINER_NAME:-shellhub}"
echo "🗑️ Stopping and removing ShellHub container..."
$SUDO docker rm -f "$CONTAINER_NAME" 2>/dev/null || echo "⚠️ Container '$CONTAINER_NAME' not found (may already be removed)."
WRAPPER_PATH="${INSTALL_DIR:-/usr/local/bin}/shellhub-agent"
if [ -f "$WRAPPER_PATH" ]; then
echo "🗑️ Removing shellhub-agent wrapper..."
$_FSUDO rm -f "$WRAPPER_PATH"
fi
echo "✅ ShellHub agent uninstalled."
echo "ℹ️ The private key file was left in place. Remove it manually if no longer needed."
}
podman_uninstall() {
_FSUDO=""
[ "$(id -u)" -ne 0 ] && _FSUDO="sudo"
SUDO="${SUDO:-$_FSUDO}"
CONTAINER_NAME="${CONTAINER_NAME:-shellhub}"
echo "🗑️ Stopping and removing ShellHub container..."
$SUDO podman rm -f "$CONTAINER_NAME" 2>/dev/null || echo "⚠️ Container '$CONTAINER_NAME' not found (may already be removed)."
WRAPPER_PATH="${INSTALL_DIR:-/usr/local/bin}/shellhub-agent"
if [ -f "$WRAPPER_PATH" ]; then
echo "🗑️ Removing shellhub-agent wrapper..."
$_FSUDO rm -f "$WRAPPER_PATH"
fi
echo "✅ ShellHub agent uninstalled."
echo "ℹ️ The private key file was left in place. Remove it manually if no longer needed."
}
standalone_uninstall() {
if [ "$(id -u)" -ne 0 ]; then
printf "⚠️ NOTE: This operation requires root privileges.\n"
SUDO="sudo"
fi
INSTALL_BIN="$INSTALL_DIR/shellhub-agent"
if [ ! -f "$INSTALL_BIN" ]; then
echo "❌ ShellHub agent binary not found at $INSTALL_BIN."
exit 1
fi
echo "🗑️ Stopping and removing ShellHub agent service..."
$SUDO "$INSTALL_BIN" uninstall || {
echo "⚠️ Service uninstall reported an error (it may already be removed)."
}
echo "🗑️ Removing ShellHub agent binary..."
$SUDO rm -f "$INSTALL_BIN"
echo "✅ ShellHub agent uninstalled."
echo "ℹ️ The private key file was left in place. Remove it manually if no longer needed."
}
wsl_install() {
if ! systemctl show-environment >/dev/null 2>&1; then
printf "❌ ERROR: This install method requires systemd to be enabled.\n"
printf "Please refer to the following link for instructions on how to enable systemd:\n"
printf "https://learn.microsoft.com/en-us/windows/wsl/wsl-config#systemd-support\n"
printf "Once systemd is enabled, run this script again to complete the installation.\n"
exit 1
fi
if [ "$(wslinfo --networking-mode)" != "mirrored" ]; then
printf "❌ ERROR: WSL networking mode must be set to mirrored.\n"
printf "Please refer to the following link for instructions on how to set the networking mode:\n"
printf "https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking\n"
printf "Once the networking mode is set to mirrored, run this script again to complete the installation.\n"
exit 1
fi
standalone_install
}
download() {
_DOWNLOAD_URL=$1
_DOWNLOAD_OUTPUT=$2
if type curl >/dev/null 2>&1; then
curl -fsSL $_DOWNLOAD_URL --output $_DOWNLOAD_OUTPUT
elif type wget >/dev/null 2>&1; then
wget -q -O $_DOWNLOAD_OUTPUT $_DOWNLOAD_URL
fi
}
http_get() {
_HTTP_GET_URL=$1
if type curl >/dev/null 2>&1; then
curl -sk $_HTTP_GET_URL
elif type wget >/dev/null 2>&1; then
wget -q -O - $_HTTP_GET_URL
fi
}
if [ "$(uname -s)" = "FreeBSD" ]; then
echo "👹 This system is running FreeBSD."
echo "❌ ERROR: Automatic installation is not supported on FreeBSD."
echo
echo "Please refer to the ShellHub port at https://github.com/shellhub-io/ports"
exit 1
fi
# TENANT_ID is optional for the container methods: without it the agent boots
# into pairing mode and is enrolled into a namespace via 'shellhub-agent login'.
# Snap and standalone installs still require it (checked in their functions).
SERVER_ADDRESS="${SERVER_ADDRESS:-https://cloud.shellhub.io}"
TENANT_ID="${TENANT_ID}"
INSTALL_METHOD="$INSTALL_METHOD"
AGENT_VERSION="${AGENT_VERSION:-$(http_get $SERVER_ADDRESS/info | sed -E 's/.*"version":\s?"?([^,"]*)"?.*/\1/')}"
[ -n "$AGENT_IMAGE" ] && AGENT_IMAGE_OVERRIDDEN="1"
AGENT_IMAGE="${AGENT_IMAGE:-docker.io/shellhubio/agent:$AGENT_VERSION}"
BINARY_ARCH="$BINARY_ARCH"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
TMP_DIR="${TMP_DIR:-$(mktemp -d -t shellhub-installer-XXXXXX)}"
# Auto detect arch if it has not already been set
if [ -z "$BINARY_ARCH" ]; then
case $(uname -m) in
x86_64)
BINARY_ARCH=amd64
;;
armv6l)
BINARY_ARCH=armv6
;;
armv7l)
BINARY_ARCH=armv7
;;
aarch64)
BINARY_ARCH=arm64
;;
i386|i486|i586|i686)
BINARY_ARCH=386
;;
esac
fi
echo "🛠️ ShellHub Agent Installer"
echo
if [ -z "$INSTALL_METHOD" ]; then
echo "This script will install the ShellHub agent on your system."
echo "It will auto-detect the best available installation method."
echo
echo "Installation methods (priority order):"
echo " 1. Docker - If Docker is installed and accessible in rootful mode"
echo " 2. Podman - If Podman is installed and accessible in rootful mode"
echo " 3. Snap - If Snap package manager is available"
echo " 4. WSL - If running in WSL2 with systemd and mirrored networking"
echo " 5. Standalone - Native binary with systemd"
echo
fi
echo "⚙️ Detected settings:"
echo "- Server address: $SERVER_ADDRESS"
echo "- Tenant ID: ${TENANT_ID:-(none — enroll with 'shellhub-agent login')}"
echo "- Agent version: $AGENT_VERSION"
echo "- Architecture: $BINARY_ARCH"
[ -n "$INSTALL_METHOD" ] && echo "- Install method: $INSTALL_METHOD"
echo
if [ -z "$INSTALL_METHOD" ] && type docker >/dev/null 2>&1; then
echo "🔍 Checking if Docker is available and accessible in rootful mode..."
export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}"
for prefix in "" "sudo"; do
if $prefix docker info >/dev/null 2>&1; then
SUDO=$prefix
INSTALL_METHOD="docker"
break
fi
done
[ -z "$INSTALL_METHOD" ] && echo "ℹ️ Docker is not accessible in rootful mode."
fi
if [ -z "$INSTALL_METHOD" ] && type podman >/dev/null 2>&1; then
echo "🔍 Checking if Podman is available and accessible in rootful mode..."
export CONTAINER_HOST="${CONTAINER_HOST:-unix:///var/run/podman/podman.sock}"
for prefix in "" "sudo"; do
if $prefix podman info >/dev/null 2>&1; then
SUDO=$prefix
INSTALL_METHOD="podman"
break
fi
done
[ -z "$INSTALL_METHOD" ] && echo "ℹ️ Podman is not accessible in rootful mode."
fi
if [ -z "$INSTALL_METHOD" ]; then
echo
echo "⚠️ NOTE: No recommended installation method was detected."
echo "⚠️ For best performance, easier updates, and better isolation, it is strongly recommended to use Docker or Podman."
echo "ℹ️ The installer will proceed with an alternative method (Snap, Standalone, or WSL), but these may have limitations."
echo
fi
if [ -z "$INSTALL_METHOD" ] && type snap >/dev/null 2>&1; then
echo "🔍 Detected Snap package manager..."
INSTALL_METHOD="snap"
fi
# Check if running on WSL
if grep -qi Microsoft /proc/version; then
echo "🔍 Detected WSL environment..."
WSL_EXE=$(find /mnt/*/Windows/System32/wsl.exe 2>/dev/null | head -n 1)
WSL_VERSION=$($WSL_EXE -v | tr -d '\0' | grep "WSL version" | awk -F'[ .:]+' '{print $3}')
if [ -z "$WSL_VERSION" ] || [ "$WSL_VERSION" -lt 2 ]; then
echo "❌ ERROR: WSL version 2 is required to run ShellHub."
exit 1
fi
if grep -qi 'NAME="Ubuntu"' /etc/os-release; then
INSTALL_METHOD="wsl"
else
echo "❌ Error: Only Ubuntu is supported in WSL."
exit 1
fi
fi
[ -z "$INSTALL_METHOD" ] && INSTALL_METHOD="standalone"
case "$1" in
uninstall)
case "$INSTALL_METHOD" in
standalone|wsl)
echo "🗑️ Uninstalling ShellHub using standalone method..."
standalone_uninstall
;;
docker)
echo "🐳 Uninstalling ShellHub using docker method..."
docker_uninstall
;;
podman)
echo "🐳 Uninstalling ShellHub using podman method..."
podman_uninstall
;;
*)
echo "❌ Uninstall is not yet supported for '$INSTALL_METHOD' install method."
exit 1
;;
esac
;;
*)
case "$INSTALL_METHOD" in
podman)
echo "🐳 Installing ShellHub using podman method..."
podman_install "$@"
;;
docker)
echo "🐳 Installing ShellHub using docker method..."
docker_install "$@"
;;
snap)
echo "📦 Installing ShellHub using snap method..."
snap_install
;;
standalone)
echo "🐧 Installing ShellHub using standalone method..."
standalone_install
;;
wsl)
echo "🪟 Installing ShellHub using WSL method..."
wsl_install
;;
*)
echo "❌ Install method not supported."
exit 1
;;
esac
;;
esac