ssh/wip
Some checks failed
/ job (push) Failing after 8s

This commit is contained in:
Marc Beninca 2024-05-31 00:29:12 +02:00
parent 887ef88ba9
commit 70a8fd3e93
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
4 changed files with 27 additions and 22 deletions

View file

@ -1,21 +0,0 @@
#! /usr/bin/env bash
KEY_ALGORITHM='ed25519'
KEY_DIRECTORY='.ssh'
KEY_PATH="${KEY_DIRECTORY}/id_${KEY_ALGORITHM}"
KEY_PUBLIC='AAAAC3NzaC1lZDI1NTE5AAAAIPHCNcgHlQoiNTXfnUZYvHz9OZwYsmBCrSSV7a7Zche5'
SERVER="$(basename ${GITHUB_SERVER_URL})"
# ssh
cd \
|| exit
mkdir "${KEY_DIRECTORY}" \
|| exit
echo "${CD}" > "${KEY_PATH}" \
|| exit
unset CD
chmod '400' "${KEY_PATH}" \
|| exit
echo "${SERVER} ssh-${KEY_ALGORITHM} ${KEY_PUBLIC}" \
> "${KEY_DIRECTORY}/known_hosts" \
|| exit

View file

@ -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)

View file

@ -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('-', '_')

View file

@ -41,6 +41,8 @@ from various CA, CI, OCI / OS.
|:--------------|:------------------------|
| CD_CA_n | Numbered CA certificate |
| CD_DNS | Space separated servers |
| CD_SSH_HOSTS | domain.tld ssh-type pub |
| CD_SSH_TYPE | SSH private key type |
| CD_URL_ALMA | Alma repository URL |
| CD_URL_ALPINE | Alpine repository URL |
| CD_URL_ARCH | Arch repository URL |