aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-08-04 12:21:05 +0200
committerFlorian Dold <florian@dold.me>2021-08-04 12:21:05 +0200
commitf92cbdbf476d4b51e1315ae26679008ae6889f60 (patch)
treeb18834dc724a03834862a7e323e5998a5863bb9f
parenta1235696778e2d1a3714fec2eeca9a1e628e333e (diff)
better default config location detection
-rw-r--r--packages/taler-util/src/talerconfig.ts30
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-libeufin-tutorial.ts1
2 files changed, 30 insertions, 1 deletions
diff --git a/packages/taler-util/src/talerconfig.ts b/packages/taler-util/src/talerconfig.ts
index 624d4ff3d..ebc418859 100644
--- a/packages/taler-util/src/talerconfig.ts
+++ b/packages/taler-util/src/talerconfig.ts
@@ -294,6 +294,26 @@ function normalizeInlineFilename(parentFile: string, f: string): string {
return nodejs_path().join(resolvedParentDir, f);
}
+/**
+ * Crude implementation of the which(1) shell command.
+ *
+ * Tries to locate the location of an executable based on the
+ * "PATH" environment variable.
+ */
+function which(name: string): string | undefined {
+ const paths = process.env["PATH"]?.split(":");
+ if (!paths) {
+ return undefined;
+ }
+ for (const path of paths) {
+ const filename = nodejs_path().join(path, name);
+ if (nodejs_fs().existsSync(filename)) {
+ return filename;
+ }
+ }
+ return undefined;
+}
+
export class Configuration {
private sectionMap: SectionMap = {};
@@ -614,6 +634,16 @@ export class Configuration {
private loadDefaults(): void {
let bc = process.env["TALER_BASE_CONFIG"];
if (!bc) {
+ /* Try to locate the configuration based on the location
+ * of the taler-config binary. */
+ const path = which("taler-config");
+ if (path) {
+ bc = nodejs_fs().realpathSync(
+ nodejs_path().dirname(path) + "/../share/taler/config.d",
+ );
+ }
+ }
+ if (!bc) {
bc = "/usr/share/taler/config.d";
}
this.loadFrom(bc);
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-libeufin-tutorial.ts b/packages/taler-wallet-cli/src/integrationtests/test-libeufin-tutorial.ts
index 59c9b28ad..707a264f0 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-libeufin-tutorial.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-libeufin-tutorial.ts
@@ -124,7 +124,6 @@ export async function runLibeufinTutorialTest(t: GlobalTestState) {
currency: "EUR",
facadeName: "my-twg",
});
-
await libeufinCli.listFacades();
}
runLibeufinTutorialTest.suites = ["libeufin"];