Skip to content
Python

install.sh: on Linux, install the openworker program from the release

Rohit C Prasad746cfb1b6dae
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index cd4687ac..2db9b7f7 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -179,6 +179,8 @@ jobs:
mkdir -p out
cp packaging/dist/openworker-*-linux-${{ matrix.arch }}.tar.gz* out/
cp packaging/dist/openworker-*-linux-${{ matrix.arch }}.tar.gz out/openworker-linux-${{ matrix.arch }}.tar.gz
+ # packaging/install.sh fetches the stable name for "latest" and checks it against this.
+ (cd out && sha256sum openworker-linux-${{ matrix.arch }}.tar.gz > openworker-linux-${{ matrix.arch }}.tar.gz.sha256)
ls -la out
- uses: actions/upload-artifact@v4
diff --git a/packaging/install.sh b/packaging/install.sh
index d874c2a7..de90dd95 100755
--- a/packaging/install.sh
+++ b/packaging/install.sh
@@ -3,13 +3,23 @@
#
# curl -fsSL https://openworker.com/install.sh | sh
#
-# Installs the `openworker` command for the current user (no sudo): it uses `uv` when present,
-# `pipx` when that is what the machine has, and otherwise installs `uv` first (uv brings its
-# own Python, so the system's Python version does not matter). Re-run it to upgrade.
+# Installs the `openworker` command for the current user (no sudo). Re-run it to upgrade.
+#
+# On Linux (x86_64, aarch64; glibc 2.31 or newer) it downloads the `openworker` program from
+# the GitHub release, checks its SHA-256, unpacks it into ~/.local/share/openworker and links
+# it into ~/.local/bin. No Python is needed.
+#
+# Elsewhere (macOS, other Linux) it installs the Python package: with `uv` when present,
+# `pipx` when that is what the machine has, and otherwise it installs `uv` first (uv brings
+# its own Python, so the system's Python version does not matter).
#
# Settings (environment variables):
-# OPENWORKER_VERSION install this exact version (default: the latest)
-# OPENWORKER_PACKAGE what to install (default: "openworker"; a wheel path or URL also works)
+# OPENWORKER_VERSION install this exact version (default: the latest)
+# OPENWORKER_INSTALL "program" or "python" to choose the route (default: automatic)
+# OPENWORKER_PACKAGE the Python route: what to install (default: "openworker";
+# a wheel path or URL also works)
+# OPENWORKER_DOWNLOAD_URL the program route: where the release files are (default: the
+# GitHub release; for mirrors and tests)
#
# The whole script is one function called on the last line, so a download that is cut off
# half-way runs nothing.
@@ -17,10 +27,7 @@
set -eu
main() {
- package="${OPENWORKER_PACKAGE:-openworker}"
- if [ -n "${OPENWORKER_VERSION:-}" ] && [ "$package" = "openworker" ]; then
- package="openworker==${OPENWORKER_VERSION}"
- fi
+ repo="https://github.com/andrewyng/openworker"
say() { printf '%s\n' "$*"; }
fail() { printf 'error: %s\n' "$*" >&2; exit 1; }
@@ -34,6 +41,111 @@ main() {
say "note: running as root installs OpenWorker for root only. A normal user account is the usual choice."
fi
+ route="${OPENWORKER_INSTALL:-}"
+ if [ -z "$route" ]; then
+ if [ -n "${OPENWORKER_PACKAGE:-}" ] || ! program_runs_here; then route="python"; else route="program"; fi
+ fi
+ case "$route" in
+ program) install_program ;;
+ python) install_python ;;
+ *) fail "OPENWORKER_INSTALL must be \"program\" or \"python\", not \"$route\"" ;;
+ esac
+
+ case ":${PATH}:" in
+ *":${bin_dir}:"*) ;;
+ *)
+ say ""
+ say "Add it to your PATH (then open a new terminal):"
+ say " export PATH=\"${bin_dir}:\$PATH\""
+ ;;
+ esac
+ say ""
+ say "Next:"
+ say " 1. In the OpenWorker app: Settings > Machines > Add a machine, and copy the join link."
+ say " 2. Here: openworker join <link>"
+ say " 3. To keep it running in the background: openworker machine service install"
+}
+
+# The program is built for Linux with glibc 2.31 or newer, on x86_64 and aarch64.
+program_runs_here() {
+ [ "$(uname -s)" = "Linux" ] || return 1
+ case "$(uname -m)" in x86_64 | aarch64) ;; *) return 1 ;; esac
+ glibc="$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')"
+ [ -n "$glibc" ] || return 1 # musl (Alpine) and other C libraries
+ major="${glibc%%.*}"
+ minor="${glibc#*.}"
+ minor="${minor%%.*}"
+ [ "$major" -gt 2 ] || { [ "$major" -eq 2 ] && [ "$minor" -ge 31 ]; }
+}
+
+install_program() {
+ arch="$(uname -m)"
+ command -v curl >/dev/null 2>&1 || fail "curl is needed to download OpenWorker. Install curl, then run this again."
+ command -v tar >/dev/null 2>&1 || fail "tar is needed to unpack OpenWorker."
+ if command -v sha256sum >/dev/null 2>&1; then
+ sha() { sha256sum "$1" | awk '{print $1}'; }
+ elif command -v shasum >/dev/null 2>&1; then
+ sha() { shasum -a 256 "$1" | awk '{print $1}'; }
+ else
+ fail "sha256sum (or shasum) is needed to check the download."
+ fi
+
+ if [ -n "${OPENWORKER_VERSION:-}" ]; then
+ file="openworker-${OPENWORKER_VERSION}-linux-${arch}.tar.gz"
+ base="${OPENWORKER_DOWNLOAD_URL:-$repo/releases/download/v${OPENWORKER_VERSION}}"
+ else
+ file="openworker-linux-${arch}.tar.gz" # the stable name of the latest release
+ base="${OPENWORKER_DOWNLOAD_URL:-$repo/releases/latest/download}"
+ fi
+
+ tmp="$(mktemp -d)"
+ trap 'rm -rf "$tmp"' EXIT
+ say "Downloading ${base}/${file}…"
+ curl -fL --progress-bar -o "$tmp/$file" "$base/$file" || fail "could not download $base/$file"
+ curl -fsSL -o "$tmp/$file.sha256" "$base/$file.sha256" || fail "could not download the checksum $base/$file.sha256"
+ expected="$(awk '{print $1}' "$tmp/$file.sha256")"
+ actual="$(sha "$tmp/$file")"
+ [ -n "$expected" ] && [ "$expected" = "$actual" ] || fail "the download does not match its checksum (expected ${expected:-nothing}, got $actual). Nothing was installed."
+ say "Checksum OK."
+
+ mkdir -p "$tmp/unpacked"
+ tar -xzf "$tmp/$file" -C "$tmp/unpacked"
+ [ -x "$tmp/unpacked/openworker/openworker" ] || fail "the download does not contain the openworker program. Nothing was installed."
+
+ # Swap the folder in whole. A running `openworker up` keeps the files it has open, and
+ # uses the new version once it is restarted.
+ data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
+ dest="$data_home/openworker"
+ bin_dir="${XDG_BIN_HOME:-$HOME/.local/bin}"
+ mkdir -p "$data_home" "$bin_dir"
+ rm -rf "$dest.new" "$dest.old"
+ mv "$tmp/unpacked/openworker" "$dest.new"
+ [ ! -e "$dest" ] || mv "$dest" "$dest.old"
+ mv "$dest.new" "$dest"
+ rm -rf "$dest.old"
+
+ link="$bin_dir/openworker"
+ if [ -e "$link" ] && [ ! -L "$link" ]; then
+ say "note: replacing the earlier $link (a Python install). Remove that install with \`uv tool uninstall openworker\` or \`pipx uninstall openworker\`."
+ fi
+ ln -sfn "$dest/openworker" "$link"
+
+ say ""
+ say "Installed: $("$link" version 2>&1 || true) in $dest"
+ if command -v systemctl >/dev/null 2>&1; then
+ units="$(systemctl --user list-units --all --plain --no-legend 'openworker-*.service' 2>/dev/null | awk '{print $1}')"
+ for unit in $units; do
+ say "Restart the running machine to use it: systemctl --user restart $unit"
+ done
+ fi
+}
+
+install_python() {
+ package="${OPENWORKER_PACKAGE:-openworker}"
+ if [ -n "${OPENWORKER_VERSION:-}" ] && [ "$package" = "openworker" ]; then
+ package="openworker==${OPENWORKER_VERSION}"
+ fi
+
if command -v uv >/dev/null 2>&1; then
installer="uv"
elif command -v pipx >/dev/null 2>&1; then
@@ -71,19 +183,6 @@ main() {
say ""
say "Installed: ${version_line}"
- case ":${PATH}:" in
- *":${bin_dir}:"*) ;;
- *)
- say ""
- say "Add it to your PATH (then open a new terminal):"
- say " export PATH=\"${bin_dir}:\$PATH\""
- ;;
- esac
- say ""
- say "Next:"
- say " 1. In the OpenWorker app: Settings > Machines > Add a machine, and copy the join link."
- say " 2. Here: openworker join <link>"
- say " 3. To keep it running in the background: openworker machine service install"
}
main "$@"