Restore working state
This commit is contained in:
parent
f9cdbe5ac9
commit
3cbe45c420
7 changed files with 55 additions and 34 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package builder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
|
@ -13,6 +14,7 @@ import (
|
|||
|
||||
"log/slog"
|
||||
|
||||
"github.com/AlexSSD7/linsk/utils"
|
||||
"github.com/AlexSSD7/linsk/vm"
|
||||
"github.com/alessio/shellescape"
|
||||
"github.com/pkg/errors"
|
||||
|
|
@ -176,6 +178,9 @@ func runAlpineSetupCmd(sc *ssh.Client, pkgs []string) error {
|
|||
|
||||
// TODO: Timeout for this command.
|
||||
|
||||
stderr := bytes.NewBuffer(nil)
|
||||
sess.Stderr = stderr
|
||||
|
||||
defer func() {
|
||||
_ = sess.Close()
|
||||
}()
|
||||
|
|
@ -191,9 +196,11 @@ func runAlpineSetupCmd(sc *ssh.Client, pkgs []string) error {
|
|||
cmd += " && mount /dev/vda3 /mnt && chroot /mnt apk add " + strings.Join(pkgsQuoted, " ")
|
||||
}
|
||||
|
||||
cmd += `&& chroot /mnt ash -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config && addgroup -g 1000 linsk && adduser -G linsk linsk -S -u 1000'`
|
||||
|
||||
err = sess.Run(cmd)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "run setup cmd")
|
||||
return utils.WrapErrWithLog(err, "run setup cmd", stderr.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -47,7 +47,10 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManag
|
|||
}
|
||||
|
||||
vmCfg := vm.VMConfig{
|
||||
CdromImagePath: "alpine-img/alpine.qcow2",
|
||||
Drives: []vm.DriveConfig{{
|
||||
Path: "alpine.qcow2",
|
||||
SnapshotMode: true,
|
||||
}},
|
||||
|
||||
USBDevices: passthroughConfig,
|
||||
ExtraPortForwardingRules: forwardPortsRules,
|
||||
|
|
@ -111,6 +114,10 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManag
|
|||
for {
|
||||
select {
|
||||
case err := <-runErrCh:
|
||||
if err == nil {
|
||||
err = fmt.Errorf("operation canceled by user")
|
||||
}
|
||||
|
||||
slog.Error("Failed to start the VM", "error", err)
|
||||
os.Exit(1)
|
||||
case <-vi.SSHUpNotifyChan():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue