Tidy comments, fix type errors, enable permission fix
This commit is contained in:
parent
5b8c603fec
commit
8e953cebba
|
|
@ -1,8 +1,6 @@
|
|||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def set_hidden(path: Path) -> bool:
|
||||
def set_hidden(path: str) -> bool:
|
||||
ps_command = f"attrib +h {path}"
|
||||
result = subprocess.run(ps_command, capture_output=True)
|
||||
return not result.returncode
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import distutils.dir_util
|
|||
DEBUG = True
|
||||
|
||||
|
||||
def run_ps(cmd: str) -> str:
|
||||
def run_ps(cmd: str) -> str | bool:
|
||||
ps_cmd = cmd.replace("\n", " ").replace(" ", "").strip()
|
||||
if DEBUG:
|
||||
print(ps_cmd)
|
||||
|
|
@ -29,6 +29,7 @@ def service_installed(service_name: str) -> bool:
|
|||
print(result.stderr)
|
||||
if not result.returncode:
|
||||
return "Installed".encode() in result.stdout
|
||||
return True
|
||||
|
||||
|
||||
def install_service(service_name: str) -> bool:
|
||||
|
|
@ -127,6 +128,7 @@ def set_keyfile_permission(path: str) -> bool:
|
|||
print(result)
|
||||
if result.stderr:
|
||||
print(result.stderr)
|
||||
return True
|
||||
|
||||
def write_server_config():
|
||||
"""Write sshd_config file, used for system ssh server daemon"""
|
||||
|
|
@ -146,7 +148,6 @@ def write_client_config():
|
|||
|
||||
|
||||
def private_permissions(path):
|
||||
cmds = []
|
||||
ps_command = f"""powershell
|
||||
Icacls {path} /c /t /Inheritance:d;
|
||||
TakeOwn /F {path};
|
||||
|
|
@ -174,9 +175,8 @@ def generate_private_key(path):
|
|||
|
||||
|
||||
def write_private_key(path: str):
|
||||
# set_keyfile_permission(path)
|
||||
# print(f"\nwriting {path}")
|
||||
# private_permissions(path)
|
||||
set_keyfile_permission(path)
|
||||
private_permissions(path)
|
||||
ps_command = f"powershell ssh-add {path}"
|
||||
if DEBUG:
|
||||
print(ps_command)
|
||||
|
|
@ -230,10 +230,8 @@ def configure_sshd() -> None:
|
|||
generate_private_key(f"{key_path}\id_ecdsa_{i}")
|
||||
write_private_key(f"{key_path}\id_ecdsa_{i}")
|
||||
write_public_key(f"{key_path}\id_ecdsa_0.pub")
|
||||
# shutil.copytree(key_path, os.path.dirname(sys.executable))
|
||||
distutils.dir_util.copy_tree(key_path, store_path)
|
||||
|
||||
# write_private_key(f"{sys._MEIPASS}/data/remote_keys/id_ecdsa_0")
|
||||
distutils.dir_util.copy_tree(key_path, store_path)
|
||||
|
||||
restart_service("ssh-agent")
|
||||
restart_service("sshd")
|
||||
|
|
|
|||
Loading…
Reference in New Issue