mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: check for .ps1 dotfiles scripts on windows (#16785)
This commit is contained in:
+17
-18
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -41,16 +42,7 @@ func (r *RootCmd) dotfiles() *serpent.Command {
|
||||
dotfilesDir = filepath.Join(cfgDir, dotfilesRepoDir)
|
||||
// This follows the same pattern outlined by others in the market:
|
||||
// https://github.com/coder/coder/pull/1696#issue-1245742312
|
||||
installScriptSet = []string{
|
||||
"install.sh",
|
||||
"install",
|
||||
"bootstrap.sh",
|
||||
"bootstrap",
|
||||
"script/bootstrap",
|
||||
"setup.sh",
|
||||
"setup",
|
||||
"script/setup",
|
||||
}
|
||||
installScriptSet = installScriptFiles()
|
||||
)
|
||||
|
||||
if cfg == "" {
|
||||
@@ -195,21 +187,28 @@ func (r *RootCmd) dotfiles() *serpent.Command {
|
||||
|
||||
_, _ = fmt.Fprintf(inv.Stdout, "Running %s...\n", script)
|
||||
|
||||
// Check if the script is executable and notify on error
|
||||
scriptPath := filepath.Join(dotfilesDir, script)
|
||||
fi, err := os.Stat(scriptPath)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("stat %s: %w", scriptPath, err)
|
||||
}
|
||||
|
||||
if fi.Mode()&0o111 == 0 {
|
||||
return xerrors.Errorf("script %q does not have execute permissions", script)
|
||||
// Permissions checks will always fail on Windows, since it doesn't have
|
||||
// conventional Unix file system permissions.
|
||||
if runtime.GOOS != "windows" {
|
||||
// Check if the script is executable and notify on error
|
||||
fi, err := os.Stat(scriptPath)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("stat %s: %w", scriptPath, err)
|
||||
}
|
||||
if fi.Mode()&0o111 == 0 {
|
||||
return xerrors.Errorf("script %q does not have execute permissions", script)
|
||||
}
|
||||
}
|
||||
|
||||
// it is safe to use a variable command here because it's from
|
||||
// a filtered list of pre-approved install scripts
|
||||
// nolint:gosec
|
||||
scriptCmd := exec.CommandContext(inv.Context(), filepath.Join(dotfilesDir, script))
|
||||
scriptCmd := exec.CommandContext(inv.Context(), scriptPath)
|
||||
if runtime.GOOS == "windows" {
|
||||
scriptCmd = exec.CommandContext(inv.Context(), "powershell", "-NoLogo", scriptPath)
|
||||
}
|
||||
scriptCmd.Dir = dotfilesDir
|
||||
scriptCmd.Stdout = inv.Stdout
|
||||
scriptCmd.Stderr = inv.Stderr
|
||||
|
||||
Reference in New Issue
Block a user