Compare commits
10 commits
e378e715f1
...
0f6201ab84
Author | SHA1 | Date | |
---|---|---|---|
baalajimaestro | 0f6201ab84 | ||
baalajimaestro | 906e948b6c | ||
baalajimaestro | 415d1a8a2f | ||
baalajimaestro | 0bacbf7241 | ||
baalajimaestro | 0391609c77 | ||
baalajimaestro | fb16a97bcf | ||
baalajimaestro | c6a24f1e53 | ||
baalajimaestro | 33fa9ecbe5 | ||
baalajimaestro | 5ff34f764f | ||
baalajimaestro | 9ff2a76479 |
|
@ -10,3 +10,5 @@ The scripts also assume that your parent directory has git set up properly, and
|
|||
`encrypt.py` - Encrypts the entire obsidian repo, with ChaCha20, retaining folder structure, with the given keys, supplied via env vars, and pushes it to a backup git facility.
|
||||
|
||||
`trigger.py` - This is more like a personal script, but all it does is, create a git tag in the current obsidian repo, push it ahead, and trigger a CI pipeline on another repo.
|
||||
|
||||
~~`termux_trigger.sh` - Script to sync all your obsidian repos, into your mobile. Works only with Termux. Fully automatic once you fill in the necessary variables, functions as a very dumb replacement to Obsidian Git Plugin. Hook it with Tasker to trigger it on a schedule/by another triggers.~~
|
||||
|
|
17
encrypt.py
17
encrypt.py
|
@ -7,11 +7,12 @@
|
|||
# Imports
|
||||
from git import Repo
|
||||
import os
|
||||
from shutil import copytree
|
||||
from shutil import copytree, rmtree
|
||||
from pathlib import Path
|
||||
from glob import glob
|
||||
import subprocess
|
||||
from time import time
|
||||
from shutil import rmtree
|
||||
|
||||
cwd = os.getcwd()
|
||||
path = Path(cwd)
|
||||
|
@ -29,12 +30,15 @@ BLACKLIST = [
|
|||
# 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")
|
||||
ssh_key = os.environ.get("SSH_SECRET_KEY")
|
||||
|
||||
git_ssh_cmd = f"ssh -i {ssh_key}"
|
||||
|
||||
# Create our encrypted directory base
|
||||
current_time = str(int(time()))
|
||||
if os.path.exists(enc_path):
|
||||
rmtree(enc_path)
|
||||
os.mkdir(enc_path)
|
||||
os.chdir(enc_path)
|
||||
|
||||
|
@ -42,7 +46,7 @@ os.chdir(enc_path)
|
|||
repo = Repo.init(enc_path)
|
||||
repo.create_remote(
|
||||
"origin",
|
||||
f"https://{enc_repo_user}:{enc_repo_pass}@github.com/baalajimaestro/{enc_repo}.git",
|
||||
f"ssh://git@github.com/{enc_repo}.git",
|
||||
)
|
||||
|
||||
# Glob the file list of "." starting files and non "." starting files
|
||||
|
@ -91,4 +95,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)
|
||||
repo.git.push("origin", "master", force=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
|
||||
|
||||
# Cleanup once you are done
|
||||
rmtree(enc_path)
|
||||
|
|
12
trigger.py
12
trigger.py
|
@ -8,24 +8,22 @@
|
|||
from git import Repo
|
||||
import subprocess
|
||||
import os
|
||||
from time import time
|
||||
from requests import post
|
||||
from pathlib import Path
|
||||
|
||||
# Environment variables for creds
|
||||
base_repo_user = os.environ.get("BASE_REPO_USERNAME")
|
||||
base_repo_pass = os.environ.get("BASE_REPO_PASSWORD")
|
||||
content_repo_git = os.environ.get("CONTENT_REPO_GIT")
|
||||
content_repo_id = os.environ.get("CONTENT_REPO_ID")
|
||||
gitlab_token = os.environ.get("GITLAB_TOKEN")
|
||||
ssh_key = os.environ.get("SSH_SECRET_KEY")
|
||||
|
||||
git_ssh_cmd = f"ssh -i {ssh_key}"
|
||||
|
||||
# Get the time and create a tag of epoch
|
||||
cwd = os.getcwd()
|
||||
path = Path(cwd)
|
||||
base_dir = str(path.parent.absolute())
|
||||
current_time = str(int(time()))
|
||||
repo = Repo(base_dir)
|
||||
repo.create_tag(current_time)
|
||||
|
||||
# Nuke the remote if it existed
|
||||
try:
|
||||
|
@ -35,11 +33,11 @@ except ValueError:
|
|||
pass
|
||||
repo.create_remote(
|
||||
"pushback",
|
||||
f"https://{base_repo_user}:{base_repo_pass}@git.baalajimaestro.me/baalajimaestro/{content_repo_git}.git",
|
||||
f"ssh://git@git.baalajimaestro.me:29999/{content_repo_git}.git",
|
||||
)
|
||||
|
||||
# Push the newly created tag
|
||||
repo.git.push("pushback", current_time)
|
||||
repo.git.push("pushback", "HEAD:prod", force=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
|
||||
|
||||
# Trigger site rebuild
|
||||
data = {"token": gitlab_token, "ref": "source"}
|
||||
|
|
Loading…
Reference in a new issue