From f9e2b2e53da479d394cbe46a31557a6d7ede85de Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Sun, 25 Sep 2022 13:11:07 +0530 Subject: [PATCH] Add comments for encryption script Signed-off-by: baalajimaestro --- encrypt.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/encrypt.py b/encrypt.py index af7a724..2e6762e 100644 --- a/encrypt.py +++ b/encrypt.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # +# Imports from git import Repo import os from shutil import copytree @@ -11,6 +12,7 @@ from glob import glob import subprocess from time import time +# Blacklist, prevents handling these files altogether BLACKLIST = [ ".git", ".obsidian", @@ -20,28 +22,32 @@ BLACKLIST = [ ".trigger.py", ] +# Env vars to handle creds enc_path = os.environ.get("ENCRYPTED_PATH") enc_repo = os.environ.get("ENCRYPTED_REPO") enc_repo_user = os.environ.get("ENCRYPTED_REPO_USERNAME") enc_repo_pass = os.environ.get("ENCRYPTED_REPO_PASSWORD") enc_key = os.environ.get("ENCRYPTION_KEY") + +# Create our encrypted directory base base_dir = os.getcwd() - current_time = str(int(time())) - os.mkdir(enc_path) os.chdir(enc_path) +# Initialise the repo for our encrypted directory and add the remote repo = Repo.init(enc_path) repo.create_remote( "origin", f"https://{enc_repo_user}:{enc_repo_pass}@github.com/baalajimaestro/{enc_repo}.git", ) +# Glob the file list of "." starting files and non "." starting files file_list = glob(base_dir + "/**/.*", recursive=True) + glob( base_dir + "/**/*", recursive=True ) +# Start going through the file list, and create all directories for i in file_list: if os.path.isdir(i): rel_path = i.split(base_dir + "/")[1] @@ -51,6 +57,7 @@ for i in file_list: else: os.mkdir(enc_path + "/" + rel_path) +# Use a subprocess to chacha20 encrypt everything, and push it to the requested directory for i in file_list: rel_path = i.split(base_dir + "/")[1] if not os.path.isdir(i): @@ -78,8 +85,7 @@ for i in file_list: ] ) +# Add, commit and push it all repo.git.add(".") - repo.index.commit(f"Commit as of {current_time}") - repo.git.push("origin", "master", force=True)