Conversation
There was a problem hiding this comment.
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_SOURCEdoesn’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 installto ensure reruns update/replace an existing install.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
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).
| 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 |
There was a problem hiding this comment.
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.
| 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 |
No description provided.