diff --git a/Scripts/lsblk.ts b/Scripts/lsblk.ts new file mode 100644 index 0000000..a5d1bbd --- /dev/null +++ b/Scripts/lsblk.ts @@ -0,0 +1,8 @@ + +fetch('https://html.affirm.duckdns.org/lsblk.json') + .then((res:any) => res.text()) + .then((text:any) => { + const data = JSON.parse(text); + console.log(data); + }) + .catch((e:any) => console.error(e)); \ No newline at end of file diff --git a/Scripts/podman.ts b/Scripts/podman.ts new file mode 100644 index 0000000..2f2376e --- /dev/null +++ b/Scripts/podman.ts @@ -0,0 +1,115 @@ +const server = 'jmlc'; +let debug: Array = []; +let warning: Array = []; +let volumes: Array = []; +let volumeExportLines: Array = []; +const pathA = 'L:/Git/AA/.vscode/helper/podman.txt'; + +await fetch(`https://html.${server}.duckdns.org/root.txt`) + .then((res: any) => res.text()) + .then((text: any) => { + const lines = text.trim().split('\n'); + for (let index = 0; index < lines.length; index++) { + const element = lines[index]; + if (element == undefined || element.length === 0 || element[0] === '#' || !element.includes('podman volume export')) { + continue; + } + volumeExportLines.push(`${server}: root: ${element}`); + debug.push(`${server}: volume [${element}] is exported.`); + } + }) + .catch((e: any) => console.error(e)); + +await fetch(`https://html.${server}.duckdns.org/podman.txt`) + .then((res: any) => res.text()) + .then((text: any) => { + const lines = text.trim().split('\n'); + for (let index = 0; index < lines.length; index++) { + const element = lines[index]; + if (element == undefined || element.length === 0 || element[0] === '#' || !element.includes('podman volume export')) { + continue; + } + volumeExportLines.push(`${server}: podman: ${element}`); + debug.push(`${server}: volume [${element}] is exported.`); + } + }) + .catch((e: any) => console.error(e)); + +await fetch(`https://html.${server}.duckdns.org/images-dangling-false.jsonl`) + .then((res: any) => res.text()) + .then((text: any) => { + const json = '[' + text.trim().split('\n').join(',') + ']'; + const data = JSON.parse(json); + for (let index = 0; index < data.length; index++) { + const element = data[index]; + debug.push(`${server}: image ${element.Name} is in use.`); + } + }) + .catch((e: any) => console.error(e)); + +await fetch(`https://html.${server}.duckdns.org/volumes-dangling-false.jsonl`) + .then((res: any) => res.text()) + .then((text: any) => { + const json = '[' + text.trim().split('\n').join(',') + ']'; + const data = JSON.parse(json); + for (let index = 0; index < data.length; index++) { + const element = data[index]; + volumes.push(element.Name); + debug.push(`${server}: volume [${element.Name}] is in use.`); + } + }) + .catch((e: any) => console.error(e)); + +await fetch(`https://html.${server}.duckdns.org/containers.jsonl`) + .then((res: any) => res.text()) + .then((text: any) => { + const json = '[' + text.trim().split('\n').join(',') + ']'; + const data = JSON.parse(json); + for (let index = 0; index < data.length; index++) { + const element = data[index]; + debug.push(`${server}: container [${element.Name}] is in use.`); + } + }) + .catch((e: any) => console.error(e)); + +for (let index = 0; index < volumes.length; index++) { + let check: boolean = false; + const volumeExportLine: string | any = volumes[index]; + volumeExportLines.forEach(element => { + if (element.includes(volumeExportLine)) { + check = true; + } + }); + if (check) { + debug.push(`${server}: volume [${volumes[index]}] is being exported.`); + } + else { + warning.push(`${server}: ## 11 * * * podman volume export ${volumes[index]} --output /home/podman/cron-backup/${server}-${volumes[index]}-$(date +"\%Y-\%m-\%d--\%H-\%M-\%S").tar`); + } +} + +await fetch(`https://html.${server}.duckdns.org/volumes-dangling-true.jsonl`) + .then((res: any) => res.text()) + .then((text: any) => { + const json = '[' + text.trim().split('\n').join(',') + ']'; + const data = JSON.parse(json); + for (let index = 0; index < data.length; index++) { + const element = data[index]; + debug.push(`${server}: podman volume rm ${element.Name}`); + } + }) + .catch((e: any) => console.error(e)); + +await fetch(`https://html.${server}.duckdns.org/images-dangling-true.jsonl`) + .then((res: any) => res.text()) + .then((text: any) => { + const json = '[' + text.trim().split('\n').join(',') + ']'; + const data = JSON.parse(json); + for (let index = 0; index < data.length; index++) { + const element = data[index]; + debug.push(`${server}: podman image rm ${element.ID}`); + } + }) + .catch((e: any) => console.error(e)); + +await Bun.write(pathA, `${debug.join('\n')}\n${warning.join('\n')}`); \ No newline at end of file diff --git a/package.json b/package.json index d5e4f0f..31d3703 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "adaptation", - "module": "index.ts", - "type": "module", - "private": true, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5" - }, - "scripts": { - "garbage-collect": "git gc" - } -} \ No newline at end of file + "name": "adaptation", + "module": "index.ts", + "type": "module", + "private": true, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5" + }, + "scripts": { + "garbage-collect": "git gc" + } +} diff --git a/tsconfig.json b/tsconfig.json index bfa0fea..dd276fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { // Environment setup & latest features - "lib": ["ESNext"], + "lib": ["dom", "ESNext"], "target": "ESNext", "module": "Preserve", "moduleDetection": "force",