@@ -276,17 +276,62 @@ func (m ModJobSshStruct) genOrGetKey() {
276276 }
277277 util.MainNodeConfWriter {}.WriteSecretConf (util.SecretConfTypeSshPrivate {}, string (localpri ))
278278
279- _ , err = os .ReadFile (ed25519PubFilePath )
279+ localpub , err : = os .ReadFile (ed25519PubFilePath )
280280 if err != nil {
281281 fail = true
282282 failInfo = fmt .Sprintf ("failed to read local pub key: %v" , err )
283283 return
284284 }
285285
286- util.MainNodeConfWriter {}.WriteSecretConf (util.SecretConfTypeSshPrivate {}, string (localpri ))
286+ util.MainNodeConfWriter {}.WriteSecretConf (util.SecretConfTypeSshPublic {}, string (localpub ))
287+
288+ util .PrintStep ("ssh genOrGetKey" , color .BlueString ("uploading keys to self" ))
289+ password , ok := util .GetPassword ("设置ssh免密访问需要配置密码" )
290+ if ! ok {
291+ fmt .Println ("User canceled config ssh no pw access" )
292+ os .Exit (1 )
293+ }
294+ m .setupClusterInner (clusterconf.ClusterConfYmlModel {
295+ Global : clusterconf.ClusterConfYmlModelGlobal {
296+ SshUser : util .MainNodeUser ,
297+ SshPasswd : password ,
298+ },
299+ Nodes : map [string ]clusterconf.ClusterConfYmlModelNode {
300+ "dummy" : {
301+ Ip : util .MainNodeIp ,
302+ },
303+ },
304+ })
287305 }
288306}
289307
308+ func (m ModJobSshStruct ) setupClusterInner (clusterConf clusterconf.ClusterConfYmlModel ) {
309+ // 打印解析后的内容
310+ fmt .Printf ("集群配置: %+v\n " , clusterConf )
311+
312+ hosts := funk .Map (clusterConf .Nodes , func (_ string , node clusterconf.ClusterConfYmlModelNode ) string {
313+ return fmt .Sprintf ("%s@%s" , clusterConf .Global .SshUser , node .Ip )
314+ }).([]string )
315+
316+ // read pubkey
317+ pubkeyFile := filepath .Join (homedir .HomeDir (), ".ssh" , "id_ed25519.pub" )
318+ pubkeybytes , err := os .ReadFile (pubkeyFile )
319+ if err != nil {
320+ fmt .Println (color .RedString ("read pubkey failed: %v" , err ))
321+ os .Exit (1 )
322+ }
323+ _ = base64 .StdEncoding .EncodeToString (pubkeybytes )
324+
325+ util .StartRemoteCmds (
326+ hosts ,
327+ // install telego,
328+ util .ModRunCmd .CmdModels ().InstallTelegoWithPy ()+ " && " +
329+ // update authorized_keys
330+ strings .Join (m .NewSshCmd (SshJob {Mode : SshModeSetupThisNode }.ModeString ()), " " ),
331+ clusterConf .Global .SshPasswd ,
332+ )
333+ }
334+
290335// https://qcnoe3hd7k5c.feishu.cn/wiki/V6eHwZm1aiofeykaSd5cmgPcnSe#share-Hc1hdGT26oI4I0xPaplcEhMundd
291336func (m ModJobSshStruct ) setupCluster () {
292337 ok , yamlFilePath := util .StartTemporaryInputUI (color .GreenString (
@@ -313,30 +358,7 @@ func (m ModJobSshStruct) setupCluster() {
313358 os .Exit (1 )
314359 }
315360
316- // 打印解析后的内容
317- fmt .Printf ("解析后的集群配置: %+v\n " , clusterConf )
318-
319- hosts := funk .Map (clusterConf .Nodes , func (nodename string , node clusterconf.ClusterConfYmlModelNode ) string {
320- return fmt .Sprintf ("%s@%s" , clusterConf .Global .SshUser , node .Ip )
321- }).([]string )
322-
323- // read pubkey
324- pubkeyFile := filepath .Join (homedir .HomeDir (), ".ssh" , "id_ed25519.pub" )
325- pubkeybytes , err := os .ReadFile (pubkeyFile )
326- if err != nil {
327- fmt .Println (color .RedString ("read pubkey failed: %v" , err ))
328- os .Exit (1 )
329- }
330- _ = base64 .StdEncoding .EncodeToString (pubkeybytes )
331-
332- util .StartRemoteCmds (
333- hosts ,
334- // install telego,
335- util .ModRunCmd .CmdModels ().InstallTelegoWithPy ()+ " && " +
336- // update authorized_keys
337- strings .Join (m .NewSshCmd (SshJob {Mode : SshModeSetupThisNode }.ModeString ()), " " ),
338- clusterConf .Global .SshPasswd ,
339- )
361+ m .setupClusterInner (clusterConf )
340362}
341363
342364func (m ModJobSshStruct ) NewSshCmd (
0 commit comments