-
Notifications
You must be signed in to change notification settings - Fork 10
fix: improve script robustness and update service unit template handling #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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="" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_unit_templateno longer downloads the unit template whenostool-server.serviceisn’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).