From 1d9c0f051872675a6d8a577ee2227aedc79eb8ba Mon Sep 17 00:00:00 2001 From: "Jyotirmoy Bandyopadhyaya [Bravo68]" Date: Wed, 19 Jul 2023 08:23:11 +0000 Subject: [PATCH 01/14] make dotfiles install scripts executable --- cli/dotfiles.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 8d331d988d53b..53ee67923cd17 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -196,6 +196,13 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { // it is safe to use a variable command here because it's from // a filtered list of pre-approved install scripts // nolint:gosec + + // making selected script executable + err = os.Chmod(filepath.Join(dotfilesDir, script), 0o755) + if err != nil { + return xerrors.Errorf("chmod %s: %w", script, err) + } + scriptCmd := exec.CommandContext(inv.Context(), filepath.Join(dotfilesDir, script)) scriptCmd.Dir = dotfilesDir scriptCmd.Stdout = inv.Stdout From 3cb96f924819b3c6058b799fff83f57fa41b7a6d Mon Sep 17 00:00:00 2001 From: "Jyotirmoy Bandyopadhyaya [Bravo68]" Date: Wed, 19 Jul 2023 11:39:40 +0000 Subject: [PATCH 02/14] refactor: added better error handling --- cli/dotfiles.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 53ee67923cd17..8ad314ff5b58c 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -43,8 +43,8 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { installScriptSet = []string{ "install.sh", "install", - "bootstrap.sh", - "bootstrap", + // "bootstrap.sh", + // "bootstrap", "script/bootstrap", "setup.sh", "setup", @@ -193,16 +193,21 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { } _, _ = fmt.Fprintf(inv.Stdout, "Running %s...\n", script) - // it is safe to use a variable command here because it's from - // a filtered list of pre-approved install scripts - // nolint:gosec - // making selected script executable - err = os.Chmod(filepath.Join(dotfilesDir, script), 0o755) + // 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("chmod %s: %w", script, err) + return xerrors.Errorf("stat %s: %w", scriptPath, err) + } + + if fi.Mode()&0o111 == 0 { + return xerrors.Errorf("%s script is not executable.\nTo solve this :-\n - Clone your dotfiles repo.\n - chmod +x %s\n - git add %s and git commit -m \"Make %s executable\"\n - git push\n", script, script, script, 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.Dir = dotfilesDir scriptCmd.Stdout = inv.Stdout From ca53d9879e8db4a77a3a738193202b961abaf1c2 Mon Sep 17 00:00:00 2001 From: "Jyotirmoy Bandyopadhyaya [Bravo68]" Date: Wed, 19 Jul 2023 11:43:04 +0000 Subject: [PATCH 03/14] revert: prev installScriptSet --- cli/dotfiles.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 8ad314ff5b58c..878e3ddb798be 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -43,8 +43,8 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { installScriptSet = []string{ "install.sh", "install", - // "bootstrap.sh", - // "bootstrap", + "bootstrap.sh", + "bootstrap", "script/bootstrap", "setup.sh", "setup", From ea1cb7762779f02318a82326804b75a8cd27b653 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Thu, 20 Jul 2023 20:00:24 +0530 Subject: [PATCH 04/14] Update cli/dotfiles.go Co-authored-by: Mathias Fredriksson --- cli/dotfiles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 878e3ddb798be..497d860d08311 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -202,7 +202,7 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { } if fi.Mode()&0o111 == 0 { - return xerrors.Errorf("%s script is not executable.\nTo solve this :-\n - Clone your dotfiles repo.\n - chmod +x %s\n - git add %s and git commit -m \"Make %s executable\"\n - git push\n", script, script, script, script) + 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 From 245ec38159d1a125a90754a6d76abd6dfcb3746b Mon Sep 17 00:00:00 2001 From: bravo68web Date: Fri, 21 Jul 2023 09:54:02 +0530 Subject: [PATCH 05/14] docs: added docs regarding usage of setup script in dotfiles --- docs/dotfiles.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 15332229d3c07..3df02f6e7d7dd 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -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 these files are present, Coder will run them after cloning the dotfiles repo. If any of these files are found in the specified order, only the first match will be executed, 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 + +chmod +x + +git commit -m "Make executable" + +git push +``` From dfab2240a632d1f91e4755c2ed46bac9c819702c Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 13:27:08 +0530 Subject: [PATCH 06/14] Update docs/dotfiles.md Co-authored-by: Muhammad Atif Ali --- docs/dotfiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 3df02f6e7d7dd..7c0cf986e95dd 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -74,7 +74,7 @@ User can have either of the following setup script files in their dotfiles repo: - setup - script/setup -If any of these files are present, Coder will run them after cloning the dotfiles repo. If any of these files are found in the specified order, only the first match will be executed, and the rest will be skipped. +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: From 32a9218a8d3e064690d41b5b5d763998646c9c35 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 13:43:27 +0530 Subject: [PATCH 07/14] Update cli/dotfiles.go Co-authored-by: Muhammad Atif Ali --- cli/dotfiles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 497d860d08311..6cc0bda7f5b0e 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -202,7 +202,7 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { } 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) + return xerrors.Errorf("%[1]q script is not executable. Please check https://coder.com/docs/v2/latest/dotfiles, script) } // it is safe to use a variable command here because it's from From 5d9741dcf4daf8992031df26dfaa6b16d442f4d0 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 21 Jul 2023 14:59:09 +0300 Subject: [PATCH 08/14] Update cli/dotfiles.go --- cli/dotfiles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/dotfiles.go b/cli/dotfiles.go index 6cc0bda7f5b0e..60be52a0fc629 100644 --- a/cli/dotfiles.go +++ b/cli/dotfiles.go @@ -202,7 +202,7 @@ func (r *RootCmd) dotfiles() *clibase.Cmd { } if fi.Mode()&0o111 == 0 { - return xerrors.Errorf("%[1]q script is not executable. Please check https://coder.com/docs/v2/latest/dotfiles, script) + 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 From 95510a240e03c9424a3c568527566f656befcbb9 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 17:46:40 +0530 Subject: [PATCH 09/14] Update docs/dotfiles.md Co-authored-by: Mathias Fredriksson --- docs/dotfiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 7c0cf986e95dd..c93d26adfaa2f 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -61,7 +61,7 @@ sudo apt update sudo apt install -y neovim fish cargo ``` -## Install or Setup script support +## Setup script support User can have either of the following setup script files in their dotfiles repo: From 4900f449e76b6227935aff9bce0843e018acb4cb Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 17:46:47 +0530 Subject: [PATCH 10/14] Update docs/dotfiles.md Co-authored-by: Mathias Fredriksson --- docs/dotfiles.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index c93d26adfaa2f..1d7a21858d374 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -65,14 +65,14 @@ sudo apt install -y neovim fish cargo 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 +- `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. From b460751519f88c67b619cdd6f66636b044cc0e3d Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 17:46:54 +0530 Subject: [PATCH 11/14] Update docs/dotfiles.md Co-authored-by: Mathias Fredriksson --- docs/dotfiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 1d7a21858d374..7085c5943284d 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -76,7 +76,7 @@ User can have either of the following setup script files in their dotfiles repo: 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: +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: ```bash cd From ab300d534228fddcf550cf9725e56d3c84eba708 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 17:47:02 +0530 Subject: [PATCH 12/14] Update docs/dotfiles.md Co-authored-by: Mathias Fredriksson --- docs/dotfiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 7085c5943284d..6d695c40659ea 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -74,7 +74,7 @@ User can have either of the following setup script files in their dotfiles repo: - `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. +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: From b2bbaa4cc858a101875e3e4071a5d05af8149b7b Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 17:47:11 +0530 Subject: [PATCH 13/14] Update docs/dotfiles.md Co-authored-by: Mathias Fredriksson --- docs/dotfiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index 6d695c40659ea..e8eb90682d532 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -63,7 +63,7 @@ sudo apt install -y neovim fish cargo ## Setup script support -User can have either of the following setup script files in their dotfiles repo: +User can setup their dotfiles by creating one of the following script files in their dotfiles repo: - `install.sh` - `install` From b1a9a24f9369f150a2c0437e61181973b52a2a71 Mon Sep 17 00:00:00 2001 From: Jyotirmoy Bandyopadhyaya Date: Fri, 21 Jul 2023 17:47:22 +0530 Subject: [PATCH 14/14] Update docs/dotfiles.md Co-authored-by: Mathias Fredriksson --- docs/dotfiles.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/dotfiles.md b/docs/dotfiles.md index e8eb90682d532..af87e116bb853 100644 --- a/docs/dotfiles.md +++ b/docs/dotfiles.md @@ -78,12 +78,9 @@ If any of the above files are found (in the specified order), Coder will try to 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: -```bash +```shell cd - chmod +x - git commit -m "Make executable" - git push ```