From 65583eca47f6d9d194ed8b038c3c010a4cd331c4 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Sat, 22 Jul 2023 00:09:50 +0530 Subject: [PATCH] feat(cli): check if dotfiles install script is executable (#8588) * feat(cli): check if dotfiles install script is executable * feat(docs): add section for dotfiles setup and document executable fix --------- Co-authored-by: Mathias Fredriksson Co-authored-by: Muhammad Atif Ali --- cli/dotfiles.go | 12 ++++++++++++ docs/dotfiles.md | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 8d331d988d..60be52a0fc 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -193,6 +193,18 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { } _, _ = 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 is not executable. See https://coder.com/docs/v2/latest/dotfiles for information on how to resolve the issue.", script) + } + // it is safe to use a variable command here because it's from // a filtered list of pre-approved install scripts // nolint:gosec diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 15332229d3..af87e116bb 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -60,3 +60,27 @@ sudo apt update # Install some of my favorite tools every time my workspace boots sudo apt install -y neovim fish cargo ``` + +## Setup script support + +User can setup their dotfiles by creating one of the following script files in their dotfiles repo: + +- `install.sh` +- `install` +- `bootstrap.sh` +- `bootstrap` +- `script/bootstrap` +- `setup.sh` +- `setup` +- `script/setup` + +If any of the above files are found (in the specified order), Coder will try to execute the first match. After the first match is found, other files will be ignored. + +The setup script must be executable, otherwise the dotfiles setup will fail. If you encounter this issue, you can fix it by making the script executable using the following commands: + +```shell +cd +chmod +x +git commit -m "Make executable" +git push +```