Files
openbot/scripts/install-server.sh
Aleksander DygońandClaude Opus 5.5 4579ff1c4c Give the service-user command when root cannot check the server control socket (#21971)
* Stop root openbot commands with a clear service-user command when ss cannot show the socket owner

On a kernel without unix_diag (for example Raspberry Pi OS), ss reads
/proc/net/unix and prints no "<->" and no "ino:" fields. check_listener
could then not match the pinned socket, so each root command and the
install claim stopped with "OpenBot does not answer" while OpenBot ran.

check_listener now tells this case apart: a LISTEN row for the control
socket in the /proc/net/unix form gives exit code 3. The command then
stops and gives the same command for the service user. The owner check
stays for all other cases, so root never sends a request to a socket
that it could not check. install-server.sh runs the claim and its status
requests as the service user only after this exit code. uninstall keeps
its "Remove the server in the app" text.

A council vote picked this option (B) over a path-only match and an
automatic switch to the service user.

Fixes #20504

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show the service-user command in readable quotes

The openbot command sets LC_ALL=C, so printf %q wrote a server name such
as "Büro Łódź" as $'B\303\274ro ...'. The command for the service user
now quotes only the words that need quotes, with ${word@Q} in a UTF-8
locale. Bash reads the text back to the same arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Let the install claim change to the service user at its first exit 3

Review fixes:
- When the first root status call fails for another reason, such as a
  slow first start, the claim login as root can still exit 3. The install
  now changes to the service user at that point. It does not show the root
  text then.
- The install script chooses the user again after the setup, so a new
  --user value is used.
- When the server is signed in, the install text gives the logout command
  for the service user when root cannot check the socket.
- The command hides the warning when the computer has no C.UTF-8 locale.
- The e2e test stops with a clear message when ss is not on PATH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:54:04 +01:00

184 lines
7.0 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
export LC_ALL=C DEBIAN_FRONTEND=noninteractive
RELEASES=https://github.com/nightly-labs/openbot/releases
OPENBOT=/usr/local/bin/openbot
service_user=""
auth_api_url=""
display_size=""
claim=${OPENBOT_CLAIM:-}
unset OPENBOT_CLAIM
server_name=""
fail() {
echo "$*" >&2
exit 1
}
fetch() {
curl --fail --location --proto '=https' --proto-redir '=https' --tlsv1.2 --silent --show-error --retry 3 "$@"
}
usage() {
cat <<'EOF'
Installs OpenBot as a self-hosted server on a Linux computer with no screen:
curl -fsSL https://raw.githubusercontent.com/nightly-labs/openbot/main/scripts/install-server.sh | sudo bash
Options (after `sudo bash -s --`):
--user <name> The user that runs OpenBot and its agents. Default: the user of the
installed server, else openbot, which the install makes when it does
not exist.
--auth-api-url <origin> Another account server, for development. Default: the one of the
installed server, else the one in the build.
--display-size <W>x<H> The size of the virtual display that computer use reads, from 640x480
to 2576x2576. Default: the one of the installed server, else 1280x800.
--name <name> The server name, with a claim. Default: OpenBot.
The command from the app (Add server, Other options, New server on another computer) puts a line
OPENBOT_CLAIM=<claim> before this script on standard input. The install then signs in with that
one-time claim, asks no questions, waits until the server is online, and ends with exit code 0
only when the server is connected. The claim is not an argument, because sudo logs its arguments.
This file only downloads the latest release and checks it against the release manifest, the
manifest that the Linux desktop updater reads. The install steps come from that release
(resources/hosting/openbot-server-setup), so they always match the build that they install.
See docs/self-hosted-server.md.
EOF
}
while [ "$#" -gt 0 ]; do
case $1 in
--user)
[ "$#" -ge 2 ] || fail "Add a user name after --user."
service_user=$2
shift 2
;;
--auth-api-url)
[ "$#" -ge 2 ] || fail "Add a URL after --auth-api-url."
auth_api_url=$2
shift 2
;;
--display-size)
[ "$#" -ge 2 ] || fail "Add a size, such as 1920x1080, after --display-size."
display_size=$2
shift 2
;;
--name)
[ "$#" -ge 2 ] || fail "Add a server name after --name."
server_name=$2
shift 2
;;
-h | --help)
usage
exit 0
;;
*) fail "Unknown option: $1" ;;
esac
done
[ -z "$server_name" ] || [ -n "$claim" ] || fail "Give --name only with the command from the app, or run: sudo openbot login --name <name>"
[ "$(uname -s)" = Linux ] || fail "This install is for Linux. Download the desktop app at https://openbot.run."
[ "$(id -u)" -eq 0 ] || fail "Run this with sudo."
[ -d /run/systemd/system ] || fail "OpenBot needs systemd."
command -v apt-get >/dev/null || fail "OpenBot needs Ubuntu 24.04 or a newer Ubuntu or Debian."
# shellcheck disable=SC1091
. /etc/os-release
if [ "${ID:-}" != ubuntu ] || [ "${VERSION_ID:-}" != 24.04 ]; then
echo "OpenBot is tested on Ubuntu 24.04. This is ${PRETTY_NAME:-an unknown system}; the install continues." >&2
fi
case $(uname -m) in
x86_64) architecture=x86_64 manifest=latest-linux.yml ;;
aarch64) architecture=arm64 manifest=latest-linux-arm64.yml ;;
*) fail "OpenBot has no release for this machine." ;;
esac
openbot_as=()
use_service_user() {
openbot_as=(runuser -u "$(cat /opt/OpenBot/hosted/service-user 2>/dev/null || echo openbot)" --)
}
claim_login() {
local code=0 errors
if [ "${#openbot_as[@]}" -eq 0 ]; then
{ errors=$(printf '%s\n' "$claim" | "$OPENBOT" login --claim "$@" 2>&1 >&3 3>&-); } 3>&1 || code=$?
if [ "$code" -ne 3 ]; then
[ -z "$errors" ] || printf '%s\n' "$errors" >&2
return "$code"
fi
use_service_user
fi
printf '%s\n' "$claim" | "${openbot_as[@]}" "$OPENBOT" login --claim "$@"
}
refuse_signed_in() {
local status code=0 logout="sudo openbot logout"
status=$("${openbot_as[@]}" "$OPENBOT" status 2>/dev/null) || code=$?
if [ "$code" -eq 3 ] && [ "${#openbot_as[@]}" -eq 0 ]; then
use_service_user
code=0
status=$("${openbot_as[@]}" "$OPENBOT" status 2>/dev/null) || code=$?
fi
[ "$code" -eq 0 ] || return 0
[ "${#openbot_as[@]}" -eq 0 ] || logout="sudo -u ${openbot_as[2]} -H openbot logout"
if grep -q '^Account: [^ ]*@' <<<"$status"; then
fail "This server is signed in to an account. To add it to another account, run \"$logout\" and then this command again."
fi
}
if [ -n "$claim" ] && [ -x "$OPENBOT" ]; then refuse_signed_in; fi
missing=()
for command in curl openssl; do command -v "$command" >/dev/null || missing+=("$command"); done
if [ "${#missing[@]}" -gt 0 ]; then
apt-get -o DPkg::Lock::Timeout=600 update
apt-get -o DPkg::Lock::Timeout=600 install -y --no-install-recommends ca-certificates "${missing[@]}"
fi
work=$(mktemp -d /var/tmp/openbot-install.XXXXXX)
trap 'rm -rf "$work"' EXIT
manifest=$(fetch "$RELEASES/latest/download/$manifest")
version=$(sed -n 's/^version: *//p' <<<"$manifest" | head -n 1)
path=$(sed -n 's/^path: *//p' <<<"$manifest" | head -n 1)
sha512=$(sed -n 's/^sha512: *//p' <<<"$manifest" | head -n 1)
[[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "The release manifest has no valid version."
[ "$path" = "OpenBot-$version-$architecture.AppImage" ] || fail "The release manifest names another file."
[[ $sha512 =~ ^[A-Za-z0-9+/]{86}==$ ]] || fail "The release manifest has no valid SHA-512."
echo "Downloading OpenBot $version..."
fetch --output "$work/OpenBot.AppImage" "$RELEASES/download/v$version/$path"
[ "$(openssl dgst -sha512 -binary "$work/OpenBot.AppImage" | openssl base64 -A)" = "$sha512" ] ||
fail "The download does not match the release manifest."
chmod 0700 "$work/OpenBot.AppImage"
(cd "$work" && ./OpenBot.AppImage --appimage-extract >/dev/null)
setup="$work/squashfs-root/resources/hosting/openbot-server-setup"
[ -f "$setup" ] || fail "OpenBot $version cannot install as a server. Try again after the next release."
if [ -n "$display_size" ] && ! grep -q OPENBOT_DISPLAY_SIZE "$setup"; then
fail "OpenBot $version has no --display-size. Install without it, or try again after the next release."
fi
bash "$setup" "$service_user" "$work/squashfs-root" "$auth_api_url" ${display_size:+"$display_size"}
openbot_as=()
if [ -n "$claim" ]; then
refuse_signed_in
echo
claim_login ${server_name:+--name "$server_name"}
status=$("${openbot_as[@]}" "$OPENBOT" status)
grep -q '^Server: \(.* (\)\{0,1\}online)\{0,1\}$' <<<"$status" ||
fail "The server is not online. Run \"openbot status\" and \"openbot logs\" to see why."
echo
echo "OpenBot is connected to your account."
exit 0
fi
cat <<'EOF'
Next, sign in with your OpenBot account:
sudo openbot login
Other commands: openbot status, openbot logs, sudo openbot update. Run "openbot help" for all.
EOF