From cc35f7e0650c18fa08d996b49c9f9e90d8f856a9 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Tue, 4 Apr 2023 15:28:07 +0200
Subject: [PATCH] Add a script for configuring nvs

---
 scripts/Common/Config/NVS/install.sh   | 14 ++++++++++++++
 scripts/Common/Software/NVS/install.sh | 14 +++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)
 create mode 100755 scripts/Common/Config/NVS/install.sh

diff --git a/scripts/Common/Config/NVS/install.sh b/scripts/Common/Config/NVS/install.sh
new file mode 100755
index 00000000..a67af0d6
--- /dev/null
+++ b/scripts/Common/Config/NVS/install.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+NVS_HOME="${NVS_HOME:-'$HOME/.nvs'}";
+NVS_PATH="${NVS_PATH}";
+
+profilePath="/etc/profile.d/nvs-home.sh";
+
+{
+    echo "NVS_HOME=\"$NVS_HOME\"";
+    echo "source \"$NVS_PATH/nvs.sh\"";
+} | sudo tee "$profilePath" > /dev/null;
+
+source "$profilePath";
+nvs add latest;
+nvs link latest;
diff --git a/scripts/Common/Software/NVS/install.sh b/scripts/Common/Software/NVS/install.sh
index 76b7bbe0..faa798fc 100755
--- a/scripts/Common/Software/NVS/install.sh
+++ b/scripts/Common/Software/NVS/install.sh
@@ -1,7 +1,11 @@
 #!/bin/bash
-export NVS_HOME="$HOME/.nvs";
+pushd "${BASH_SOURCE%/*}" > /dev/null;
+home_expression='$HOME/.nvs';
+export NVS_HOME="$(bash -c echo $home_expression)";
 git clone https://github.com/jasongin/nvs "$NVS_HOME";
-# shellcheck source=~/.nvs/nvs.sh
-. "$NVS_HOME/nvs.sh" install;
-bash -c 'exec bash -c "nvs add latest"';
-bash -c 'exec bash -c "nvs link latest"';
+
+NVS_HOME="$home_expression" \
+NVS_PATH="$NVS_HOME" \
+    . "../../Config/NVS/install.sh";
+
+popd > /dev/null;