getstarted_windows.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package lifecycle
  2. import (
  3. "fmt"
  4. "log/slog"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "syscall"
  9. )
  10. func GetStarted() error {
  11. const CREATE_NEW_CONSOLE = 0x00000010
  12. var err error
  13. bannerScript := filepath.Join(AppDir, "ollama_welcome.ps1")
  14. args := []string{
  15. // TODO once we're signed, the execution policy bypass should be removed
  16. "powershell", "-noexit", "-ExecutionPolicy", "Bypass", "-nologo", "-file", bannerScript,
  17. }
  18. args[0], err = exec.LookPath(args[0])
  19. if err != nil {
  20. return err
  21. }
  22. // Make sure the script actually exists
  23. _, err = os.Stat(bannerScript)
  24. if err != nil {
  25. return fmt.Errorf("getting started banner script error %s", err)
  26. }
  27. slog.Info(fmt.Sprintf("opening getting started terminal with %v", args))
  28. attrs := &os.ProcAttr{
  29. Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
  30. Sys: &syscall.SysProcAttr{CreationFlags: CREATE_NEW_CONSOLE, HideWindow: false},
  31. }
  32. proc, err := os.StartProcess(args[0], args, attrs)
  33. if err != nil {
  34. return fmt.Errorf("unable to start getting started shell %w", err)
  35. }
  36. slog.Debug(fmt.Sprintf("getting started terminal PID: %d", proc.Pid))
  37. return proc.Release()
  38. }