65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
|
#!/usr/bin/env -S /root/.deno/bin/deno run --allow-env --allow-read --unstable --allow-sys --allow-run --allow-write
|
||
|
import {load} from "https://deno.land/std@0.214.0/dotenv/mod.ts";
|
||
|
import { Command } from "https://deno.land/x/cliffy@v0.25.7/mod.ts";
|
||
|
|
||
|
async function changeTextRecord(domain: string, token:string, text: string){
|
||
|
const url = `https://www.duckdns.org/update?domains=${domain}&token=${token}&txt=${text}`
|
||
|
const res = await fetch(url);
|
||
|
const c = await res.text()
|
||
|
return c === "OK"
|
||
|
}
|
||
|
|
||
|
|
||
|
const env = await load();
|
||
|
const domain = env.DUCKDNS_DOMAIN;
|
||
|
const token = env.DUCKDNS_TOKEN;
|
||
|
/*
|
||
|
sudo certbot certonly --manual --preferred-challenges dns --renew-by-default -d "*.pages.prelude.duckdns.org"
|
||
|
*/
|
||
|
if(import.meta.main){
|
||
|
if (!domain || !token){
|
||
|
console.log("Env not found!");
|
||
|
Deno.exit(1);
|
||
|
}
|
||
|
|
||
|
//const cmd = new Deno.Command("certbot",{
|
||
|
// args:[
|
||
|
// "certonly",
|
||
|
// "--manual",
|
||
|
// "--preferred-challenges",
|
||
|
// "dns",
|
||
|
// "--renew-by-default",
|
||
|
// "-d", "*.pages.prelude.duckdns.org"
|
||
|
// ],
|
||
|
// stdin: "piped",
|
||
|
// stdout: "piped",
|
||
|
//});
|
||
|
//
|
||
|
//const proc = cmd.spawn();
|
||
|
//await proc.stdout.pipeTo(Deno.stdout.writable);
|
||
|
|
||
|
await new Command()
|
||
|
.name("renew_dns")
|
||
|
.description("Duckdns TXT Record renewer")
|
||
|
.version("v1.0.0")
|
||
|
.option("-q, --quiet", "disable output.")
|
||
|
.arguments("<text>")
|
||
|
.action(async ({quiet},text)=>{
|
||
|
const s = await changeTextRecord(domain, token, text);
|
||
|
if (s) {
|
||
|
if (!quiet){
|
||
|
console.log("success!");
|
||
|
}
|
||
|
Deno.exit(0);
|
||
|
}
|
||
|
else {
|
||
|
if(!quiet){
|
||
|
console.log("failed!");
|
||
|
}
|
||
|
Deno.exit(1);
|
||
|
}
|
||
|
})
|
||
|
.parse(Deno.args);
|
||
|
|
||
|
}
|