blob: 68f3c36274e7c87511ca03838b496497eae82dea [file] [log] [blame]
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04001package main
2
3import (
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04004 "golang.org/x/crypto/ssh"
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04005 "os"
6
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04007 "github.com/spf13/cobra"
8
9 "github.com/giolekva/pcloud/core/installer"
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040010 "github.com/giolekva/pcloud/core/installer/soft"
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040011 "github.com/giolekva/pcloud/core/installer/welcome"
12)
13
14var welcomeFlags struct {
15 repo string
16 sshKey string
17 port int
18}
19
20func welcomeCmd() *cobra.Command {
21 cmd := &cobra.Command{
22 Use: "welcome",
23 RunE: welcomeCmdRun,
24 }
25 cmd.Flags().StringVar(
26 &welcomeFlags.repo,
27 "repo-addr",
28 "",
29 "",
30 )
31 cmd.Flags().StringVar(
32 &welcomeFlags.sshKey,
33 "ssh-key",
34 "",
35 "",
36 )
37 cmd.Flags().IntVar(
38 &welcomeFlags.port,
39 "port",
40 8080,
41 "",
42 )
43 return cmd
44}
45
46func welcomeCmdRun(cmd *cobra.Command, args []string) error {
47 sshKey, err := os.ReadFile(welcomeFlags.sshKey)
48 if err != nil {
49 return err
50 }
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040051 signer, err := ssh.ParsePrivateKey(sshKey)
52 if err != nil {
53 return err
54 }
55 addr, err := soft.ParseRepositoryAddress(welcomeFlags.repo)
56 if err != nil {
57 return err
58 }
Giorgi Lekveishvili57dffb32023-08-07 15:45:43 +040059 repo, err := soft.CloneRepository(addr, signer)
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040060 if err != nil {
61 return err
62 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040063 nsCreator, err := newNSCreator()
64 if err != nil {
65 return err
66 }
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040067 s := welcome.NewServer(
68 welcomeFlags.port,
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040069 installer.NewRepoIO(repo, signer),
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040070 nsCreator,
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040071 )
72 s.Start()
73 return nil
74}