Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxin1300 committed Nov 4, 2024
1 parent cf92da5 commit 28aca1d
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,23 @@ def generate_ssh_key_pair_on_remote(
shell = sh.LocalShell()
# pass cmd through stdin rather than as arguments. It seems sudo has its own argument parsing mechanics,
# which breaks shell expansion used in cmd
cmd = '''
[ -f ~/.ssh/id_rsa ] || ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -C "Cluster internal on $(hostname)" -N ''
[ -f ~/.ssh/id_rsa.pub ] || ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
cmd = f'''
key_types=({ ' '.join(ssh_key.KeyFileManager.KNOWN_KEY_TYPES) })
for key_type in "${{key_types[@]}}"; do
if [ -f ~/.ssh/id_${{key_type}} ]; then
pub_key_file=~/.ssh/id_${{key_type}}.pub
break
fi
done
if [ -z "$pub_key_file" ]; then
key_type={ssh_key.KeyFileManager.DEFAULT_KEY_TYPE}
priv_key_file=~/.ssh/id_${{key_type}}
ssh-keygen -q -t $key_type -f $priv_key_file -C "Cluster internal on $(hostname)" -N ''
pub_key_file=$key_file.pub
fi
[ -f "$pub_key_file" ] || ssh-keygen -y -f $priv_key_file > $pub_key_file
'''
result = shell.su_subprocess_run(
local_sudoer,
Expand All @@ -1024,7 +1038,15 @@ def generate_ssh_key_pair_on_remote(
if result.returncode != 0:
raise ValueError(codecs.decode(result.stdout, 'utf-8', 'replace'))

cmd = 'cat ~/.ssh/id_rsa.pub'
cmd = f'''
key_types=({ ' '.join(ssh_key.KeyFileManager.KNOWN_KEY_TYPES) })
for key_type in "${{key_types[@]}}"; do
if [ -f ~/.ssh/id_${{key_type}} ]; then
cat ~/.ssh/id_${{key_type}}.pub
break
fi
done
'''
result = shell.su_subprocess_run(
local_sudoer,
'ssh {} {}@{} sudo -H -u {} /bin/sh'.format(constants.SSH_OPTION, remote_sudoer, remote_host, remote_user),
Expand Down

0 comments on commit 28aca1d

Please sign in to comment.