bootv2: bootstrap, vpn

This commit is contained in:
Mikaël Cluseau
2022-04-04 10:29:28 +02:00
parent 8506f8807d
commit 3c7d56ae48
17 changed files with 296 additions and 258 deletions

28
ssh.go
View File

@ -16,7 +16,7 @@ import (
"github.com/kr/pty"
"golang.org/x/crypto/ssh"
"novit.nc/direktil/initrd/config"
config "novit.tech/direktil/pkg/bootstrapconfig"
)
func startSSH(cfg *config.Config) {
@ -118,7 +118,7 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
}()
var once sync.Once
close := func() {
closeCh := func() {
channel.Close()
}
@ -130,11 +130,27 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
case "init":
go func() {
io.Copy(channel, stdout.NewReader())
once.Do(close)
once.Do(closeCh)
}()
go func() {
io.Copy(stdinPipe, channel)
once.Do(close)
once.Do(closeCh)
}()
req.Reply(true, nil)
case "bootstrap":
// extract a new bootstrap package
os.MkdirAll("/bootstrap/current", 0750)
cmd := exec.Command("/bin/tar", "xv", "-C", "/bootstrap/current")
cmd.Stdin = channel
cmd.Stdout = channel
cmd.Stderr = channel.Stderr()
go func() {
cmd.Run()
closeCh()
}()
req.Reply(true, nil)
@ -167,11 +183,11 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
go func() {
io.Copy(channel, ptyF)
once.Do(close)
once.Do(closeCh)
}()
go func() {
io.Copy(ptyF, channel)
once.Do(close)
once.Do(closeCh)
}()
req.Reply(true, nil)