parent
887ef88ba9
commit
70a8fd3e93
4 changed files with 27 additions and 22 deletions
|
@ -2,6 +2,7 @@ import os
|
|||
|
||||
from cd.project import Project
|
||||
from cd.projects import Projects
|
||||
from rwx import fs
|
||||
from rwx import ps
|
||||
|
||||
COMMANDS_PREFIX = 'cd-'
|
||||
|
@ -50,7 +51,7 @@ def cd_clone_branch():
|
|||
|
||||
|
||||
def cd_list_environment():
|
||||
for variable, value in sorted(os.environ.items()):
|
||||
for variable, value in sorted(projects.environment.items()):
|
||||
print(variable, '=', value)
|
||||
|
||||
|
||||
|
@ -64,3 +65,25 @@ def install_commands(path):
|
|||
]:
|
||||
print(command)
|
||||
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}'))
|
||||
|
||||
|
||||
def set_ssh():
|
||||
ssh_hosts = projects.environment.get('CD_SSH_HOSTS', None)
|
||||
ssh_key = projects.environment.get('CD', None)
|
||||
ssh_type = projects.environment.get('CD_SSH_TYPE', 'ed25519')
|
||||
#
|
||||
home = os.path.expanduser('~')
|
||||
#
|
||||
ssh = os.path.join(home, '.ssh')
|
||||
os.makedirs(ssh, exist_ok=True)
|
||||
os.chmod(ssh, 0o700)
|
||||
#
|
||||
key = os.path.join(ssh, f'id_{ssh_type}')
|
||||
if ssh_key:
|
||||
fs.write(key, ssh_key)
|
||||
os.chmod(key, 0o400)
|
||||
#
|
||||
known = os.path.join(ssh, 'known_hosts')
|
||||
if ssh_hosts:
|
||||
fs.write(known, ssh_hosts)
|
||||
os.chmod(known, 0o400)
|
||||
|
|
|
@ -10,6 +10,7 @@ if __name__ == '__main__':
|
|||
command, *arguments = sys.argv
|
||||
command = os.path.basename(command)
|
||||
if command == '__main__.py':
|
||||
cd.set_ssh()
|
||||
cd.install_commands(__file__)
|
||||
else:
|
||||
command = command.replace('-', '_')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue