76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "fs";
|
|
import { info } from "./gum.js";
|
|
import { authenticate, bulk, call } from "./mosyle.js";
|
|
|
|
let serialsTxt = "";
|
|
for await (const chunk of process.stdin) {
|
|
serialsTxt += chunk;
|
|
}
|
|
|
|
const serials = serialsTxt.split("\n").filter(Boolean);
|
|
|
|
const accessToken = process.env.MOSYLE_TOKEN;
|
|
|
|
info("Authenticating...");
|
|
const token = await authenticate(
|
|
process.env.MOSYLE_USER,
|
|
process.env.MOSYLE_PASSWORD,
|
|
accessToken,
|
|
);
|
|
|
|
info("Getting devices...");
|
|
const devices = await call(
|
|
"/listdevices",
|
|
{ accessToken, serial_number: serials, options: { os: "ios" } },
|
|
token,
|
|
)
|
|
.then((res) => res.json())
|
|
.then((j) =>
|
|
j.status == "OK"
|
|
? j.response.devices.map((d) => d.deviceudid)
|
|
: console.error(j),
|
|
);
|
|
|
|
info("Changing to limbo and wiping...");
|
|
console.log(
|
|
await (
|
|
await bulk(
|
|
{
|
|
accessToken,
|
|
elements: [
|
|
{
|
|
operation: "change_to_limbo",
|
|
devices,
|
|
},
|
|
{
|
|
operation: "wipe_devices",
|
|
devices,
|
|
options: {
|
|
PreserveDataPlan: "true",
|
|
DisallowProximitySetup: "true",
|
|
RevokeVPPLicenses: "true",
|
|
EnableReturnToService: "true",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
token,
|
|
)
|
|
).text(),
|
|
);
|
|
|
|
await info(
|
|
"To do more, paste this comma-separated list of serial numbers into the Mosyle search box:",
|
|
);
|
|
|
|
console.log(serials.join(","));
|
|
|
|
await info("Devices with available updates:");
|
|
|
|
await info(
|
|
devices
|
|
.filter((d) => d.AvailableOSUpdates.filter(Boolean).length > 0)
|
|
.map((d) => d.serial_number)
|
|
.join(","),
|
|
);
|