Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions ostool-server/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_SOURCE="${BASH_SOURCE[0]:-}"
if [[ -n "${SCRIPT_SOURCE}" && -f "${SCRIPT_SOURCE}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_SOURCE}")" && pwd)"
else
SCRIPT_DIR=""
fi

SERVICE_NAME="ostool-server"
UNIT_FILE="${SCRIPT_DIR}/${SERVICE_NAME}.service"
UNIT_FILE=""
if [[ -n "${SCRIPT_DIR}" ]]; then
UNIT_FILE="${SCRIPT_DIR}/${SERVICE_NAME}.service"
fi
CONFIG_DIR="/etc/${SERVICE_NAME}"
DATA_DIR="/var/lib/${SERVICE_NAME}"
CONFIG_FILE="${CONFIG_DIR}/config.toml"
SYSTEM_BIN_DIR="/usr/local/bin"
SYSTEM_BIN_PATH="${SYSTEM_BIN_DIR}/${SERVICE_NAME}"
REMOTE_SCRIPT_BASE_URL="${OSTOOL_SERVER_SCRIPT_BASE_URL:-https://raw.githubusercontent.com/drivercraft/ostool/main/ostool-server/scripts}"

LOCAL_PATH=""

Expand Down Expand Up @@ -74,26 +82,34 @@ run_cmd() {
}

load_unit_template() {
if [[ -f "${UNIT_FILE}" ]]; then
if [[ -n "${UNIT_FILE}" && -f "${UNIT_FILE}" ]]; then
cat "${UNIT_FILE}"
return 0
fi

local remote_unit_url="${REMOTE_SCRIPT_BASE_URL}/${SERVICE_NAME}.service"
echo "Local service template not found, downloading: ${remote_unit_url}" >&2

if command -v curl >/dev/null 2>&1; then
curl -fsSL "${remote_unit_url}"
return 0
fi

if command -v wget >/dev/null 2>&1; then
wget -qO- "${remote_unit_url}"
return 0
fi

echo "Neither curl nor wget is available to download ${remote_unit_url}" >&2
return 1
cat <<'EOF'
[Unit]
Description=OSTool Board Server
After=network.target

[Service]
Type=simple
Comment on lines 84 to +96
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_unit_template no longer downloads the unit template when ostool-server.service isn’t present locally (it now falls back to an embedded template). The repository README currently states that remote execution will download the matching service template from GitHub; that documentation should be updated to match the new behavior (or the download fallback reintroduced if that behavior is still desired).

Copilot uses AI. Check for mistakes.
ExecStart=__BIN_PATH__ --config /etc/ostool-server/config.toml
Restart=on-failure
RestartSec=5
WorkingDirectory=/var/lib/ostool-server

ReadWritePaths=/etc/ostool-server /var/lib/ostool-server /srv/tftp
ProtectHome=true
PrivateTmp=true

StandardOutput=journal
StandardError=journal
SyslogIdentifier=ostool-server

[Install]
WantedBy=multi-user.target
EOF
Comment on lines +90 to +112
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The systemd unit template is now duplicated: once in scripts/ostool-server.service and again as an embedded heredoc fallback here. This increases the chance the two templates drift over time (e.g., when updating sandboxing or paths). Consider making one source-of-truth (e.g., generate/embed the .service file content into install.sh during release/build, or keep a download fallback) so changes only need to be made in one place.

Suggested change
cat <<'EOF'
[Unit]
Description=OSTool Board Server
After=network.target
[Service]
Type=simple
ExecStart=__BIN_PATH__ --config /etc/ostool-server/config.toml
Restart=on-failure
RestartSec=5
WorkingDirectory=/var/lib/ostool-server
ReadWritePaths=/etc/ostool-server /var/lib/ostool-server /srv/tftp
ProtectHome=true
PrivateTmp=true
StandardOutput=journal
StandardError=journal
SyslogIdentifier=ostool-server
[Install]
WantedBy=multi-user.target
EOF
echo "Error: systemd unit template file not found at: ${UNIT_FILE:-<unset>}" >&2
echo "Please run this installer from a distribution that includes '${SERVICE_NAME}.service' alongside install.sh." >&2
return 1

Copilot uses AI. Check for mistakes.
}

render_unit_file() {
Expand Down Expand Up @@ -172,10 +188,10 @@ if [[ -n "$LOCAL_PATH" ]]; then
fi
LOCAL_PATH="$(cd "$LOCAL_PATH" && pwd)"
echo "Installing from local source: ${LOCAL_PATH}"
cargo install --path "${LOCAL_PATH}"
cargo install --force --path "${LOCAL_PATH}"
else
echo "Installing from crates.io..."
cargo install "${SERVICE_NAME}"
cargo install --force "${SERVICE_NAME}"
fi

BIN_SOURCE="$(command -v "${SERVICE_NAME}" || true)"
Expand Down
Loading