Better OS checks

This commit is contained in:
AlexSSD7 2023-09-02 11:28:23 +01:00
commit 58039acc3c
9 changed files with 48 additions and 29 deletions

View file

@ -4,10 +4,10 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"log/slog"
"github.com/AlexSSD7/linsk/osspecifics"
"github.com/spf13/cobra"
)
@ -64,7 +64,7 @@ func init() {
slog.Error("Failed to get user home directory, will use a local directory as a fallback", "error", err.Error(), "dir", defaultDataDir)
} else {
homeDirName := ".linsk"
if runtime.GOOS == "windows" {
if osspecifics.IsWindows() {
homeDirName = "Linsk"
}

View file

@ -5,9 +5,9 @@ import (
"fmt"
"log/slog"
"os"
"runtime"
"strings"
"github.com/AlexSSD7/linsk/osspecifics"
"github.com/AlexSSD7/linsk/share"
"github.com/AlexSSD7/linsk/vm"
"github.com/sethvargo/go-password/password"
@ -126,10 +126,10 @@ func init() {
runCmd.Flags().BoolVar(&debugShellFlag, "debug-shell", false, "Start a VM shell when the network file share is active.")
var defaultShareType string
switch runtime.GOOS {
case "windows":
switch {
case osspecifics.IsWindows():
defaultShareType = "smb"
case "darwin":
case osspecifics.IsMacOS():
defaultShareType = "afp"
default:
defaultShareType = "ftp"

View file

@ -4,9 +4,9 @@ import (
"context"
"log/slog"
"os"
"runtime"
"strings"
"github.com/AlexSSD7/linsk/osspecifics"
"github.com/AlexSSD7/linsk/share"
"github.com/AlexSSD7/linsk/vm"
"github.com/pkg/errors"
@ -94,7 +94,7 @@ func runVMShell(ctx context.Context, vi *vm.VM) error {
}()
termFDGetSize := termFD
if runtime.GOOS == "windows" {
if osspecifics.IsWindows() {
// Workaround for Windows.
termFDGetSize = int(os.Stdout.Fd())
}

View file

@ -6,7 +6,6 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
@ -74,11 +73,11 @@ func runVM(passthroughArg string, fn runVMFunc, forwardPortsRules []vm.PortForwa
// libusbK driver, which nullifies the UX. This is a problem with how QEMU works, and unfortunately there isn't
// much we can do about it from our side.
switch runtime.GOOS {
case "windows":
switch {
case osspecifics.IsWindows():
// TODO: To document: installation of libusbK driver with Zadig utility.
slog.Warn("USB passthrough is unstable on Windows and requires installation of libusbK driver. Please consider using raw block device passthrough instead.")
case "darwin":
case osspecifics.IsMacOS():
slog.Warn("USB passthrough is unstable on macOS. Please consider using raw block device passthrough instead.")
}
}
@ -235,11 +234,12 @@ func innerRunVM(vmCfg vm.VMConfig, tapRuntimeCtx *share.NetTapRuntimeContext, fn
case sig := <-interrupt:
lg := slog.With("signal", sig)
if i == 0 {
switch {
case i == 0:
lg.Warn("Caught interrupt, safely shutting down")
} else if i < 10 {
case i < 10:
lg.Warn("Caught subsequent interrupt, please interrupt n more times to panic", "n", 10-i)
} else {
default:
panic("force interrupt")
}