Skip to content

Commit 22525a2

Browse files
committed
feat(install): add OPENSHELL_INSTALL_METHOD options
As @drew suggested, add `deb`, `rpm`, `snap`, and `homebrew` as installation methods which the user can specify via `OPENSHELL_INSTALL_METHOD` rather than falling back to detecting the package manager automatically. `homebrew` is not yet supported on Linux, and it is the only supported option on MacOS. Also adds a TODO to implement `install_linux_homebrew` in the future. Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
1 parent 4bd8a05 commit 22525a2

3 files changed

Lines changed: 186 additions & 9 deletions

File tree

‎docs/about/installation.mdx‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ On distributions that ship with `snapd`, the install script uses the Snap path
5858
described below, unless one of the following is true:
5959
- a native (non-snap) Docker package is present (the `openshell` snap requires the `docker` snap, for now)
6060
- `snapd` is not present
61-
- `OPENSHELL_INSTALL_METHOD=classic` is set in the environment
61+
- `OPENSHELL_INSTALL_METHOD` is set in the environment to some value other than `snap` (e.g. `OPENSHELL_INSTALL_METHOD=deb`)
6262

6363
On Fedora and RHEL, the install script uses RPM packages. The RPM installs the `openshell` CLI, the `openshell-gateway` daemon, and a systemd user service.
6464

@@ -188,8 +188,25 @@ Use the `openshell` `.deb` or `.rpm` file when `snapd` is unavailable or when
188188
you already run Docker from a non-snap source. The installer falls back to
189189
these methods on hosts with native Docker.
190190

191-
Set `OPENSHELL_INSTALL_METHOD=classic` to force the classic package on hosts
192-
that also have `snapd` available.
191+
### Force an install method
192+
193+
Set `OPENSHELL_INSTALL_METHOD` to force a specific install method instead of
194+
relying on auto-detection. Supported values:
195+
196+
| Value | Install path |
197+
|---|---|
198+
| `deb` | Debian package via `apt`/`dpkg` |
199+
| `rpm` | RPM package via `dnf`/`yum`/`zypper`/`rpm` |
200+
| `snap` | Snap package via `snapd` |
201+
| `homebrew` | Homebrew formula via `brew` (macOS only; not yet supported on Linux) |
202+
203+
When the variable is unset, the script auto-detects the host package manager
204+
as described above. If the requested method's package manager is not
205+
installed, the installer aborts with an error.
206+
207+
```shell
208+
curl -LsSf https://raw.githubusercontent.com/NVIDIA/OpenShell/main/install.sh | OPENSHELL_INSTALL_METHOD=deb sh
209+
```
193210

194211
## Kubernetes
195212

‎install.sh‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ OPTIONS:
5151
ENVIRONMENT VARIABLES:
5252
OPENSHELL_VERSION Release tag to install (default: latest tagged release).
5353
Set OPENSHELL_VERSION=dev to install the rolling dev build.
54+
OPENSHELL_INSTALL_METHOD
55+
Force a specific install method. Supported values:
56+
deb, rpm, snap, homebrew. When unset, the script
57+
auto-detects the host package manager.
5458
OPENSHELL_ACK_BREAKING_UPGRADE
5559
Set to 1 only after backing up and cleaning up a
5660
pre-v0.0.37 installation.
@@ -478,17 +482,32 @@ detect_platform() {
478482

479483
linux_package_method() {
480484
case "${OPENSHELL_INSTALL_METHOD:-}" in
481-
classic)
485+
"")
486+
;;
487+
snap)
488+
echo "snap"
489+
return 0
490+
;;
491+
deb|apt)
492+
echo "deb"
493+
return 0
494+
;;
495+
rpm|dnf|yum|zypper)
496+
echo "rpm"
497+
return 0
498+
;;
499+
homebrew|brew)
500+
echo "homebrew"
501+
return 0
482502
;;
483503
*)
484-
if has_snapd && ! has_native_docker; then
485-
echo "snap"
486-
return 0
487-
fi
504+
error "OPENSHELL_INSTALL_METHOD='${OPENSHELL_INSTALL_METHOD}' is not supported; use one of: deb, rpm, snap, homebrew"
488505
;;
489506
esac
490507

491-
if has_cmd dpkg; then
508+
if has_snapd && ! has_native_docker; then
509+
echo "snap"
510+
elif has_cmd dpkg; then
492511
echo "deb"
493512
elif has_cmd rpm; then
494513
echo "rpm"
@@ -974,6 +993,7 @@ install_linux_rpm() {
974993
}
975994

976995
install_linux_snap() {
996+
require_cmd snap
977997
set_linux_target_runtime_dir
978998

979999
# Docker snap must be installed before openshell so that the
@@ -1133,12 +1153,24 @@ main() {
11331153
require_linux_package_glibc
11341154
install_linux_rpm
11351155
;;
1156+
homebrew)
1157+
# TODO: implement install_linux_homebrew for Linuxbrew hosts
1158+
# (e.g. Universal Blue/Bazzite). Homebrew is accepted as a method
1159+
# value but not yet wired to an installer on Linux.
1160+
error "the 'homebrew' install method is not yet supported on Linux"
1161+
;;
11361162
*)
11371163
error "unsupported Linux package method"
11381164
;;
11391165
esac
11401166
;;
11411167
darwin)
1168+
case "${OPENSHELL_INSTALL_METHOD:-}" in
1169+
""|homebrew|brew) ;;
1170+
*)
1171+
error "only the 'homebrew' install method is supported on macOS"
1172+
;;
1173+
esac
11421174
install_macos_homebrew
11431175
;;
11441176
*)

‎tasks/scripts/test-install-sh.sh‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,132 @@ assert_glibc_preflight_fails \
100100
"OpenShell Linux packages require glibc >= 2.28; detected musl or unsupported libc." \
101101
setup_ldd_musl
102102

103+
assert_method_equals() {
104+
local name=$1
105+
local value=$2
106+
local expected=$3
107+
108+
local result
109+
if ! result="$(OPENSHELL_INSTALL_METHOD="$value" linux_package_method)" 2>"$err"; then
110+
echo "FAIL: ${name}: expected '${expected}' but call failed" >&2
111+
cat "$err" >&2 || true
112+
exit 1
113+
fi
114+
115+
if [ "$result" != "$expected" ]; then
116+
echo "FAIL: ${name}: expected '${expected}', got '${result}'" >&2
117+
exit 1
118+
fi
119+
}
120+
121+
assert_method_fails() {
122+
local name=$1
123+
local value=$2
124+
local expected=$3
125+
126+
if (OPENSHELL_INSTALL_METHOD="$value" linux_package_method) >"$out" 2>"$err"; then
127+
echo "FAIL: ${name}: expected failure for value '${value}'" >&2
128+
exit 1
129+
fi
130+
131+
if ! grep -Fq "$expected" "$err"; then
132+
echo "FAIL: ${name}: missing expected message" >&2
133+
echo "Expected: ${expected}" >&2
134+
echo "Actual:" >&2
135+
cat "$err" >&2 || true
136+
exit 1
137+
fi
138+
}
139+
140+
assert_method_equals "method deb passes through" "deb" "deb"
141+
assert_method_equals "method rpm passes through" "rpm" "rpm"
142+
assert_method_equals "method snap passes through" "snap" "snap"
143+
assert_method_equals "method homebrew passes through" "homebrew" "homebrew"
144+
145+
assert_method_equals "alias apt maps to deb" "apt" "deb"
146+
assert_method_equals "alias dnf maps to rpm" "dnf" "rpm"
147+
assert_method_equals "alias yum maps to rpm" "yum" "rpm"
148+
assert_method_equals "alias zypper maps to rpm" "zypper" "rpm"
149+
assert_method_equals "alias brew maps to homebrew" "brew" "homebrew"
150+
151+
assert_method_fails \
152+
"unknown method fails" \
153+
"apk" \
154+
"is not supported; use one of: deb, rpm, snap, homebrew"
155+
156+
assert_method_fails \
157+
"classic method fails" \
158+
"classic" \
159+
"is not supported; use one of: deb, rpm, snap, homebrew"
160+
161+
# Unset OPENSHELL_INSTALL_METHOD falls through to host detection. Shim the
162+
# has_* helpers so the auto-detect path is deterministic regardless of the
163+
# host running the tests.
164+
assert_method_unset_detects() {
165+
local name=$1
166+
local snapd=$2
167+
local native_docker=$3
168+
local dpkg=$4
169+
local rpm=$5
170+
local expected=$6
171+
172+
local result
173+
if ! result="$(
174+
unset OPENSHELL_INSTALL_METHOD
175+
has_snapd() { [ "$snapd" = "1" ]; }
176+
has_native_docker() { [ "$native_docker" = "1" ]; }
177+
has_cmd() {
178+
case "$1" in
179+
dpkg) [ "$dpkg" = "1" ] ;;
180+
rpm) [ "$rpm" = "1" ] ;;
181+
*) return 1 ;;
182+
esac
183+
}
184+
linux_package_method
185+
)" 2>"$err"; then
186+
echo "FAIL: ${name}: call failed" >&2
187+
cat "$err" >&2 || true
188+
exit 1
189+
fi
190+
191+
if [ "$result" != "$expected" ]; then
192+
echo "FAIL: ${name}: expected '${expected}', got '${result}'" >&2
193+
exit 1
194+
fi
195+
}
196+
197+
assert_method_unset_detects \
198+
"unset prefers snap when snapd and no native docker" \
199+
1 0 1 1 "snap"
200+
201+
assert_method_unset_detects \
202+
"unset skips snap when native docker present" \
203+
1 1 1 0 "deb"
204+
205+
assert_method_unset_detects \
206+
"unset skips snap when snapd absent" \
207+
0 0 1 0 "deb"
208+
209+
assert_method_unset_detects \
210+
"unset falls back to rpm when no dpkg" \
211+
0 0 0 1 "rpm"
212+
213+
# Unset with no snapd, no dpkg, no rpm must error.
214+
if (
215+
unset OPENSHELL_INSTALL_METHOD
216+
has_snapd() { return 1; }
217+
has_native_docker() { return 1; }
218+
has_cmd() { return 1; }
219+
linux_package_method
220+
) >"$out" 2>"$err"; then
221+
echo "FAIL: unset with no package managers should error" >&2
222+
exit 1
223+
fi
224+
225+
if ! grep -Fq "Linux installs require either dpkg or rpm" "$err"; then
226+
echo "FAIL: missing no-package-manager error" >&2
227+
cat "$err" >&2 || true
228+
exit 1
229+
fi
230+
103231
echo "install.sh libc preflight tests passed"

0 commit comments

Comments
 (0)