script for updating dns records on porkbun
1import { Command } from "commander";
2import { loadConfig } from "./config.js";
3import { runUpdate } from "./lib.js";
4import { getPaths } from "./utils.js";
5
6const program = new Command();
7
8program
9 .name("ddns")
10 .description("ddns")
11 .version("1.0.0")
12 .option("-c, --config <path>", "path to config file")
13 .option("-d, --domain <domain>", "domain to update")
14 .option("-k, --api-key <key>", "porkbun API Key")
15 .option("-s, --secret-api-key <secret>", "porkbun secret API Key")
16 .option(
17 "--ip <ips>",
18 "comma separated list of old IPs to look for (first run)",
19 )
20 .option("-f, --force", "force update even if IP hasn't changed")
21 .option("--dry-run", "simulate updates without changing records")
22 .option("--show-paths", "show where config and state files are stored")
23 .action(async (options) => {
24 if (options.showPaths) {
25 const paths = getPaths();
26 console.log("config File:", paths.configFile);
27 console.log("state File: ", paths.stateFile);
28 process.exit(0);
29 }
30
31 const cliConfig = {
32 apiKey: options.apiKey,
33 secretApiKey: options.secretApiKey,
34 domain: options.domain,
35 initialIps: options.ip ? options.ip.split(",") : undefined,
36 };
37
38 const config = await loadConfig(cliConfig, options.config);
39
40 try {
41 await runUpdate(config, {
42 force: options.force,
43 dryRun: options.dryRun,
44 });
45 } catch (error) {
46 console.error("error:");
47 console.error((error as Error).message);
48 process.exit(1);
49 }
50 });
51
52program.parse();