Add comments for encryption script
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
bc299b676a
commit
f9e2b2e53d
1 changed files with 10 additions and 4 deletions
14
encrypt.py
14
encrypt.py
|
@ -4,6 +4,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Imports
|
||||||
from git import Repo
|
from git import Repo
|
||||||
import os
|
import os
|
||||||
from shutil import copytree
|
from shutil import copytree
|
||||||
|
@ -11,6 +12,7 @@ from glob import glob
|
||||||
import subprocess
|
import subprocess
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
# Blacklist, prevents handling these files altogether
|
||||||
BLACKLIST = [
|
BLACKLIST = [
|
||||||
".git",
|
".git",
|
||||||
".obsidian",
|
".obsidian",
|
||||||
|
@ -20,28 +22,32 @@ BLACKLIST = [
|
||||||
".trigger.py",
|
".trigger.py",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Env vars to handle creds
|
||||||
enc_path = os.environ.get("ENCRYPTED_PATH")
|
enc_path = os.environ.get("ENCRYPTED_PATH")
|
||||||
enc_repo = os.environ.get("ENCRYPTED_REPO")
|
enc_repo = os.environ.get("ENCRYPTED_REPO")
|
||||||
enc_repo_user = os.environ.get("ENCRYPTED_REPO_USERNAME")
|
enc_repo_user = os.environ.get("ENCRYPTED_REPO_USERNAME")
|
||||||
enc_repo_pass = os.environ.get("ENCRYPTED_REPO_PASSWORD")
|
enc_repo_pass = os.environ.get("ENCRYPTED_REPO_PASSWORD")
|
||||||
enc_key = os.environ.get("ENCRYPTION_KEY")
|
enc_key = os.environ.get("ENCRYPTION_KEY")
|
||||||
|
|
||||||
|
# Create our encrypted directory base
|
||||||
base_dir = os.getcwd()
|
base_dir = os.getcwd()
|
||||||
|
|
||||||
current_time = str(int(time()))
|
current_time = str(int(time()))
|
||||||
|
|
||||||
os.mkdir(enc_path)
|
os.mkdir(enc_path)
|
||||||
os.chdir(enc_path)
|
os.chdir(enc_path)
|
||||||
|
|
||||||
|
# Initialise the repo for our encrypted directory and add the remote
|
||||||
repo = Repo.init(enc_path)
|
repo = Repo.init(enc_path)
|
||||||
repo.create_remote(
|
repo.create_remote(
|
||||||
"origin",
|
"origin",
|
||||||
f"https://{enc_repo_user}:{enc_repo_pass}@github.com/baalajimaestro/{enc_repo}.git",
|
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(
|
file_list = glob(base_dir + "/**/.*", recursive=True) + glob(
|
||||||
base_dir + "/**/*", recursive=True
|
base_dir + "/**/*", recursive=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Start going through the file list, and create all directories
|
||||||
for i in file_list:
|
for i in file_list:
|
||||||
if os.path.isdir(i):
|
if os.path.isdir(i):
|
||||||
rel_path = i.split(base_dir + "/")[1]
|
rel_path = i.split(base_dir + "/")[1]
|
||||||
|
@ -51,6 +57,7 @@ for i in file_list:
|
||||||
else:
|
else:
|
||||||
os.mkdir(enc_path + "/" + rel_path)
|
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:
|
for i in file_list:
|
||||||
rel_path = i.split(base_dir + "/")[1]
|
rel_path = i.split(base_dir + "/")[1]
|
||||||
if not os.path.isdir(i):
|
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.git.add(".")
|
||||||
|
|
||||||
repo.index.commit(f"Commit as of {current_time}")
|
repo.index.commit(f"Commit as of {current_time}")
|
||||||
|
|
||||||
repo.git.push("origin", "master", force=True)
|
repo.git.push("origin", "master", force=True)
|
||||||
|
|
Loading…
Reference in a new issue