Added conversion scripts (moved from main repo) and organized extra folder

This commit is contained in:
rwinkhart
2022-07-10 00:13:47 -04:00
parent 5a077ba356
commit 4c852a4bcf
4 changed files with 89 additions and 0 deletions

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

+41
View File
@@ -0,0 +1,41 @@
#!/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)):
if _num == 3:
if _old_contents[_num] == ' ' or _old_contents[_num] == '\n':
pass
else:
_new_contents += _old_contents[_num]
else:
_new_contents += _old_contents[_num]
for _num in reversed(range(len(_new_contents))):
if _new_contents[_num] == '\n' 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)
+48
View File
@@ -0,0 +1,48 @@
#!/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: ')
pasture = path.expanduser('~/.password-pasture')
if Path(f"{pasture}.new").exists():
rmtree(f"{pasture}.new")
if Path(f"{pasture}.old").exists():
rmtree(f"{pasture}.old")
if path.isdir(pasture):
for dirPath, dirNames, filenames in walk(pasture):
for filename in sorted(filenames):
Path(dirPath.replace(pasture, pasture + '.new')).mkdir(0o700, parents=True, exist_ok=True)
system(f"gpg -d '{dirPath}/{filename}' "
f"> '{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}'")
_old_contents, _new_contents = \
open(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}", 'r').readlines(), ''
for _num in range(len(_old_contents)):
if _num == 0:
try:
_new_contents += _old_contents[1]
except IndexError:
_new_contents += '\n'
elif _num == 1:
_new_contents += _old_contents[0]
elif _num == 3:
if _old_contents[_num] == ' ' or _old_contents[_num] == '\n':
pass
else:
_new_contents += _old_contents[_num]
else:
_new_contents += _old_contents[_num]
for _num in reversed(range(len(_new_contents))):
if _new_contents[_num] == '\n' or _new_contents[_num] == '':
_new_contents = _new_contents[:-1]
else:
break
open(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}", 'w').writelines(_new_contents)
system(f"gpg -qr {str(gpg_id)} -e '{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}'")
remove(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}")
else:
print(f"\nError: no entry folder ({pasture}) found\n")
move(pasture, f"{pasture}.old")
move(f"{pasture}.new", pasture)