mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-06 00:57:14 -04:00
Updated sshyp-refresh to use new entry directory
Former-commit-id: 9dedbb71ef7cf4f45511780d62a4c51d75d782a9 [formerly 8c520d972e]
Former-commit-id: 900cc5e3e7c0508a2629cfcb002faebb7c1d3753
This commit is contained in:
+16
-16
@@ -6,19 +6,19 @@ from shutil import move, rmtree
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
gpg_id = input('\nWhat is the ID of the GPG key you would like to use for re-encryption?\n\nID: ')
|
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')
|
directory = path.expanduser('~/.local/share/sshyp')
|
||||||
if Path(f"{pasture}.new").exists():
|
if Path(f"{directory}.new").exists():
|
||||||
rmtree(f"{pasture}.new")
|
rmtree(f"{directory}.new")
|
||||||
if Path(f"{pasture}.old").exists():
|
if Path(f"{directory}.old").exists():
|
||||||
rmtree(f"{pasture}.old")
|
rmtree(f"{directory}.old")
|
||||||
if path.isdir(pasture):
|
if path.isdir(directory):
|
||||||
for dirPath, dirNames, filenames in walk(pasture):
|
for dirPath, dirNames, filenames in walk(directory):
|
||||||
for filename in sorted(filenames):
|
for filename in sorted(filenames):
|
||||||
Path(dirPath.replace(pasture, pasture + '.new')).mkdir(0o700, parents=True, exist_ok=True)
|
Path(dirPath.replace(directory, directory + '.new')).mkdir(0o700, parents=True, exist_ok=True)
|
||||||
system(f"gpg -d '{dirPath}/{filename}' "
|
system(f"gpg -d '{dirPath}/{filename}' "
|
||||||
f"> '{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}'")
|
f"> '{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}'")
|
||||||
_old_contents, _new_contents = \
|
_old_contents, _new_contents = \
|
||||||
open(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}", 'r').readlines(), ''
|
open(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}", 'r').readlines(), ''
|
||||||
for _num in range(len(_old_contents)):
|
for _num in range(len(_old_contents)):
|
||||||
if _num == 3:
|
if _num == 3:
|
||||||
if _old_contents[_num] == ' ' or _old_contents[_num] == '\n':
|
if _old_contents[_num] == ' ' or _old_contents[_num] == '\n':
|
||||||
@@ -32,10 +32,10 @@ if __name__ == "__main__":
|
|||||||
_new_contents = _new_contents[:-1]
|
_new_contents = _new_contents[:-1]
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
open(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}", 'w').writelines(_new_contents)
|
open(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}", 'w').writelines(_new_contents)
|
||||||
system(f"gpg -qr {str(gpg_id)} -e '{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}'")
|
system(f"gpg -qr {str(gpg_id)} -e '{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}'")
|
||||||
remove(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}")
|
remove(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}")
|
||||||
else:
|
else:
|
||||||
print(f"\nError: no entry folder ({pasture}) found\n")
|
print(f"\nError: no entry folder ({directory}) found\n")
|
||||||
move(pasture, f"{pasture}.old")
|
move(directory, f"{directory}.old")
|
||||||
move(f"{pasture}.new", pasture)
|
move(f"{directory}.new", directory)
|
||||||
|
|||||||
Reference in New Issue
Block a user