Files
dokploy/server/setup/config-paths.ts
Lorenzo Migliorero bda0689e18 fix: ssh permission
2024-07-26 10:11:38 +02:00

54 lines
1.0 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { chmodSync, existsSync, mkdirSync } from "node:fs";
import {
APPLICATIONS_PATH,
BASE_PATH,
CERTIFICATES_PATH,
DYNAMIC_TRAEFIK_PATH,
LOGS_PATH,
MAIN_TRAEFIK_PATH,
MONITORING_PATH,
SSH_PATH,
} from "../constants";
const createDirectoryIfNotExist = (dirPath: string) => {
if (!existsSync(dirPath)) {
mkdirSync(dirPath, { recursive: true });
console.log(`Directory created: ${dirPath}`);
}
};
export const setupDirectories = () => {
const directories = [
BASE_PATH,
MAIN_TRAEFIK_PATH,
DYNAMIC_TRAEFIK_PATH,
LOGS_PATH,
APPLICATIONS_PATH,
SSH_PATH,
CERTIFICATES_PATH,
MONITORING_PATH,
];
for (const dir of directories) {
try {
createDirectoryIfNotExist(dir);
if (dir === SSH_PATH) {
/* Changing SSH Keys permission to 600 keeping the SSH folder writable */
spawnSync("find", [
SSH_PATH,
"-type",
"f",
"-exec",
"chmod",
"600",
"{}",
";",
]);
}
} catch (error) {
console.log(error, " On path: ", dir);
}
}
};