mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
Merge pull request #1237 from 24sama/patch-1
add auto-generate local ssh key in "localRuntime"
This commit is contained in:
commit
e2622aca1b
|
|
@ -84,27 +84,20 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error {
|
|||
if i.KubeConf.Arg.Artifact == "" {
|
||||
for _, host := range results {
|
||||
if host.Sudo == "" {
|
||||
fmt.Printf("%s: sudo is required. \n", host.Name)
|
||||
logger.Log.Errorf("%s: sudo is required. \n", host.Name)
|
||||
logger.Log.Errorf("%s: sudo is required.", host.Name)
|
||||
stopFlag = true
|
||||
}
|
||||
|
||||
if host.Conntrack == "" {
|
||||
fmt.Printf("%s: conntrack is required. \n", host.Name)
|
||||
logger.Log.Errorf("%s: conntrack is required. \n", host.Name)
|
||||
logger.Log.Errorf("%s: conntrack is required.", host.Name)
|
||||
stopFlag = true
|
||||
}
|
||||
|
||||
if host.Socat == "" {
|
||||
fmt.Printf("%s: socat is required. \n", host.Name)
|
||||
logger.Log.Errorf("%s: socat is required. \n", host.Name)
|
||||
logger.Log.Errorf("%s: socat is required.", host.Name)
|
||||
stopFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
if stopFlag {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("")
|
||||
|
|
@ -113,6 +106,10 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error {
|
|||
fmt.Println("https://github.com/kubesphere/kubekey#requirements-and-recommendations")
|
||||
fmt.Println("")
|
||||
|
||||
if stopFlag {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
confirmOK := false
|
||||
for !confirmOK {
|
||||
fmt.Printf("Continue this installation? [yes/no]: ")
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ import (
|
|||
"fmt"
|
||||
"github.com/kubesphere/kubekey/pkg/core/connector"
|
||||
"github.com/kubesphere/kubekey/pkg/core/util"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"runtime"
|
||||
)
|
||||
|
|
@ -39,6 +41,13 @@ func NewLocalRuntime(debug, ingoreErr bool) (LocalRuntime, error) {
|
|||
return localRuntime, fmt.Errorf("current user is %s. Please use root", u.Username)
|
||||
}
|
||||
|
||||
if output, err := exec.Command("/bin/sh", "-c", "if [ ! -f \"$HOME/.ssh/id_rsa\" ]; then ssh-keygen -t rsa -P \"\" -f $HOME/.ssh/id_rsa && ls $HOME/.ssh;fi;").CombinedOutput(); err != nil {
|
||||
return localRuntime, errors.New(fmt.Sprintf("Failed to generate public key: %v\n%s", err, string(output)))
|
||||
}
|
||||
if output, err := exec.Command("/bin/sh", "-c", "echo \"\n$(cat $HOME/.ssh/id_rsa.pub)\" >> $HOME/.ssh/authorized_keys && awk ' !x[$0]++{print > \"'$HOME'/.ssh/authorized_keys\"}' $HOME/.ssh/authorized_keys").CombinedOutput(); err != nil {
|
||||
return localRuntime, errors.New(fmt.Sprintf("Failed to copy public key to authorized_keys: %v\n%s", err, string(output)))
|
||||
}
|
||||
|
||||
name, err := os.Hostname()
|
||||
if err != nil {
|
||||
return localRuntime, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue