Some work on supporting Windows
This commit is contained in:
parent
a8f5af7bd0
commit
2f1d4ae60d
9 changed files with 109 additions and 19 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
|
@ -69,8 +70,13 @@ func NewBuildContext(logger *slog.Logger, baseISOPath string, outPath string, sh
|
|||
|
||||
func createQEMUImg(outPath string) error {
|
||||
outPath = filepath.Clean(outPath)
|
||||
baseCmd := "qemu-img"
|
||||
|
||||
err := exec.Command("qemu-img", "create", "-f", "qcow2", outPath, "1G").Run()
|
||||
if runtime.GOOS == "windows" {
|
||||
baseCmd += ".exe"
|
||||
}
|
||||
|
||||
err := exec.Command(baseCmd, "create", "-f", "qcow2", outPath, "1G").Run()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "run qemu-img create cmd")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ var runCmd = &cobra.Command{
|
|||
return 1
|
||||
}
|
||||
|
||||
// TODO: Use FTP instead of SMB
|
||||
|
||||
shareURI := "smb://linsk:" + sharePWD + "@127.0.0.1:" + fmt.Sprint(networkSharePort)
|
||||
|
||||
fmt.Fprintf(os.Stderr, "================\n[Network File Share Config]\nThe network file share was started. Please use the credentials below to connect to the file server.\n\nType: SMB\nServer Address: smb://127.0.0.1:%v\nUsername: linsk\nPassword: %v\n\nShare URI: %v\n================\n", networkSharePort, sharePWD, shareURI)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/AlexSSD7/linsk/vm"
|
||||
|
|
@ -70,7 +71,13 @@ var shellCmd = &cobra.Command{
|
|||
}
|
||||
}()
|
||||
|
||||
termWidth, termHeight, err := term.GetSize(termFD)
|
||||
termFDGetSize := termFD
|
||||
if runtime.GOOS == "windows" {
|
||||
// Another Windows workaround :/
|
||||
termFDGetSize = int(os.Stdout.Fd())
|
||||
}
|
||||
|
||||
termWidth, termHeight, err := term.GetSize(termFDGetSize)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get terminal size", "error", err)
|
||||
return 1
|
||||
|
|
|
|||
20
cmd/utils.go
20
cmd/utils.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
|
|
@ -24,7 +25,19 @@ func checkIfRoot() (bool, error) {
|
|||
return currentUser.Username == "root", nil
|
||||
}
|
||||
|
||||
func doRootCheck() {
|
||||
func doUSBRootCheck() {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
// Root privileges is not required in macOS.
|
||||
return
|
||||
case "windows":
|
||||
// Administrator privileges are not required in Windows.
|
||||
return
|
||||
default:
|
||||
// As for everything else, we will likely need root privileges
|
||||
// for the USB passthrough.
|
||||
}
|
||||
|
||||
ok, err := checkIfRoot()
|
||||
if err != nil {
|
||||
slog.Error("Failed to check whether the command is ran by root", "error", err)
|
||||
|
|
@ -32,18 +45,17 @@ func doRootCheck() {
|
|||
}
|
||||
|
||||
if !ok {
|
||||
slog.Error("You must run this program as root")
|
||||
slog.Error("USB passthrough on your OS requires this program to be ran as root")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManager) int, forwardPortsRules []vm.PortForwardingRule, unrestrictedNetworking bool) int {
|
||||
doRootCheck()
|
||||
|
||||
var passthroughConfig []vm.USBDevicePassthroughConfig
|
||||
|
||||
if passthroughArg != "" {
|
||||
passthroughConfig = []vm.USBDevicePassthroughConfig{getDevicePassthroughConfig(passthroughArg)}
|
||||
doUSBRootCheck()
|
||||
}
|
||||
|
||||
vmCfg := vm.VMConfig{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue