Skip to content

Commit

Permalink
Merge pull request #251 from dappnode/pablo/create-init-file
Browse files Browse the repository at this point in the history
Create vars file if does not exist
  • Loading branch information
pablomendezroyo authored Jan 22, 2024
2 parents 58e61dd + f6ccbae commit f768e82
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/src/createVarsFileIfNotExist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from "fs";
import path from "path";
import { logs } from "./logs";
import { OPENVPN } from "./params";

export function createVarsFileIfNotExist(): void {
try {
// Get the environment variables
const easyrsaVarsFile = path.join(OPENVPN, "vars");
const varsExamplePath = "/usr/share/easy-rsa/vars.example";

// Check if the EASYRSA_VARS_FILE exists
if (!fs.existsSync(easyrsaVarsFile)) {
// Copy vars.example if it exists, else create an empty vars file
if (fs.existsSync(varsExamplePath))
fs.copyFileSync(varsExamplePath, easyrsaVarsFile);
else fs.writeFileSync(easyrsaVarsFile, "");
}
} catch (e) {
logs.error("Error creating vars file", e);
}
}
4 changes: 4 additions & 0 deletions src/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { initalizeOpenVpnConfig, openvpnBinary } from "./openvpn";
import { config } from "./config";
import { startCredentialsService } from "./credentials";
import { logs } from "./logs";
import { createVarsFileIfNotExist } from "./createVarsFileIfNotExist";

// Print version data
printGitData();

// Create /etc/openvpn/vars file if it doesn't exist
createVarsFileIfNotExist();

// Start JSON RPC API
startHttpApi(API_PORT);

Expand Down

0 comments on commit f768e82

Please sign in to comment.