Add comments for encryption script

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-09-25 13:11:07 +05:30
parent bc299b676a
commit f9e2b2e53d
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -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)