From 2ba19f9a391128c3d75a3abc8d299bd854f3a103 Mon Sep 17 00:00:00 2001 From: Cuan Date: Wed, 16 Feb 2022 12:02:45 -0500 Subject: [PATCH] Initial folder sync implementation --- bin/sshyp | 18 +++++++++++++++++- bin/sshyp-remote.py | 9 ++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bin/sshyp b/bin/sshyp index 4cc1196..7455d3c 100755 --- a/bin/sshyp +++ b/bin/sshyp @@ -158,7 +158,7 @@ def print_info(): # prints help text based on argument print('/ /') print('/ sshyp Copyright (C) 2021-2022 Randall Winkhart /') print('/ /') - print('/ Version 2022.02.16.fr4.3 /') + print('/ Version 2022.02.16.fr4.4 /') print('/ The High-Tech Shears Update /') print('/ /') print('////////////////////////////////////////////////////////\n') @@ -231,6 +231,22 @@ def sync(): # calls sshync to sync changes to the user's server remove(f"{path.expanduser('~/.password-pasture/')}{_file[:-1]}.gpg") except (FileNotFoundError, IsADirectoryError): print('File does not exist locally.\n') + # check for new folders + system(f"ssh -i '{path.expanduser('~/.ssh/sshyp')}' -p {port} {username_ssh}@{ip} \"python -c 'import sshyp-remote" + f"; sshyp-remote.folder_check()'\"") + system(f"sftp -p -q -i '{path.expanduser('~/.ssh/sshyp')}' -P {port} {username_ssh}@{ip}:" + f"'/home/{username_ssh}/.config/sshyp/folder_database' {path.expanduser('~/.config/sshyp/')}") + try: + _folder_database = open(path.expanduser('~/.config/sshyp/folder_database')).readlines() + except (FileNotFoundError, IndexError): + print('\nThe folder database does not exist or is corrupted.\n') + _folder_database = None + s_exit() + for _folder in _folder_database: + if Path(f"{path.expanduser('~/.password-pasture/')}{_folder[:-1]}").exists(): + pass + else: + Path(f"{path.expanduser('~/.password-pasture/')}{_folder[:-1]}").mkdir(0o700, parents=True, exist_ok=True) # set permissions before uploading system('find ' + directory + ' -type d -exec chmod -R 700 {} +') system('find ' + directory + ' -type f -exec chmod -R 600 {} +') diff --git a/bin/sshyp-remote.py b/bin/sshyp-remote.py index 789ea14..3997fa7 100755 --- a/bin/sshyp-remote.py +++ b/bin/sshyp-remote.py @@ -3,7 +3,7 @@ # external modules from os import remove, listdir -from os.path import expanduser +from os.path import expanduser, isdir, join from shutil import rmtree @@ -35,3 +35,10 @@ def deletion_check(_client_device_name): except FileNotFoundError: pass open(expanduser('~/.config/sshyp/deletion_database'), 'a').write(_file_path + '\n') + + +def folder_check(): + open(expanduser('~/.config/sshyp/deletion_database'), 'w').write('') + for _file in listdir(expanduser('~/.password-pasture')): + if isdir(join('~/.config/sshyp/deletion_database/', _file)): + open(expanduser('~/.config/sshyp/folder_database'), 'a').write(_file + '\n')