fostrom 0.0.20 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dl-agent.sh +22 -3
- package/index.js +7 -7
- package/package.json +1 -1
package/dl-agent.sh
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
#
|
|
5
5
|
# Usage: ./dl-agent.sh <directory>
|
|
6
6
|
|
|
7
|
-
VERSION="v0.0
|
|
7
|
+
VERSION="v0.1.0"
|
|
8
8
|
|
|
9
9
|
# CDN URLs in order of preference
|
|
10
10
|
CDN_PRIMARY="https://cdn.fostrom.dev/fostrom-device-agent/$VERSION"
|
|
@@ -135,6 +135,14 @@ install_binary() {
|
|
|
135
135
|
ln -sf "$FILENAME" "$INSTALL_DIR/fostrom-device-agent"
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
read_installed_version() {
|
|
139
|
+
BIN="$1"
|
|
140
|
+
[ ! -x "$BIN" ] && return 1
|
|
141
|
+
RAW_VERSION="$("$BIN" version 2>/dev/null || true)"
|
|
142
|
+
[ -z "$RAW_VERSION" ] && return 1
|
|
143
|
+
printf "%s\n" "$RAW_VERSION" | tr -d '[:space:]'
|
|
144
|
+
}
|
|
145
|
+
|
|
138
146
|
main() {
|
|
139
147
|
# Detect OS and architecture
|
|
140
148
|
OS="$(uname -s)"
|
|
@@ -165,9 +173,16 @@ main() {
|
|
|
165
173
|
|
|
166
174
|
FILENAME="fostrom-device-agent-${OS}-${ARCH}"
|
|
167
175
|
|
|
168
|
-
# Check if binary already exists
|
|
176
|
+
# Check if binary already exists and the version matches.
|
|
169
177
|
if [ -f "$LOCATION/$FILENAME" ]; then
|
|
170
|
-
|
|
178
|
+
INSTALLED_VERSION="$(read_installed_version "$LOCATION/$FILENAME" || true)"
|
|
179
|
+
if [ "$INSTALLED_VERSION" = "$VERSION" ]; then
|
|
180
|
+
# Ensure symlink exists even when reusing.
|
|
181
|
+
ln -sf "$FILENAME" "$LOCATION/fostrom-device-agent"
|
|
182
|
+
exit 0
|
|
183
|
+
fi
|
|
184
|
+
|
|
185
|
+
printf "Updating Fostrom Device Agent to %s...\n" "$VERSION"
|
|
171
186
|
fi
|
|
172
187
|
|
|
173
188
|
printf "Downloading Fostrom Device Agent...\n"
|
|
@@ -179,6 +194,10 @@ main() {
|
|
|
179
194
|
xattr -r -d com.apple.quarantine "$LOCATION/$FILENAME" 2>/dev/null || true
|
|
180
195
|
fi
|
|
181
196
|
|
|
197
|
+
INSTALLED_VERSION="$(read_installed_version "$LOCATION/$FILENAME" || true)"
|
|
198
|
+
[ "$INSTALLED_VERSION" = "$VERSION" ] || die \
|
|
199
|
+
"Fatal: Installed Version Mismatch (expected $VERSION, got ${INSTALLED_VERSION:-unknown})"
|
|
200
|
+
|
|
182
201
|
printf "Fostrom Device Agent downloaded successfully\n"
|
|
183
202
|
}
|
|
184
203
|
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFileSync } from "child_process"
|
|
2
2
|
import { fileURLToPath } from "url"
|
|
3
3
|
import path from "path"
|
|
4
4
|
import http from "node:http"
|
|
@@ -109,18 +109,18 @@ export default class Fostrom {
|
|
|
109
109
|
env["FOSTROM_RUNTIME_ENV"] = String(this.#runtimeEnv)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const args = ["start"]
|
|
113
|
-
|
|
114
112
|
try {
|
|
115
|
-
const output =
|
|
113
|
+
const output = execFileSync(agent_path(), ["start"], { encoding: "utf8", env })
|
|
116
114
|
const out = output.trim()
|
|
117
115
|
if (out.startsWith("started:")) return
|
|
118
116
|
if (out.startsWith("already_started:")) return
|
|
119
117
|
return
|
|
120
118
|
} catch (error) {
|
|
121
119
|
const out = (error.stdout || "").toString().trim()
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
const err = (error.stderr || "").toString().trim()
|
|
121
|
+
const text = out || err
|
|
122
|
+
if (text) {
|
|
123
|
+
const [atom, rest] = text.split(":", 2)
|
|
124
124
|
throw new FostromError(atom || "failed", (rest || "Failed to start Device Agent").trim())
|
|
125
125
|
}
|
|
126
126
|
throw new FostromError("failed", "Failed to start Device Agent")
|
|
@@ -167,7 +167,7 @@ export default class Fostrom {
|
|
|
167
167
|
|
|
168
168
|
static stopAgent() {
|
|
169
169
|
try {
|
|
170
|
-
|
|
170
|
+
execFileSync(agent_path(), ["stop"], { encoding: "utf8" })
|
|
171
171
|
} catch (e) {
|
|
172
172
|
console.error("[Fostrom] Failed to stop the Fostrom Device Agent")
|
|
173
173
|
}
|