machineconfig 1.5__py3-none-any.whl → 1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of machineconfig might be problematic. Click here for more details.
- machineconfig/__init__.py +8 -5
- machineconfig/jobs/python/check_installations.py +173 -163
- machineconfig/jobs/python/checkout_version.py +117 -0
- machineconfig/jobs/python/create_bootable_media.py +14 -14
- machineconfig/jobs/python/create_zellij_template.py +59 -56
- machineconfig/jobs/python/python_cargo_build_share.py +50 -45
- machineconfig/jobs/python/python_ve_symlink.py +20 -18
- machineconfig/jobs/python/tasks.py +4 -0
- machineconfig/jobs/script_installer/azure_data_studio.py +22 -0
- machineconfig/jobs/script_installer/bypass_paywall.py +23 -0
- machineconfig/jobs/script_installer/code.py +34 -0
- machineconfig/jobs/script_installer/docker_desktop.py +41 -0
- machineconfig/jobs/script_installer/ngrok.py +29 -0
- machineconfig/jobs/{python_linux_installers → script_installer}/skim.py +21 -19
- machineconfig/jobs/script_installer/wezterm.py +34 -0
- machineconfig/profile/create.py +107 -200
- machineconfig/profile/shell.py +127 -0
- machineconfig/scripts/__init__.py +6 -6
- machineconfig/scripts/python/cloud_copy.py +93 -0
- machineconfig/scripts/python/cloud_manager.py +38 -0
- machineconfig/scripts/python/cloud_mount.py +115 -52
- machineconfig/scripts/python/cloud_repo_sync.py +154 -114
- machineconfig/scripts/python/cloud_sync.py +261 -79
- machineconfig/scripts/python/croshell.py +151 -0
- machineconfig/scripts/python/devops.py +119 -87
- machineconfig/scripts/python/devops_add_identity.py +27 -23
- machineconfig/scripts/python/devops_add_ssh_key.py +70 -55
- machineconfig/scripts/python/devops_backup_retrieve.py +52 -46
- machineconfig/scripts/python/devops_devapps_install.py +120 -91
- machineconfig/scripts/python/devops_update_repos.py +82 -68
- machineconfig/scripts/python/dotfile.py +42 -38
- machineconfig/scripts/python/fire_jobs.py +351 -98
- machineconfig/scripts/python/ftpx.py +82 -0
- machineconfig/scripts/python/mount_nfs.py +54 -3
- machineconfig/scripts/python/mount_nw_drive.py +31 -0
- machineconfig/scripts/python/mount_ssh.py +44 -20
- machineconfig/scripts/python/onetimeshare.py +60 -51
- machineconfig/scripts/python/pomodoro.py +41 -37
- machineconfig/scripts/python/repos.py +195 -128
- machineconfig/scripts/python/scheduler.py +52 -0
- machineconfig/scripts/python/snapshot.py +21 -21
- machineconfig/scripts/python/start_slidev.py +104 -0
- machineconfig/scripts/python/start_terminals.py +97 -0
- machineconfig/scripts/python/wifi_conn.py +90 -71
- machineconfig/scripts/python/{transfer_wsl_win.py → wsl_windows_transfer.py} +47 -39
- machineconfig/setup_windows/wt_and_pwsh/set_pwsh_theme.py +44 -48
- machineconfig/setup_windows/wt_and_pwsh/set_wt_settings.py +136 -130
- machineconfig/utils/installer.py +251 -0
- machineconfig/utils/procs.py +114 -64
- machineconfig/utils/scheduling.py +188 -0
- machineconfig/utils/utils.py +353 -249
- machineconfig/utils/ve.py +222 -0
- {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/METADATA +140 -110
- machineconfig-1.8.dist-info/RECORD +70 -0
- {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/WHEEL +1 -1
- machineconfig/jobs/python/python_linux_installers_all.py +0 -73
- machineconfig/jobs/python/python_ve_installer.py +0 -73
- machineconfig/jobs/python/python_windows_installers_all.py +0 -23
- machineconfig/jobs/python_generic_installers/archive/nvim.py +0 -15
- machineconfig/jobs/python_generic_installers/archive/strongbox.py +0 -32
- machineconfig/jobs/python_generic_installers/archive/vtm.py +0 -25
- machineconfig/jobs/python_generic_installers/broot.py +0 -39
- machineconfig/jobs/python_generic_installers/browsh.py +0 -25
- machineconfig/jobs/python_generic_installers/bw.py +0 -26
- machineconfig/jobs/python_generic_installers/chatgpt.py +0 -24
- machineconfig/jobs/python_generic_installers/cpufetch.py +0 -23
- machineconfig/jobs/python_generic_installers/delta.py +0 -59
- machineconfig/jobs/python_generic_installers/dev/__init__.py +0 -0
- machineconfig/jobs/python_generic_installers/dev/autogpt.py +0 -28
- machineconfig/jobs/python_generic_installers/dev/bw.py +0 -29
- machineconfig/jobs/python_generic_installers/dev/evcxr.py +0 -22
- machineconfig/jobs/python_generic_installers/dev/kondo.py +0 -21
- machineconfig/jobs/python_generic_installers/dev/lvim.py +0 -60
- machineconfig/jobs/python_generic_installers/dev/ngrok.py +0 -35
- machineconfig/jobs/python_generic_installers/dev/opencommit.py +0 -21
- machineconfig/jobs/python_generic_installers/dev/qrcp.py +0 -25
- machineconfig/jobs/python_generic_installers/dev/qrscan.py +0 -16
- machineconfig/jobs/python_generic_installers/dev/rust-analyzer.py +0 -24
- machineconfig/jobs/python_generic_installers/dev/termscp.py +0 -23
- machineconfig/jobs/python_generic_installers/dev/tldr.py +0 -25
- machineconfig/jobs/python_generic_installers/dev/tokei.py +0 -24
- machineconfig/jobs/python_generic_installers/diskonaut.py +0 -26
- machineconfig/jobs/python_generic_installers/dua.py +0 -21
- machineconfig/jobs/python_generic_installers/evcxr.py +0 -21
- machineconfig/jobs/python_generic_installers/gitui.py +0 -23
- machineconfig/jobs/python_generic_installers/gopass.py +0 -19
- machineconfig/jobs/python_generic_installers/helix.py +0 -45
- machineconfig/jobs/python_generic_installers/kondo.py +0 -20
- machineconfig/jobs/python_generic_installers/lf.py +0 -25
- machineconfig/jobs/python_generic_installers/lvim.py +0 -34
- machineconfig/jobs/python_generic_installers/mprocs.py +0 -20
- machineconfig/jobs/python_generic_installers/navi.py +0 -20
- machineconfig/jobs/python_generic_installers/ots.py +0 -26
- machineconfig/jobs/python_generic_installers/ouch.py +0 -25
- machineconfig/jobs/python_generic_installers/pomodoro.py +0 -19
- machineconfig/jobs/python_generic_installers/procs.py +0 -20
- machineconfig/jobs/python_generic_installers/qrcp.py +0 -22
- machineconfig/jobs/python_generic_installers/qrscan.py +0 -14
- machineconfig/jobs/python_generic_installers/rclone.py +0 -21
- machineconfig/jobs/python_generic_installers/rust-analyzer.py +0 -24
- machineconfig/jobs/python_generic_installers/tere.py +0 -26
- machineconfig/jobs/python_generic_installers/termscp.py +0 -23
- machineconfig/jobs/python_generic_installers/tldr.py +0 -24
- machineconfig/jobs/python_generic_installers/tokei.py +0 -21
- machineconfig/jobs/python_generic_installers/vtm.py +0 -26
- machineconfig/jobs/python_generic_installers/watchexec.py +0 -21
- machineconfig/jobs/python_linux_installers/archive/__init__.py +0 -0
- machineconfig/jobs/python_linux_installers/archive/ranger.py +0 -18
- machineconfig/jobs/python_linux_installers/bandwhich.py +0 -11
- machineconfig/jobs/python_linux_installers/bottom.py +0 -17
- machineconfig/jobs/python_linux_installers/btop.py +0 -17
- machineconfig/jobs/python_linux_installers/dev/bandwhich.py +0 -13
- machineconfig/jobs/python_linux_installers/dev/bytehound.py +0 -20
- machineconfig/jobs/python_linux_installers/dev/nnn.py +0 -21
- machineconfig/jobs/python_linux_installers/gotty.py +0 -16
- machineconfig/jobs/python_linux_installers/joshuto.py +0 -28
- machineconfig/jobs/python_linux_installers/mcfly.py +0 -12
- machineconfig/jobs/python_linux_installers/nnn.py +0 -18
- machineconfig/jobs/python_linux_installers/topgrade.py +0 -15
- machineconfig/jobs/python_linux_installers/viu.py +0 -19
- machineconfig/jobs/python_linux_installers/xplr.py +0 -22
- machineconfig/jobs/python_linux_installers/zellij.py +0 -31
- machineconfig/jobs/python_windows_installers/archive/ntop.py +0 -20
- machineconfig/jobs/python_windows_installers/bat.py +0 -16
- machineconfig/jobs/python_windows_installers/boxes.py +0 -19
- machineconfig/jobs/python_windows_installers/bypass_paywall.py +0 -18
- machineconfig/jobs/python_windows_installers/dev/bypass_paywall.py +0 -21
- machineconfig/jobs/python_windows_installers/dev/obs_background_removal_plugin.py +0 -20
- machineconfig/jobs/python_windows_installers/fd.py +0 -17
- machineconfig/jobs/python_windows_installers/fzf.py +0 -19
- machineconfig/jobs/python_windows_installers/obs_background_removal_plugin.py +0 -19
- machineconfig/jobs/python_windows_installers/rg.py +0 -15
- machineconfig/jobs/python_windows_installers/ugrep.py +0 -14
- machineconfig/jobs/python_windows_installers/zoomit.py +0 -20
- machineconfig/jobs/python_windows_installers/zoxide.py +0 -20
- machineconfig/profile/fix_shell_profiles.py +0 -8
- machineconfig/scripts/python/archive/__init__.py +0 -0
- machineconfig/scripts/python/archive/bu_gdrive_rx.py +0 -41
- machineconfig/scripts/python/archive/bu_gdrive_sx.py +0 -40
- machineconfig/scripts/python/archive/bu_onedrive_rx.py +0 -59
- machineconfig/scripts/python/archive/bu_onedrive_sx.py +0 -45
- machineconfig/scripts/python/chatgpt.py +0 -28
- machineconfig/scripts/python/choose_ohmybash_theme.py +0 -25
- machineconfig/scripts/python/choose_ohmyposh_theme.py +0 -40
- machineconfig/scripts/python/cloud_rx.py +0 -42
- machineconfig/scripts/python/cloud_sx.py +0 -40
- machineconfig/scripts/python/ftprx.py +0 -37
- machineconfig/scripts/python/ftpsx.py +0 -36
- machineconfig/scripts/python/im2text.py +0 -15
- machineconfig/scripts/python/tmate_conn.py +0 -28
- machineconfig/scripts/python/tmate_start.py +0 -31
- machineconfig/utils/to_exe.py +0 -7
- machineconfig-1.5.dist-info/RECORD +0 -147
- /machineconfig/jobs/{python_generic_installers/archive → script_installer}/__init__.py +0 -0
- {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/top_level.txt +0 -0
|
@@ -1,87 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
program =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
program =
|
|
73
|
-
|
|
74
|
-
elif choice_key == Options.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"""devops
|
|
5
|
+
"""
|
|
6
|
+
from crocodile.file_management import P
|
|
7
|
+
from machineconfig.utils.utils import display_options, PROGRAM_PATH, write_shell_script
|
|
8
|
+
from platform import system
|
|
9
|
+
from enum import Enum
|
|
10
|
+
from typing import Optional
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Options(Enum):
|
|
14
|
+
update = 'UPDATE essential repos'
|
|
15
|
+
cli_install = 'DEVAPPS install'
|
|
16
|
+
ve = 'VE install'
|
|
17
|
+
sym_path_shell = 'SYMLINKS, PATH & SHELL PROFILE'
|
|
18
|
+
sym_new = 'SYMLINKS new'
|
|
19
|
+
ssh_add_pubkey = 'SSH add pub key to this machine'
|
|
20
|
+
ssh_add_id = 'SSH add identity (private key) to this machine'
|
|
21
|
+
ssh_use_pair = 'SSH use key pair to connect two machines'
|
|
22
|
+
ssh_setup = 'SSH setup'
|
|
23
|
+
ssh_setup_wsl = 'SSH setup wsl'
|
|
24
|
+
backup = 'BACKUP'
|
|
25
|
+
retreive = 'RETRIEVE'
|
|
26
|
+
scheduler = 'SCHEDULER'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def args_parser():
|
|
30
|
+
import argparse
|
|
31
|
+
parser = argparse.ArgumentParser()
|
|
32
|
+
parser.add_argument("-w", "--which", help="which option to run", type=str, default=None) # , choices=[op.value for op in Options]
|
|
33
|
+
args = parser.parse_args()
|
|
34
|
+
main(which=args.which)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def main(which: Optional[str] = None):
|
|
38
|
+
PROGRAM_PATH.delete(sure=True, verbose=False)
|
|
39
|
+
options = [op.value for op in Options]
|
|
40
|
+
if which is None:
|
|
41
|
+
# import questionary
|
|
42
|
+
# choice_key = questionary.autocomplete(message="Which option to run?", choices=options, default=options[0]).ask()
|
|
43
|
+
choice_key = display_options(msg="", options=options, header="DEVOPS", default=options[0])
|
|
44
|
+
else: choice_key = Options[which].value
|
|
45
|
+
|
|
46
|
+
if choice_key == Options.update.value:
|
|
47
|
+
import machineconfig.scripts.python.devops_update_repos as helper
|
|
48
|
+
program = helper.main()
|
|
49
|
+
|
|
50
|
+
elif choice_key == Options.ve.value:
|
|
51
|
+
program = ""
|
|
52
|
+
reply: bool = False
|
|
53
|
+
if P.cwd().joinpath(".ve.ini").exists():
|
|
54
|
+
reply = input("Detected .ve.ini file. Do you want to use it to build ve? (y/[n]): ") == "y"
|
|
55
|
+
if reply:
|
|
56
|
+
from machineconfig.utils.ve import get_ve_install_script_from_specs
|
|
57
|
+
program_win = get_ve_install_script_from_specs(repo_root=P.cwd().str, system="Windows")
|
|
58
|
+
program_lin = get_ve_install_script_from_specs(repo_root=P.cwd().str, system="Linux")
|
|
59
|
+
install_reply = input("Proceed with installation? (y/[n]): ") == "y"
|
|
60
|
+
if not install_reply: program = ""
|
|
61
|
+
else:
|
|
62
|
+
if system() == "Windows": program = program_win
|
|
63
|
+
elif system() == "Linux": program = program_lin
|
|
64
|
+
else: raise ValueError(f"Unknown system: {system()}")
|
|
65
|
+
|
|
66
|
+
if not reply:
|
|
67
|
+
from machineconfig.utils.ve import get_ve_install_script
|
|
68
|
+
program = get_ve_install_script()
|
|
69
|
+
|
|
70
|
+
elif choice_key == Options.cli_install.value:
|
|
71
|
+
import machineconfig.scripts.python.devops_devapps_install as helper
|
|
72
|
+
program = helper.main()
|
|
73
|
+
|
|
74
|
+
elif choice_key == Options.sym_new.value:
|
|
75
|
+
import machineconfig.jobs.python.python_ve_symlink as helper
|
|
76
|
+
program = helper.main()
|
|
77
|
+
|
|
78
|
+
elif choice_key == Options.sym_path_shell.value:
|
|
79
|
+
import machineconfig.profile.create as helper
|
|
80
|
+
helper.main()
|
|
81
|
+
program = "echo '✅ done with symlinks'"
|
|
82
|
+
|
|
83
|
+
elif choice_key == Options.ssh_add_pubkey.value:
|
|
84
|
+
import machineconfig.scripts.python.devops_add_ssh_key as helper
|
|
85
|
+
program = helper.main()
|
|
86
|
+
|
|
87
|
+
elif choice_key == Options.ssh_use_pair.value:
|
|
88
|
+
raise NotImplementedError
|
|
89
|
+
|
|
90
|
+
elif choice_key == Options.ssh_add_id.value: # so that you can SSH directly withuot pointing to identity key.
|
|
91
|
+
import machineconfig.scripts.python.devops_add_identity as helper
|
|
92
|
+
program = helper.main()
|
|
93
|
+
|
|
94
|
+
elif choice_key == Options.ssh_setup.value:
|
|
95
|
+
program_windows = f"""Invoke-WebRequest https://raw.githubusercontent.com/thisismygitrepo/machineconfig/main/src/machineconfig/setup_windows/openssh_all.ps1 | Invoke-Expression # https://github.com/thisismygitrepo.keys"""
|
|
96
|
+
program_linux = f"""curl https://raw.githubusercontent.com/thisismygitrepo/machineconfig/main/src/machineconfig/setup_linux/openssh_all.sh | sudo bash # https://github.com/thisismygitrepo.keys"""
|
|
97
|
+
program = program_linux if system() == "Linux" else program_windows
|
|
98
|
+
|
|
99
|
+
elif choice_key == Options.ssh_setup_wsl.value:
|
|
100
|
+
program = f"""curl https://raw.githubusercontent.com/thisismygitrepo/machineconfig/main/src/machineconfig/setup_linux/openssh_wsl.sh | sudo bash"""
|
|
101
|
+
|
|
102
|
+
elif choice_key == Options.backup.value:
|
|
103
|
+
from machineconfig.scripts.python.devops_backup_retrieve import main as helper
|
|
104
|
+
program = helper(direction="BACKUP")
|
|
105
|
+
elif choice_key == Options.retreive.value:
|
|
106
|
+
from machineconfig.scripts.python.devops_backup_retrieve import main as helper
|
|
107
|
+
program = helper(direction="RETRIEVE")
|
|
108
|
+
|
|
109
|
+
elif choice_key == Options.scheduler.value:
|
|
110
|
+
from machineconfig.scripts.python.scheduler import main as helper
|
|
111
|
+
program = helper()
|
|
112
|
+
|
|
113
|
+
else: raise ValueError(f"Unimplemented choice: {choice_key}")
|
|
114
|
+
if program: write_shell_script(program, display=True, preserve_cwd=True, desc="Shell script prepared by Python.", execute=True if which is not None else False)
|
|
115
|
+
else: write_shell_script("echo 'Done.'", display=False, ) # Python did not return any script to run.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
args_parser()
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
else:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
|
|
2
|
+
"""ID
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# from platform import system
|
|
7
|
+
from crocodile.file_management import P
|
|
8
|
+
from machineconfig.utils.utils import display_options
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
private_keys = P.home().joinpath(".ssh").search("*.pub").apply(lambda x: x.with_name(x.stem)).filter(lambda x: x.exists())
|
|
13
|
+
choice = display_options(msg="Path to private key to be used when ssh'ing: ", options=private_keys.apply(str).list + ["I have the path to the key file", "I want to paste the key itself"])
|
|
14
|
+
if choice == "I have the path to the key file": path_to_key = P(input("Input path here: ")).expanduser().absolute()
|
|
15
|
+
elif choice == "I want to paste the key itself": path_to_key = P.home().joinpath(f".ssh/{input('file name (default: my_pasted_key): ') or 'my_pasted_key'}").write_text(input("Paste the private key here: "))
|
|
16
|
+
elif isinstance(choice, str): path_to_key = P(choice)
|
|
17
|
+
else: raise NotImplementedError(f"Choice {choice} not supported")
|
|
18
|
+
txt = f"IdentityFile {path_to_key.collapseuser().as_posix()}" # adds this id for all connections, no host specified.
|
|
19
|
+
config_path = P.home().joinpath(".ssh/config")
|
|
20
|
+
if config_path.exists(): config_path.modify_text(txt_search=txt, txt_alt=txt, replace_line=True, notfound_append=True, prepend=True) # note that Identity line must come on top of config file otherwise it won't work, hence `prepend=True`
|
|
21
|
+
else: config_path.write_text(txt)
|
|
22
|
+
program = f"echo 'Finished adding identity to ssh config file. {'*'*50} Consider reloading config file.'"
|
|
23
|
+
return program
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == '__main__':
|
|
27
|
+
pass
|
|
@@ -1,55 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if authorized_keys.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
|
|
2
|
+
"""SSH
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from platform import system
|
|
7
|
+
from machineconfig.utils.utils import LIBRARY_ROOT, display_options
|
|
8
|
+
from crocodile.file_management import P
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_add_ssh_key_script(path_to_key: P):
|
|
12
|
+
if system() == "Linux": authorized_keys = P.home().joinpath(".ssh/authorized_keys")
|
|
13
|
+
elif system() == "Windows": authorized_keys = P("C:/ProgramData/ssh/administrators_authorized_keys")
|
|
14
|
+
else: raise NotImplementedError
|
|
15
|
+
|
|
16
|
+
if authorized_keys.exists():
|
|
17
|
+
split = "\n"
|
|
18
|
+
print(f'ℹ️ Users that can access this machine have private keys of those pub keys:\n{authorized_keys.read_text().split(split)}')
|
|
19
|
+
|
|
20
|
+
if path_to_key.read_text() in authorized_keys.read_text():
|
|
21
|
+
print(f"⚠️ Key {path_to_key} already added to {authorized_keys}. No action is taken.")
|
|
22
|
+
program = ""
|
|
23
|
+
else:
|
|
24
|
+
if system() == "Linux":
|
|
25
|
+
program = f"cat {path_to_key} >> ~/.ssh/authorized_keys"
|
|
26
|
+
elif system() == "Windows":
|
|
27
|
+
program_path = LIBRARY_ROOT.joinpath("setup_windows/openssh-server_add-sshkey.ps1")
|
|
28
|
+
program = program_path.expanduser().read_text()
|
|
29
|
+
place_holder = r'$sshfile = "$env:USERPROFILE\.ssh\pubkey.pub"'
|
|
30
|
+
assert place_holder in program, f"This section performs string manipulation on the script {program_path} to add the key to the authorized_keys file. The script has changed and the string {place_holder} is not found."
|
|
31
|
+
program = program.replace(place_holder, f'$sshfile = "{path_to_key}"')
|
|
32
|
+
print(f"Replaced {place_holder} with {path_to_key} in {program_path}.")
|
|
33
|
+
else: raise NotImplementedError
|
|
34
|
+
else:
|
|
35
|
+
if system() == "Linux":
|
|
36
|
+
program = f"cat {path_to_key} > ~/.ssh/authorized_keys"
|
|
37
|
+
else:
|
|
38
|
+
program = LIBRARY_ROOT.joinpath("setup_windows/openssh-server_add-sshkey.ps1")
|
|
39
|
+
program = P(program).expanduser().read_text().replace('$sshfile=""', f'$sshfile="{path_to_key}"')
|
|
40
|
+
|
|
41
|
+
if system() == "Linux": program += f"""
|
|
42
|
+
|
|
43
|
+
sudo chmod 700 ~/.ssh
|
|
44
|
+
sudo chmod 644 ~/.ssh/authorized_keys
|
|
45
|
+
sudo chmod 644 ~/.ssh/*.pub
|
|
46
|
+
sudo service ssh --full-restart
|
|
47
|
+
# from superuser.com/questions/215504/permissions-on-private-key-in-ssh-folder
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
return program
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
pub_keys = P.home().joinpath(".ssh").search("*.pub")
|
|
55
|
+
all_keys_option = f"all pub keys available ({len(pub_keys)})"
|
|
56
|
+
i_have_path_option = "I have the path to the key file"
|
|
57
|
+
i_paste_option = "I want to paste the key itself"
|
|
58
|
+
res = display_options("Which public key to add? ", options=pub_keys.apply(str).list + [all_keys_option, i_have_path_option, i_paste_option])
|
|
59
|
+
assert isinstance(res, str), f"Got {res} of type {type(res)} instead of str."
|
|
60
|
+
if res == all_keys_option: program = "\n\n\n".join(pub_keys.apply(get_add_ssh_key_script))
|
|
61
|
+
elif res == i_have_path_option: program = get_add_ssh_key_script(P(input("Path: ")).expanduser().absolute())
|
|
62
|
+
elif res == i_paste_option: program = get_add_ssh_key_script(P.home().joinpath(f".ssh/{input('file name (default: my_pasted_key.pub): ') or 'my_pasted_key.pub'}").write_text(input("Paste the pub key here: ")))
|
|
63
|
+
else:
|
|
64
|
+
program = get_add_ssh_key_script(P(res))
|
|
65
|
+
print(program)
|
|
66
|
+
return program
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == '__main__':
|
|
70
|
+
pass
|
|
@@ -1,46 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
|
|
2
|
+
"""BR: Backup and Retrieve
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# import subprocess
|
|
6
|
+
from crocodile.file_management import Read, P
|
|
7
|
+
from machineconfig.utils.utils import LIBRARY_ROOT, DEFAULTS_PATH, print_code, choose_cloud_interactively, display_options
|
|
8
|
+
from machineconfig.scripts.python.cloud_sync import ES
|
|
9
|
+
from platform import system
|
|
10
|
+
from typing import Any, Literal, Optional
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
OPTIONS = Literal["BACKUP", "RETRIEVE"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main(direction: OPTIONS, which: Optional[str] = None):
|
|
17
|
+
try:
|
|
18
|
+
cloud: str = Read.ini(DEFAULTS_PATH)['general']['rclone_config_name']
|
|
19
|
+
print(f"\n{'--' * 50}\n ⚠️ Using default cloud: `{cloud}` ⚠️\n{'--' * 50}\n")
|
|
20
|
+
except (FileNotFoundError, KeyError, IndexError): cloud = choose_cloud_interactively()
|
|
21
|
+
|
|
22
|
+
bu_file: dict[str, Any] = LIBRARY_ROOT.joinpath("profile/backup.toml").readit()
|
|
23
|
+
if system() == "Linux": bu_file = {key: val for key, val in bu_file.items() if "windows" not in key}
|
|
24
|
+
elif system() == "Windows": bu_file = {key: val for key, val in bu_file.items() if "linux" not in key}
|
|
25
|
+
|
|
26
|
+
if which is None:
|
|
27
|
+
choice_key = display_options(msg=f"WHICH FILE of the following do you want to {direction}?", options=['all'] + list(bu_file.keys()))
|
|
28
|
+
assert isinstance(choice_key, str)
|
|
29
|
+
else: choice_key = which
|
|
30
|
+
|
|
31
|
+
if choice_key == "all": items = bu_file
|
|
32
|
+
else: items = {choice_key: bu_file[choice_key]}
|
|
33
|
+
|
|
34
|
+
program = f"""$cloud = "{cloud}:{ES}" \n """ if system() == "Windows" else f"""cloud="{cloud}:{ES}" \n """
|
|
35
|
+
for item_name, item in items.items():
|
|
36
|
+
# P.home().joinpath(".ipython").to_cloud(cloud="oduq1", zip=True, encrypt=True, rel2home=True, os_specific=False)
|
|
37
|
+
flags = ''
|
|
38
|
+
flags += 'z' if item['zip'] == 'True' else ''
|
|
39
|
+
flags += 'e' if item['encrypt'] == 'True' else ''
|
|
40
|
+
flags += 'r' if item['rel2home'] == 'True' else ''
|
|
41
|
+
flags += 'o' if system().lower() in item_name else ''
|
|
42
|
+
if flags: flags = "-" + flags
|
|
43
|
+
if direction == "BACKUP": program += f"""\ncloud_copy "{P(item['path']).as_posix()}" $cloud {flags}\n"""
|
|
44
|
+
elif direction == "RETRIEVE": program += f"""\ncloud_copy $cloud "{P(item['path']).as_posix()}" {flags}\n"""
|
|
45
|
+
else: raise RuntimeError(f"Unknown direction: {direction}")
|
|
46
|
+
if item_name == "dotfiles" and system() == "Linux": program += f"""\nchmod 700 ~/.ssh/*\n"""
|
|
47
|
+
print_code(program, lexer="shell", desc=f"{direction} script")
|
|
48
|
+
return program
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
pass
|