mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-03 15:47:18 -04:00
Added return codes
This commit is contained in:
+1
-1
@@ -63,7 +63,7 @@ def get_profile(_profile_dir):
|
|||||||
except (FileNotFoundError, IndexError):
|
except (FileNotFoundError, IndexError):
|
||||||
print('\nEither the profile does not exist, or it is corrupted.\n')
|
print('\nEither the profile does not exist, or it is corrupted.\n')
|
||||||
_profile_data = None
|
_profile_data = None
|
||||||
s_exit()
|
s_exit(1)
|
||||||
# extract data from profile
|
# extract data from profile
|
||||||
_user = _profile_data[0].replace('\n', '')
|
_user = _profile_data[0].replace('\n', '')
|
||||||
_ip = _profile_data[1].replace('\n', '')
|
_ip = _profile_data[1].replace('\n', '')
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ def tweak(): # runs configuration wizard
|
|||||||
copy('/usr/bin/sshync.py', path.expanduser('~/'))
|
copy('/usr/bin/sshync.py', path.expanduser('~/'))
|
||||||
copy('/usr/bin/sshypRemote.py', path.expanduser('~/sshypRemote.py'))
|
copy('/usr/bin/sshypRemote.py', path.expanduser('~/sshypRemote.py'))
|
||||||
print('\nMake sure the ssh service is running and properly configured.\n\nConfiguration complete!\n')
|
print('\nMake sure the ssh service is running and properly configured.\n\nConfiguration complete!\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
else:
|
else:
|
||||||
# device type configuration
|
# device type configuration
|
||||||
_device_type = 'c' # ensure device type flag is properly set
|
_device_type = 'c' # ensure device type flag is properly set
|
||||||
@@ -288,7 +288,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
|||||||
except (FileNotFoundError, IndexError):
|
except (FileNotFoundError, IndexError):
|
||||||
print('\nThe deletion database does not exist or is corrupted.\n')
|
print('\nThe deletion database does not exist or is corrupted.\n')
|
||||||
_deletion_database = None
|
_deletion_database = None
|
||||||
s_exit()
|
s_exit(1)
|
||||||
for _file in _deletion_database:
|
for _file in _deletion_database:
|
||||||
if _file[:-1].endswith('/'):
|
if _file[:-1].endswith('/'):
|
||||||
try:
|
try:
|
||||||
@@ -316,7 +316,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
|||||||
except (FileNotFoundError, IndexError):
|
except (FileNotFoundError, IndexError):
|
||||||
print('\nThe folder database does not exist or is corrupted.\n')
|
print('\nThe folder database does not exist or is corrupted.\n')
|
||||||
_folder_database = None
|
_folder_database = None
|
||||||
s_exit()
|
s_exit(1)
|
||||||
for _folder in _folder_database:
|
for _folder in _folder_database:
|
||||||
if Path(f"{path.expanduser('~')}{_folder[:-1]}").is_dir():
|
if Path(f"{path.expanduser('~')}{_folder[:-1]}").is_dir():
|
||||||
pass
|
pass
|
||||||
@@ -412,7 +412,7 @@ def edit(): # edits the contents of an entry
|
|||||||
_entry_name = _entry_name.replace('/', '', 1)
|
_entry_name = _entry_name.replace('/', '', 1)
|
||||||
if not Path(f"{directory}{_entry_name}.gpg").is_file():
|
if not Path(f"{directory}{_entry_name}.gpg").is_file():
|
||||||
print("\nYou are trying to edit a file that does not exist!\n")
|
print("\nYou are trying to edit a file that does not exist!\n")
|
||||||
s_exit()
|
s_exit(1)
|
||||||
if argument.startswith('edit username') or argument.startswith('edit -u'):
|
if argument.startswith('edit username') or argument.startswith('edit -u'):
|
||||||
_detail = str(input('New Username: '))
|
_detail = str(input('New Username: '))
|
||||||
_shm_folder, _shm_entry = shm_gen()
|
_shm_folder, _shm_entry = shm_gen()
|
||||||
@@ -459,7 +459,7 @@ def gen(): # generates a password for a new or an existing entry
|
|||||||
if argument.startswith('gen update') or argument.startswith('gen -u'):
|
if argument.startswith('gen update') or argument.startswith('gen -u'):
|
||||||
if not Path(f"{directory}{_entry_name}.gpg").is_file():
|
if not Path(f"{directory}{_entry_name}.gpg").is_file():
|
||||||
print("\nYou are trying to edit a file that does not exist!\n")
|
print("\nYou are trying to edit a file that does not exist!\n")
|
||||||
s_exit()
|
s_exit(1)
|
||||||
else:
|
else:
|
||||||
_username = str(input('Username: '))
|
_username = str(input('Username: '))
|
||||||
_password = pass_gen()
|
_password = pass_gen()
|
||||||
@@ -498,7 +498,7 @@ def copy_data(): # copies a specified field of an entry to the clipboard
|
|||||||
_read_entry = ' '.join(_read_entry)
|
_read_entry = ' '.join(_read_entry)
|
||||||
if not Path(f"{directory}{_read_entry}.gpg").is_file():
|
if not Path(f"{directory}{_read_entry}.gpg").is_file():
|
||||||
print("\nThe file does not exist!\n")
|
print("\nThe file does not exist!\n")
|
||||||
s_exit()
|
s_exit(1)
|
||||||
_shm_folder, _shm_entry = shm_gen()
|
_shm_folder, _shm_entry = shm_gen()
|
||||||
system(f"gpg -qd --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_read_entry}.gpg'")
|
system(f"gpg -qd --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_read_entry}.gpg'")
|
||||||
_copy_line = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines()
|
_copy_line = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines()
|
||||||
@@ -548,7 +548,7 @@ def remove_data(): # deletes an entry from the server and flags it for local de
|
|||||||
remove(f"{tmp_dir}sshyp.lock")
|
remove(f"{tmp_dir}sshyp.lock")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('\nAccess denied.\n')
|
print('\nAccess denied.\n')
|
||||||
s_exit()
|
s_exit(1)
|
||||||
system(f"ssh -i '{path.expanduser('~/.ssh/sshyp')}' -p {port} {username_ssh}@{ip} \"python -c 'import sshypRemote"
|
system(f"ssh -i '{path.expanduser('~/.ssh/sshyp')}' -p {port} {username_ssh}@{ip} \"python -c 'import sshypRemote"
|
||||||
f"; sshypRemote.delete(\"'\"{_entry_name}\"'\")'\"")
|
f"; sshypRemote.delete(\"'\"{_entry_name}\"'\")'\"")
|
||||||
|
|
||||||
@@ -582,14 +582,14 @@ if __name__ == "__main__":
|
|||||||
print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||||
print("Not all necessary configuration files are present. Please run 'sshyp tweak'!")
|
print("Not all necessary configuration files are present. Please run 'sshyp tweak'!")
|
||||||
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
|
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
|
||||||
s_exit()
|
s_exit(1)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
tweak()
|
tweak()
|
||||||
s_exit()
|
s_exit(0)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
|
|
||||||
# run function based on argument
|
# run function based on argument
|
||||||
error = 0 # create an error flag to determine if syncing should occur at end
|
error = 0 # create an error flag to determine if syncing should occur at end
|
||||||
@@ -600,7 +600,7 @@ if __name__ == "__main__":
|
|||||||
no_arg()
|
no_arg()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument == 'help' or argument == '--help' or argument == '-h' or argument == 'license' or \
|
elif argument == 'help' or argument == '--help' or argument == '-h' or argument == 'license' or \
|
||||||
argument == 'version' or argument == '-v' or argument == 'add' or argument == 'edit' or argument == 'copy':
|
argument == 'version' or argument == '-v' or argument == 'add' or argument == 'edit' or argument == 'copy':
|
||||||
print_info()
|
print_info()
|
||||||
@@ -610,20 +610,20 @@ if __name__ == "__main__":
|
|||||||
add_entry()
|
add_entry()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument.startswith('add folder') or argument.startswith('add -f'):
|
elif argument.startswith('add folder') or argument.startswith('add -f'):
|
||||||
try:
|
try:
|
||||||
add_folder()
|
add_folder()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument.startswith('edit rename') or argument.startswith('edit relocate') or argument.startswith('edit -r'):
|
elif argument.startswith('edit rename') or argument.startswith('edit relocate') or argument.startswith('edit -r'):
|
||||||
silent_sync = 1
|
silent_sync = 1
|
||||||
try:
|
try:
|
||||||
rename()
|
rename()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith('edit password')\
|
elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith('edit password')\
|
||||||
or argument.startswith('edit -p') or argument.startswith('edit url') or argument.startswith('edit -l') or \
|
or argument.startswith('edit -p') or argument.startswith('edit url') or argument.startswith('edit -l') or \
|
||||||
argument.startswith('edit note') or argument.startswith('edit -n'):
|
argument.startswith('edit note') or argument.startswith('edit -n'):
|
||||||
@@ -631,13 +631,13 @@ if __name__ == "__main__":
|
|||||||
edit()
|
edit()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument.startswith('gen'):
|
elif argument.startswith('gen'):
|
||||||
try:
|
try:
|
||||||
gen()
|
gen()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith('copy password')\
|
elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith('copy password')\
|
||||||
or argument.startswith('copy -p') or argument.startswith('copy url') or argument.startswith('copy -l')\
|
or argument.startswith('copy -p') or argument.startswith('copy url') or argument.startswith('copy -l')\
|
||||||
or argument.startswith('copy note') or argument.startswith('copy -n'):
|
or argument.startswith('copy note') or argument.startswith('copy -n'):
|
||||||
@@ -645,19 +645,19 @@ if __name__ == "__main__":
|
|||||||
copy_data()
|
copy_data()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument.startswith('shear') or argument.startswith('-rm'):
|
elif argument.startswith('shear') or argument.startswith('-rm'):
|
||||||
try:
|
try:
|
||||||
remove_data()
|
remove_data()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\n')
|
print('\n')
|
||||||
s_exit()
|
s_exit(0)
|
||||||
elif argument == 'sync' or argument == '-s':
|
elif argument == 'sync' or argument == '-s':
|
||||||
sync()
|
sync()
|
||||||
else:
|
else:
|
||||||
error = 1 # set error flag to 1 to stop syncing
|
error = 1 # set error flag to 1 to stop syncing
|
||||||
print("\nArgument error! Please run 'sshyp help' for a list of usable commands.\n")
|
print("\nArgument error! Please run 'sshyp help' for a list of usable commands.\n")
|
||||||
s_exit()
|
s_exit(1)
|
||||||
|
|
||||||
# sync at end of program if any changes were made
|
# sync at end of program if any changes were made
|
||||||
if argument != '' and argument != 'help' and argument != '--help' and argument != '-h' and argument != 'license' \
|
if argument != '' and argument != 'help' and argument != '--help' and argument != '-h' and argument != 'license' \
|
||||||
|
|||||||
Reference in New Issue
Block a user