bootv2: bootstrap, vpn
This commit is contained in:
28
ssh.go
28
ssh.go
@ -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)
|
||||
|
Reference in New Issue
Block a user