From 44be482846c438b766cc223843bf7d02cd31655c Mon Sep 17 00:00:00 2001
From: "flyingscorpio@arch-desktop" <tfranken@protonmail.com>
Date: Mon, 26 Oct 2020 17:10:04 +0100
Subject: [PATCH] Add checks for secrets and template

---
 install.py | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/install.py b/install.py
index 152d43b..3a6aedd 100755
--- a/install.py
+++ b/install.py
@@ -42,9 +42,19 @@ class Installer:
         by the user. If the secrets is wrong, or missing, fail.
         """
 
+        try:
+            with open("secrets.template", "r") as template_file:
+                template_content = [
+                    line.strip()
+                    for line in template_file.readlines()
+                    if not line.startswith("#") and line.strip()
+                ]
+        except FileNotFoundError:
+            print("No 'secrets.template' file found. Did you delete it?")
+            sys.exit(1)
         try:
             with open("secrets", "r") as secrets_file:
-                secrets = [
+                secrets_content = [
                     line.strip()
                     for line in secrets_file.readlines()
                     if not line.startswith("#") and line.strip()
@@ -52,7 +62,20 @@ class Installer:
         except FileNotFoundError:
             print("No 'secrets' file found. Did you forget to create it?")
             sys.exit(1)
-        for line in secrets:
+
+        # Check that the template file and secrets file have the same keys
+        template_keys = [line.split("=")[0] for line in template_content]
+        secrets_keys = [line.split("=")[0] for line in secrets_content]
+
+        if template_keys != secrets_keys:
+            print(
+                "'secrets.template' and 'secrets' don't have the same keys.\n"
+                "Perhaps you have forgotten to add some?"
+            )
+            sys.exit(1)
+
+        # Check that each key has a value that has been set:
+        for line in secrets_content:
             key, value = line.split("=")
             value = value.replace("'", "").replace('"', "")
             if not value: