Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65583ec

Browse files
BRAVO68WEBmafredrimatifali
authored
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 <[email protected]> Co-authored-by: Muhammad Atif Ali <[email protected]>
1 parent 7f67000 commit 65583ec

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cli/dotfiles.go

+12
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ func (r *RootCmd) dotfiles() *clibase.Cmd {
193193
}
194194

195195
_, _ = fmt.Fprintf(inv.Stdout, "Running %s...\n", script)
196+
197+
// Check if the script is executable and notify on error
198+
scriptPath := filepath.Join(dotfilesDir, script)
199+
fi, err := os.Stat(scriptPath)
200+
if err != nil {
201+
return xerrors.Errorf("stat %s: %w", scriptPath, err)
202+
}
203+
204+
if fi.Mode()&0o111 == 0 {
205+
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)
206+
}
207+
196208
// it is safe to use a variable command here because it's from
197209
// a filtered list of pre-approved install scripts
198210
// nolint:gosec

docs/dotfiles.md

+24
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,27 @@ sudo apt update
6060
# Install some of my favorite tools every time my workspace boots
6161
sudo apt install -y neovim fish cargo
6262
```
63+
64+
## Setup script support
65+
66+
User can setup their dotfiles by creating one of the following script files in their dotfiles repo:
67+
68+
- `install.sh`
69+
- `install`
70+
- `bootstrap.sh`
71+
- `bootstrap`
72+
- `script/bootstrap`
73+
- `setup.sh`
74+
- `setup`
75+
- `script/setup`
76+
77+
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.
78+
79+
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:
80+
81+
```shell
82+
cd <path_to_dotfiles_repo>
83+
chmod +x <script_name>
84+
git commit -m "Make <script_name> executable" <script_name>
85+
git push
86+
```

0 commit comments

Comments
 (0)