[ Agent ] [ BASE ] - add default ssh key install
This commit is contained in:
@@ -67,6 +67,9 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) (bool,
|
||||
case "installDockerCompose":
|
||||
resultOk, errorLog = op.installDockerComposeExec()
|
||||
break
|
||||
case "installDefaultSSHKey":
|
||||
resultOk, errorLog = op.installDefaultSSHKeyExec(funcArgs)
|
||||
break
|
||||
case "modifyDockerConfig":
|
||||
resultOk, errorLog = op.modifyDockerConfigExec(funcArgs)
|
||||
break
|
||||
@@ -316,6 +319,46 @@ func (op *AgentOsOperator) disableSwapExec() (bool, []string) {
|
||||
return true, resultLog
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []string) {
|
||||
|
||||
// ssh-keygen -t ed25519 -C "wdd@cmii.com" -N "octopus_standard_phrase"
|
||||
|
||||
// check key exists
|
||||
if BasicFileExistAndNotNull("/root/.ssh/id_ed25519") {
|
||||
if BasicFileExistAndNotNull("/root/.ssh/id_ed25519.pub") {
|
||||
if BasicGrepItemInFile("wdd@cmii.com", "/root/.ssh/authorized_keys") {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// download standard private and public key
|
||||
ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+"id_ed25519_private_key", "/root/.ssh/id_ed25519")
|
||||
if !ok {
|
||||
return false, resultLog
|
||||
}
|
||||
ok, resultLog = BasicDownloadFile(op.OssOfflinePrefix+"id_ed25519_public_key.pub", "/root/.ssh/id_ed25519.pub")
|
||||
if !ok {
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
// write into authorized_keys
|
||||
if !BasicAppendSourceToFile("/root/.ssh/id_ed25519.pub", "/root/.ssh/authorized_keys") {
|
||||
return false, []string{
|
||||
"[installDefaultSSHKeyExec] - error appending ssh key to authorized_keys !",
|
||||
}
|
||||
}
|
||||
|
||||
// check
|
||||
if BasicGrepItemInFile("wdd@cmii.com", "/root/.ssh/authorized_keys") {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, []string{
|
||||
"[installDefaultSSHKeyExec] - authorized_keys don't contain the ssh-pub key !",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) removeDocker() [][]string {
|
||||
|
||||
removeDockerLine := append(op.RemoveCommandPrefix, []string{
|
||||
|
||||
Reference in New Issue
Block a user