mirror of
https://github.com/rwinkhart/sshyp-labs.git
synced 2026-08-27 20:36:31 -04:00
Updated refresh script (changes gpg id, optimizes entries) to take advantage of sshyp v1.1.1
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
from os import path, remove, system, walk
|
||||
from pathlib import Path
|
||||
from shutil import move, rmtree
|
||||
|
||||
if __name__ == "__main__":
|
||||
gpg_id = input('\nWhat is the ID of the GPG key you would like to use for re-encryption?\n\nID: ')
|
||||
directory = path.expanduser('~/.local/share/sshyp')
|
||||
if Path(f"{directory}.new").exists():
|
||||
rmtree(f"{directory}.new")
|
||||
if Path(f"{directory}.old").exists():
|
||||
rmtree(f"{directory}.old")
|
||||
if path.isdir(directory):
|
||||
for dirPath, dirNames, filenames in walk(directory):
|
||||
for filename in sorted(filenames):
|
||||
Path(dirPath.replace(directory, directory + '.new')).mkdir(0o700, parents=True, exist_ok=True)
|
||||
system(f"gpg -d '{dirPath}/{filename}' "
|
||||
f"> '{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}'")
|
||||
_old_contents, _new_contents = \
|
||||
open(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}", 'r').readlines(), []
|
||||
for _num in range(len(_old_contents)):
|
||||
_new_contents += _old_contents[_num]
|
||||
for _num in reversed(range(len(_new_contents))):
|
||||
if _new_contents[_num] == '\n' or _new_contents[_num] == '' or _new_contents[_num] == ' ':
|
||||
_new_contents = _new_contents[:-1]
|
||||
else:
|
||||
break
|
||||
open(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}", 'w').writelines(_new_contents)
|
||||
system(f"gpg -qr {str(gpg_id)} -e '{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}'")
|
||||
remove(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}")
|
||||
else:
|
||||
print(f"\nError: no entry folder ({directory}) found\n")
|
||||
move(directory, f"{directory}.old")
|
||||
move(f"{directory}.new", directory)
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/python3
|
||||
|
||||
from os import path, system, uname, walk
|
||||
from pathlib import Path
|
||||
from shutil import move, rmtree
|
||||
from sshyp import decrypt, encrypt, optimized_edit, shm_gen
|
||||
|
||||
if __name__ == "__main__":
|
||||
directory, tmp_dir = path.expanduser('~/.local/share/sshyp'), path.expanduser('~/.config/sshyp/tmp/')
|
||||
if uname()[0] == 'Haiku': # set proper gpg command for OS
|
||||
gpg = 'gpg --pinentry-mode loopback'
|
||||
else:
|
||||
gpg = 'gpg'
|
||||
system(f"{gpg} -k")
|
||||
gpg_id = input('\ngpg id for re-encryption: ')
|
||||
if Path(f"{directory}.new").exists():
|
||||
rmtree(f"{directory}.new")
|
||||
if Path(f"{directory}.old").exists():
|
||||
rmtree(f"{directory}.old")
|
||||
if path.isdir(directory):
|
||||
print('\nconverting... please wait, do not force close this process')
|
||||
for dirPath, dirNames, filenames in walk(directory):
|
||||
for filename in sorted(filenames):
|
||||
Path(dirPath.replace(directory, directory + '.new')).mkdir(0o700, parents=True, exist_ok=True)
|
||||
_shm_folder, _shm_entry = shm_gen()
|
||||
decrypt(f"{dirPath}/{filename[:-4]}", _shm_folder, _shm_entry, gpg)
|
||||
_new_lines = optimized_edit(open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines(), None, -1)
|
||||
open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'w').writelines(_new_lines)
|
||||
encrypt(f"{dirPath.replace(directory, directory + '.new', 1)}/{filename[:-4]}",
|
||||
_shm_folder, _shm_entry, gpg, gpg_id)
|
||||
move(directory, f"{directory}.old")
|
||||
move(f"{directory}.new", directory)
|
||||
else:
|
||||
print(f"\nError: no entry folder ({directory}) found\n")
|
||||
Reference in New Issue
Block a user