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.

Files changed (155) hide show
  1. machineconfig/__init__.py +8 -5
  2. machineconfig/jobs/python/check_installations.py +173 -163
  3. machineconfig/jobs/python/checkout_version.py +117 -0
  4. machineconfig/jobs/python/create_bootable_media.py +14 -14
  5. machineconfig/jobs/python/create_zellij_template.py +59 -56
  6. machineconfig/jobs/python/python_cargo_build_share.py +50 -45
  7. machineconfig/jobs/python/python_ve_symlink.py +20 -18
  8. machineconfig/jobs/python/tasks.py +4 -0
  9. machineconfig/jobs/script_installer/azure_data_studio.py +22 -0
  10. machineconfig/jobs/script_installer/bypass_paywall.py +23 -0
  11. machineconfig/jobs/script_installer/code.py +34 -0
  12. machineconfig/jobs/script_installer/docker_desktop.py +41 -0
  13. machineconfig/jobs/script_installer/ngrok.py +29 -0
  14. machineconfig/jobs/{python_linux_installers → script_installer}/skim.py +21 -19
  15. machineconfig/jobs/script_installer/wezterm.py +34 -0
  16. machineconfig/profile/create.py +107 -200
  17. machineconfig/profile/shell.py +127 -0
  18. machineconfig/scripts/__init__.py +6 -6
  19. machineconfig/scripts/python/cloud_copy.py +93 -0
  20. machineconfig/scripts/python/cloud_manager.py +38 -0
  21. machineconfig/scripts/python/cloud_mount.py +115 -52
  22. machineconfig/scripts/python/cloud_repo_sync.py +154 -114
  23. machineconfig/scripts/python/cloud_sync.py +261 -79
  24. machineconfig/scripts/python/croshell.py +151 -0
  25. machineconfig/scripts/python/devops.py +119 -87
  26. machineconfig/scripts/python/devops_add_identity.py +27 -23
  27. machineconfig/scripts/python/devops_add_ssh_key.py +70 -55
  28. machineconfig/scripts/python/devops_backup_retrieve.py +52 -46
  29. machineconfig/scripts/python/devops_devapps_install.py +120 -91
  30. machineconfig/scripts/python/devops_update_repos.py +82 -68
  31. machineconfig/scripts/python/dotfile.py +42 -38
  32. machineconfig/scripts/python/fire_jobs.py +351 -98
  33. machineconfig/scripts/python/ftpx.py +82 -0
  34. machineconfig/scripts/python/mount_nfs.py +54 -3
  35. machineconfig/scripts/python/mount_nw_drive.py +31 -0
  36. machineconfig/scripts/python/mount_ssh.py +44 -20
  37. machineconfig/scripts/python/onetimeshare.py +60 -51
  38. machineconfig/scripts/python/pomodoro.py +41 -37
  39. machineconfig/scripts/python/repos.py +195 -128
  40. machineconfig/scripts/python/scheduler.py +52 -0
  41. machineconfig/scripts/python/snapshot.py +21 -21
  42. machineconfig/scripts/python/start_slidev.py +104 -0
  43. machineconfig/scripts/python/start_terminals.py +97 -0
  44. machineconfig/scripts/python/wifi_conn.py +90 -71
  45. machineconfig/scripts/python/{transfer_wsl_win.py → wsl_windows_transfer.py} +47 -39
  46. machineconfig/setup_windows/wt_and_pwsh/set_pwsh_theme.py +44 -48
  47. machineconfig/setup_windows/wt_and_pwsh/set_wt_settings.py +136 -130
  48. machineconfig/utils/installer.py +251 -0
  49. machineconfig/utils/procs.py +114 -64
  50. machineconfig/utils/scheduling.py +188 -0
  51. machineconfig/utils/utils.py +353 -249
  52. machineconfig/utils/ve.py +222 -0
  53. {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/METADATA +140 -110
  54. machineconfig-1.8.dist-info/RECORD +70 -0
  55. {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/WHEEL +1 -1
  56. machineconfig/jobs/python/python_linux_installers_all.py +0 -73
  57. machineconfig/jobs/python/python_ve_installer.py +0 -73
  58. machineconfig/jobs/python/python_windows_installers_all.py +0 -23
  59. machineconfig/jobs/python_generic_installers/archive/nvim.py +0 -15
  60. machineconfig/jobs/python_generic_installers/archive/strongbox.py +0 -32
  61. machineconfig/jobs/python_generic_installers/archive/vtm.py +0 -25
  62. machineconfig/jobs/python_generic_installers/broot.py +0 -39
  63. machineconfig/jobs/python_generic_installers/browsh.py +0 -25
  64. machineconfig/jobs/python_generic_installers/bw.py +0 -26
  65. machineconfig/jobs/python_generic_installers/chatgpt.py +0 -24
  66. machineconfig/jobs/python_generic_installers/cpufetch.py +0 -23
  67. machineconfig/jobs/python_generic_installers/delta.py +0 -59
  68. machineconfig/jobs/python_generic_installers/dev/__init__.py +0 -0
  69. machineconfig/jobs/python_generic_installers/dev/autogpt.py +0 -28
  70. machineconfig/jobs/python_generic_installers/dev/bw.py +0 -29
  71. machineconfig/jobs/python_generic_installers/dev/evcxr.py +0 -22
  72. machineconfig/jobs/python_generic_installers/dev/kondo.py +0 -21
  73. machineconfig/jobs/python_generic_installers/dev/lvim.py +0 -60
  74. machineconfig/jobs/python_generic_installers/dev/ngrok.py +0 -35
  75. machineconfig/jobs/python_generic_installers/dev/opencommit.py +0 -21
  76. machineconfig/jobs/python_generic_installers/dev/qrcp.py +0 -25
  77. machineconfig/jobs/python_generic_installers/dev/qrscan.py +0 -16
  78. machineconfig/jobs/python_generic_installers/dev/rust-analyzer.py +0 -24
  79. machineconfig/jobs/python_generic_installers/dev/termscp.py +0 -23
  80. machineconfig/jobs/python_generic_installers/dev/tldr.py +0 -25
  81. machineconfig/jobs/python_generic_installers/dev/tokei.py +0 -24
  82. machineconfig/jobs/python_generic_installers/diskonaut.py +0 -26
  83. machineconfig/jobs/python_generic_installers/dua.py +0 -21
  84. machineconfig/jobs/python_generic_installers/evcxr.py +0 -21
  85. machineconfig/jobs/python_generic_installers/gitui.py +0 -23
  86. machineconfig/jobs/python_generic_installers/gopass.py +0 -19
  87. machineconfig/jobs/python_generic_installers/helix.py +0 -45
  88. machineconfig/jobs/python_generic_installers/kondo.py +0 -20
  89. machineconfig/jobs/python_generic_installers/lf.py +0 -25
  90. machineconfig/jobs/python_generic_installers/lvim.py +0 -34
  91. machineconfig/jobs/python_generic_installers/mprocs.py +0 -20
  92. machineconfig/jobs/python_generic_installers/navi.py +0 -20
  93. machineconfig/jobs/python_generic_installers/ots.py +0 -26
  94. machineconfig/jobs/python_generic_installers/ouch.py +0 -25
  95. machineconfig/jobs/python_generic_installers/pomodoro.py +0 -19
  96. machineconfig/jobs/python_generic_installers/procs.py +0 -20
  97. machineconfig/jobs/python_generic_installers/qrcp.py +0 -22
  98. machineconfig/jobs/python_generic_installers/qrscan.py +0 -14
  99. machineconfig/jobs/python_generic_installers/rclone.py +0 -21
  100. machineconfig/jobs/python_generic_installers/rust-analyzer.py +0 -24
  101. machineconfig/jobs/python_generic_installers/tere.py +0 -26
  102. machineconfig/jobs/python_generic_installers/termscp.py +0 -23
  103. machineconfig/jobs/python_generic_installers/tldr.py +0 -24
  104. machineconfig/jobs/python_generic_installers/tokei.py +0 -21
  105. machineconfig/jobs/python_generic_installers/vtm.py +0 -26
  106. machineconfig/jobs/python_generic_installers/watchexec.py +0 -21
  107. machineconfig/jobs/python_linux_installers/archive/__init__.py +0 -0
  108. machineconfig/jobs/python_linux_installers/archive/ranger.py +0 -18
  109. machineconfig/jobs/python_linux_installers/bandwhich.py +0 -11
  110. machineconfig/jobs/python_linux_installers/bottom.py +0 -17
  111. machineconfig/jobs/python_linux_installers/btop.py +0 -17
  112. machineconfig/jobs/python_linux_installers/dev/bandwhich.py +0 -13
  113. machineconfig/jobs/python_linux_installers/dev/bytehound.py +0 -20
  114. machineconfig/jobs/python_linux_installers/dev/nnn.py +0 -21
  115. machineconfig/jobs/python_linux_installers/gotty.py +0 -16
  116. machineconfig/jobs/python_linux_installers/joshuto.py +0 -28
  117. machineconfig/jobs/python_linux_installers/mcfly.py +0 -12
  118. machineconfig/jobs/python_linux_installers/nnn.py +0 -18
  119. machineconfig/jobs/python_linux_installers/topgrade.py +0 -15
  120. machineconfig/jobs/python_linux_installers/viu.py +0 -19
  121. machineconfig/jobs/python_linux_installers/xplr.py +0 -22
  122. machineconfig/jobs/python_linux_installers/zellij.py +0 -31
  123. machineconfig/jobs/python_windows_installers/archive/ntop.py +0 -20
  124. machineconfig/jobs/python_windows_installers/bat.py +0 -16
  125. machineconfig/jobs/python_windows_installers/boxes.py +0 -19
  126. machineconfig/jobs/python_windows_installers/bypass_paywall.py +0 -18
  127. machineconfig/jobs/python_windows_installers/dev/bypass_paywall.py +0 -21
  128. machineconfig/jobs/python_windows_installers/dev/obs_background_removal_plugin.py +0 -20
  129. machineconfig/jobs/python_windows_installers/fd.py +0 -17
  130. machineconfig/jobs/python_windows_installers/fzf.py +0 -19
  131. machineconfig/jobs/python_windows_installers/obs_background_removal_plugin.py +0 -19
  132. machineconfig/jobs/python_windows_installers/rg.py +0 -15
  133. machineconfig/jobs/python_windows_installers/ugrep.py +0 -14
  134. machineconfig/jobs/python_windows_installers/zoomit.py +0 -20
  135. machineconfig/jobs/python_windows_installers/zoxide.py +0 -20
  136. machineconfig/profile/fix_shell_profiles.py +0 -8
  137. machineconfig/scripts/python/archive/__init__.py +0 -0
  138. machineconfig/scripts/python/archive/bu_gdrive_rx.py +0 -41
  139. machineconfig/scripts/python/archive/bu_gdrive_sx.py +0 -40
  140. machineconfig/scripts/python/archive/bu_onedrive_rx.py +0 -59
  141. machineconfig/scripts/python/archive/bu_onedrive_sx.py +0 -45
  142. machineconfig/scripts/python/chatgpt.py +0 -28
  143. machineconfig/scripts/python/choose_ohmybash_theme.py +0 -25
  144. machineconfig/scripts/python/choose_ohmyposh_theme.py +0 -40
  145. machineconfig/scripts/python/cloud_rx.py +0 -42
  146. machineconfig/scripts/python/cloud_sx.py +0 -40
  147. machineconfig/scripts/python/ftprx.py +0 -37
  148. machineconfig/scripts/python/ftpsx.py +0 -36
  149. machineconfig/scripts/python/im2text.py +0 -15
  150. machineconfig/scripts/python/tmate_conn.py +0 -28
  151. machineconfig/scripts/python/tmate_start.py +0 -31
  152. machineconfig/utils/to_exe.py +0 -7
  153. machineconfig-1.5.dist-info/RECORD +0 -147
  154. /machineconfig/jobs/{python_generic_installers/archive → script_installer}/__init__.py +0 -0
  155. {machineconfig-1.5.dist-info → machineconfig-1.8.dist-info}/top_level.txt +0 -0
@@ -1,87 +1,119 @@
1
-
2
- from platform import system
3
- # import subprocess
4
- # import crocodile.toolbox as tb
5
- from machineconfig.utils.utils import display_options, PROGRAM_PATH, write_shell_script
6
- from enum import Enum
7
-
8
-
9
- class Options(Enum):
10
- update = 'UPDATE essential repos'
11
- devaps = 'DEVAPPS install'
12
- ve = 'VE install'
13
- sym_path_shell = 'SYMLINKS, PATH & SHELL PROFILE'
14
- sym_new = 'SYMLINKS new'
15
- ssh_add_pubkey = 'SSH add pub key to this machine'
16
- ssh_add_id = 'SSH add identity (private key) to this machine'
17
- ssh_use_pair = 'SSH use key pair to connect two machines'
18
- ssh_setup = 'SSH setup'
19
- ssh_setup_wsl = 'SSH setup wsl'
20
- backup = 'BACKUP & RETRIEVE'
21
-
22
-
23
- def args_parser():
24
- import argparse
25
- parser = argparse.ArgumentParser()
26
- parser.add_argument("-w", "--which", help="which option to run", type=str, default=None) # , choices=[op.value for op in Options]
27
- args = parser.parse_args()
28
- main(which=args.which)
29
-
30
-
31
- def main(which=None):
32
- PROGRAM_PATH.delete(sure=True, verbose=False)
33
- options = [op.value for op in Options]
34
- if which is None: choice_key = display_options(msg="", options=options, header="DEVOPS", default=options[0])
35
- else: choice_key = Options[which].value
36
-
37
- if choice_key == Options.update.value:
38
- import machineconfig.scripts.python.devops_update_repos as helper
39
- program = helper.main()
40
-
41
- elif choice_key == Options.ve.value:
42
- import machineconfig.jobs.python.python_ve_installer as helper
43
- program = helper.main()
44
-
45
- elif choice_key == Options.devaps.value:
46
- import machineconfig.scripts.python.devops_devapps_install as helper
47
- program = helper.main()
48
-
49
- elif choice_key == Options.sym_new.value:
50
- import machineconfig.jobs.python.python_ve_symlink as helper
51
- program = helper.main()
52
-
53
- elif choice_key == Options.sym_path_shell.value:
54
- import machineconfig.profile.create as helper
55
- helper.main()
56
- program = "echo 'done with symlinks'"
57
-
58
- elif choice_key == Options.ssh_add_pubkey.value:
59
- import machineconfig.scripts.python.devops_add_ssh_key as helper
60
- program = helper.main()
61
-
62
- elif choice_key == Options.ssh_use_pair.value:
63
- raise NotImplementedError
64
-
65
- elif choice_key == Options.ssh_add_id.value: # so that you can SSH directly withuot pointing to identity key.
66
- import machineconfig.scripts.python.devops_add_identity as helper
67
- program = helper.main()
68
-
69
- elif choice_key == Options.ssh_setup.value:
70
- 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"""
71
- 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"""
72
- program = program_linux if system() == "Linux" else program_windows
73
-
74
- elif choice_key == Options.ssh_setup_wsl.value:
75
- program = f"""curl https://raw.githubusercontent.com/thisismygitrepo/machineconfig/main/src/machineconfig/setup_linux/openssh_wsl.sh | sudo bash"""
76
-
77
- elif choice_key == Options.backup.value:
78
- from machineconfig.scripts.python.devops_backup_retrieve import main
79
- program = main()
80
-
81
- else: raise ValueError(f"Unimplemented choice: {choice_key}")
82
- 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)
83
- else: write_shell_script("echo 'Done.'", display=False, ) # Python did not return any script to run.
84
-
85
-
86
- if __name__ == "__main__":
87
- args_parser()
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
- import crocodile.toolbox as tb
4
- # from platform import system
5
- from machineconfig.utils.utils import display_options
6
-
7
-
8
- def main():
9
- private_keys = tb.P.home().joinpath(".ssh").search("*.pub").apply(lambda x: x.with_name(x.stem)).filter(lambda x: x.exists())
10
- choice = display_options(msg="Path to private key to be used when ssh'ing: ", options=private_keys.list + ["I have the path to the key file", "I want to paste the key itself"])
11
- if choice == "I have the path to the key file": path_to_key = tb.P(input("Input path here: ")).expanduser().absolute()
12
- elif choice == "I want to paste the key itself": path_to_key = tb.P.home().joinpath(f".ssh/{input('file name (default: my_pasted_key): ') or 'my_pasted_key'}").write_text(input("Paste the private key here: "))
13
- else: path_to_key = tb.P(choice)
14
- txt = f"IdentityFile {path_to_key.collapseuser().as_posix()}" # adds this id for all connections, no host specified.
15
- config_path = tb.P.home().joinpath(".ssh/config")
16
- 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`
17
- else: config_path.write_text(txt)
18
- program = f"echo 'Finished adding identity to ssh config file. {'*'*50} Consider reloading config file.'"
19
- return program
20
-
21
-
22
- if __name__ == '__main__':
23
- pass
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
- import crocodile.toolbox as tb
3
- from platform import system
4
- from machineconfig.utils.utils import LIBRARY_ROOT, display_options
5
-
6
-
7
- def get_add_ssh_key_script(path_to_key):
8
- if system() == "Linux": authorized_keys = tb.P.home().joinpath(".ssh/authorized_keys")
9
- elif system() == "Windows": authorized_keys = tb.P("C:/ProgramData/ssh/administrators_authorized_keys")
10
- else: raise NotImplementedError
11
-
12
- if authorized_keys.exists():
13
- split = "\n"
14
- print(f'Users that can access this machine have private keys of those pub keys:\n{authorized_keys.read_text().split(split)}')
15
-
16
- if path_to_key.read_text() in authorized_keys.read_text():
17
- program = ""
18
- else:
19
- if system() == "Linux":
20
- program = f"cat {path_to_key} >> ~/.ssh/authorized_keys"
21
- else:
22
- program = LIBRARY_ROOT.joinpath("jobs/windows/openssh-server_add_key.ps1")
23
- program = tb.P(program).expanduser().read_text().replace('$sshfile=""', f'$sshfile="{path_to_key}"')
24
-
25
- else:
26
- if system() == "Linux":
27
- program = f"cat {path_to_key} > ~/.ssh/authorized_keys"
28
- else:
29
- program = LIBRARY_ROOT.joinpath("jobs/windows/openssh-server_add_key.ps1")
30
- program = tb.P(program).expanduser().read_text().replace('$sshfile=""', f'$sshfile="{path_to_key}"')
31
-
32
- if system() == "Linux" and 2 > 1: program += f"""
33
-
34
- sudo chmod 700 ~/.ssh
35
- sudo chmod 644 ~/.ssh/authorized_keys
36
- sudo chmod 644 ~/.ssh/*.pub
37
- sudo service ssh --full-restart
38
- # from superuser.com/questions/215504/permissions-on-private-key-in-ssh-folder
39
-
40
- """
41
- return program
42
-
43
-
44
- def main():
45
- pub_keys = tb.P.home().joinpath(".ssh").search("*.pub")
46
- res = display_options("Which public key to add? ", options=pub_keys.list + [f"all pub keys available ({len(pub_keys)})", "I have the path to the key file", "I want to paste the key itself"])
47
- if res == "all": program = "\n\n\n".join(pub_keys.apply(get_add_ssh_key_script))
48
- elif res == "I have the path to the key file": program = get_add_ssh_key_script(tb.P(input("Path: ")).expanduser().absolute())
49
- elif res == "I want to paste the key itself": program = get_add_ssh_key_script(tb.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: ")))
50
- else: program = get_add_ssh_key_script(tb.P(res))
51
- return program
52
-
53
-
54
- if __name__ == '__main__':
55
- pass
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
- from platform import system
3
- # import subprocess
4
- import crocodile.toolbox as tb
5
- from machineconfig.utils.utils import LIBRARY_ROOT, display_options, print_programming_script
6
-
7
-
8
- def main():
9
- direction = display_options(msg="BACKUP OR RETRIEVE?", options=["BACKUP", "RETRIEVE"], default="BACKUP", fzf=True)
10
- tool = "cloud_sx" if direction == "BACKUP" else "cloud_rx"
11
-
12
- print(f"Listing Remotes ... ")
13
- remotes = tb.L(tb.Terminal().run("rclone listremotes", shell="pwsh").op_if_successfull_or_default("").splitlines()).apply(lambda x: x.replace(":", ""))
14
- if len(remotes) == 0:
15
- raise RuntimeError(f"You don't have remotes. Configure your rclone first to get cloud services access.")
16
- cloud = display_options(msg="WHICH CLOUD?", options=list(remotes), default=remotes[0], fzf=True)
17
-
18
- bu_file = LIBRARY_ROOT.joinpath("profile/backup.toml").readit()
19
-
20
- if system() == "Linux": bu_file = {key: val for key, val in bu_file.items() if "windows" not in key}
21
- elif system() == "Windows": bu_file = {key: val for key, val in bu_file.items() if "linux" not in key}
22
-
23
- # choice_key = display_options(msg="WHICH FILE of the following do you want to back up?", options=['all'] + list(bu_file.keys()), default="dotfiles")
24
- # if choice_key == "all": items = bu_file
25
- # else: items = {choice_key: bu_file[choice_key]}
26
- items = bu_file
27
-
28
- program = f"""$cloud = "{cloud}" \n """ if system() == "Windows" else f"""cloud="{cloud}" \n """
29
- for item_name, item in items.items():
30
- path = tb.P(item['path'])
31
- os_specific = True if system().lower() in item_name else False
32
- flags = ''
33
- flags += 'z' if item['zip'] else ''
34
- flags += 'e' if item['encrypt'] else ''
35
- flags += 'r'
36
- flags += 'o' if os_specific else ''
37
- if flags: flags = f"-{flags}"
38
- program += f"""\n{tool} "{path.as_posix()}" --cloud $cloud {flags}\n"""
39
- if item_name == "dotfiles" and system() == "Linux": program += f"""\nchmod 700 ~/.ssh/*\n"""
40
- print_programming_script(program, lexer="shell", desc=f"{direction} script")
41
- print(program)
42
- return ""
43
-
44
-
45
- if __name__ == "__main__":
46
- pass
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