Skip to content

fix: improve script robustness and update service unit template handling#75

Merged
ZR233 merged 1 commit intomainfrom
fix-doc
Apr 2, 2026
Merged

fix: improve script robustness and update service unit template handling#75
ZR233 merged 1 commit intomainfrom
fix-doc

Conversation

@ZR233
Copy link
Copy Markdown
Member

@ZR233 ZR233 commented Apr 2, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 2, 2026 08:24
@ZR233 ZR233 merged commit 25db3c9 into main Apr 2, 2026
3 checks passed
@ZR233 ZR233 deleted the fix-doc branch April 2, 2026 08:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the ostool-server installer script to behave more robustly when executed in different contexts (local checkout vs. remote/pipe execution) and to adjust how the systemd unit template is obtained.

Changes:

  • Make script/unit-template path detection resilient when BASH_SOURCE doesn’t point to a normal on-disk file.
  • Replace the “download unit template from GitHub” fallback with an embedded systemd unit template.
  • Force reinstallation on cargo install to ensure reruns update/replace an existing install.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 84 to +96
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
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.
Comment on lines +90 to +112
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
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.
@github-actions github-actions bot mentioned this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants