Skip to content

feat(cli): check if dotfiles install script is executable #8588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 21, 2023
Merged
12 changes: 12 additions & 0 deletions cli/dotfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("%[1]q script is not executable. You can solve this by making it executable in your dotfiles repo:\n chmod +x %[1]q && git add %[1]q && git commit -m \"Make %[1]s executable\" && git push", script)
}

// it is safe to use a variable command here because it's from
// a filtered list of pre-approved install scripts
// nolint:gosec
Expand Down
27 changes: 27 additions & 0 deletions docs/dotfiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,30 @@ sudo apt update
# Install some of my favorite tools every time my workspace boots
sudo apt install -y neovim fish cargo
```

## Install or Setup script support

User can have either of the following setup 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 execute the first match, and the rest will be skipped.

The Setup scripts must be executable. If they are not, Coder will not execute them. If the script is not executable, you can make it executable by running:

```bash
cd <path_to_dotfiles_repo>

chmod +x <script_name>

git commit -m "Make <script_name> executable" <script_name>

git push
```