Skip to content

[feat] Setup end-user environment - #1029

Closed
gwynbleidd2106 wants to merge 1 commit into
mainfrom
setup-env
Closed

[feat] Setup end-user environment#1029
gwynbleidd2106 wants to merge 1 commit into
mainfrom
setup-env

Conversation

@gwynbleidd2106

@gwynbleidd2106 gwynbleidd2106 commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

Add script to automatically install all required packages on end-user system.
Linux distro independent, MacOS ready

Summary by CodeRabbit

  • New Features

    • Introduced an automated script to set up a user environment with Kubernetes-related CLI tools and plugins, including talm, kubectl, krew (and plugins), virtctl, helm (and plugins), and fluxcd.
  • Chores

    • Updated the build process to run the environment setup script as part of dependency installation.

@coderabbitai

coderabbitai Bot commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new Bash script, user_setup_env.sh, was added to automate the installation of several Kubernetes-related CLI tools and plugins. The Makefile's build-deps target was updated to execute this script as part of the dependency setup process, integrating user environment preparation into the build workflow.

Changes

File(s) Change Summary
Makefile Modified build-deps target to run ./hack/user_setup_env.sh after checking GNU utilities.
hack/user_setup_env.sh Added new script to install Kubernetes CLI tools and plugins including kubectl, krew, helm, fluxcd, and others.

Poem

In the warren, tools abound,
With scripts and bins now tightly wound.
Kubectl, helm, and flux appear,
Installed with care—no need to fear!
The Makefile hops, the setup’s done,
A bunny’s work, now smoothly run.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gwynbleidd2106

Copy link
Copy Markdown
Contributor Author

Andrei Kvapil (@kvaps) pls check

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (6)
scripts/user_setup_env.sh (5)

27-29: Quote logged messages for safety.
In log(), consider quoting $1 to safely handle messages with special characters.

-function log() {
-    echo "$(date '+%d-%m-%Y %H:%M:%S') - $1"
-}
+function log() {
+    echo "$(date '+%d-%m-%Y %H:%M:%S') - \"$1\""
+}

49-59: Make krew installation idempotent and clean up temp artifacts.
If /tmp/krew already exists, mkdir will fail, and leftover files may persist across runs. Use mktemp -d or clear the directory, and remove temp folders after installation. Also, instead of sourcing .bashrc directly, instruct the user to restart their shell or append a notice.

-function install_krew() {
-    mkdir /tmp/krew && tar -xzf "/tmp/${KREW}.tar.gz" -C /tmp/krew/
-    "/tmp/krew/${KREW}" install krew
+function install_krew() {
+    local tmpdir
+    tmpdir=$(mktemp -d)
+    tar -xzf "/tmp/${KREW}.tar.gz" -C "$tmpdir"
+    "$tmpdir/${KREW}" install krew
+    rm -rf "$tmpdir"
     printf '# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
-    source ~/.bashrc
+    log "Added krew to PATH; restart your shell to apply."
 }  
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 58-58: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)


88-96: Clean up Helm temp directory and prevent collisions.
/tmp/helm may persist between runs. Use mktemp -d and remove it after moving the binary.

-function install_helm() {
+function install_helm() {
     log "Installing Helm"
-    mkdir /tmp/helm && tar -xzf /tmp/helm.tar.gz -C /tmp/helm/
-    sudo mv "/tmp/helm/${OS}-${ARCH}/helm" /usr/local/bin/helm
+    local tmphelm
+    tmphelm=$(mktemp -d)
+    tar -xzf /tmp/helm.tar.gz -C "$tmphelm"
+    sudo mv "$tmphelm/${OS}-${ARCH}/helm" /usr/local/bin/helm
     sudo chown 0:0 /usr/local/bin/helm
     sudo chmod 0755 /usr/local/bin/helm
+    rm -rf "$tmphelm"
 }  

105-113: Use temporary directory for FluxCD extraction.
Similar to Helm and krew, protect against stale /tmp/flux folders by leveraging mktemp -d and cleanup.

-function install_fluxcd() {
+function install_fluxcd() {
     log "Installing FluxCD"
-    mkdir /tmp/flux && tar -xzf /tmp/flux.tar.gz -C /tmp/flux/
-    sudo mv /tmp/flux/flux /usr/local/bin/flux
+    local tmpflux
+    tmpflux=$(mktemp -d)
+    tar -xzf /tmp/flux.tar.gz -C "$tmpflux"
+    sudo mv "$tmpflux/flux" /usr/local/bin/flux
     sudo chown 0:0 /usr/local/bin/flux
     sudo chmod 0755 /usr/local/bin/flux
+    rm -rf "$tmpflux"
 }  

116-116: Guard script execution when sourced.
Directly calling user_setup_env on load prevents safe sourcing. Wrap in:

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    user_setup_env
fi
packages/apps/vm-instance/templates/vm.yaml (1)

97-118: Suggest DRY’ing repeated cloudinitdisk blocks.
The three conditional branches each declare identical keys (- name: cloudinitdisk, cloudInitNoCloud:). Consider collapsing common YAML structure and vary only secretRef vs. userData.

For example, extract the disk name and volume into a single block and template the inner fields.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 730ea4d and 9d4f94a.

📒 Files selected for processing (5)
  • packages/apps/versions_map (2 hunks)
  • packages/apps/virtual-machine/Chart.yaml (1 hunks)
  • packages/apps/vm-instance/Chart.yaml (1 hunks)
  • packages/apps/vm-instance/templates/vm.yaml (1 hunks)
  • scripts/user_setup_env.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/user_setup_env.sh

[warning] 58-58: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test
🔇 Additional comments (4)
packages/apps/vm-instance/Chart.yaml (1)

20-20: Approve chart version bump to 0.7.2.
This aligns with the updated version in versions_map. No other template changes detected.

packages/apps/virtual-machine/Chart.yaml (1)

20-20: Approve chart version bump to 0.10.2.
Version bump is consistent with the versions_map update and no template changes are required.

packages/apps/versions_map (2)

174-174: Approve mapping update for virtual-machine 0.10.2.
The removed 0.10.1 entry was correctly replaced with 0.10.2 HEAD.


187-187: Approve mapping update for vm-instance 0.7.2.
Entry for 0.7.2 HEAD matches the bumped chart version.

Comment thread scripts/user_setup_env.sh
Comment on lines +43 to +47
curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
sudo mv /tmp/kubectl /usr/local/bin/kubectl
sudo chown 0:0 /usr/local/bin/kubectl
sudo chmod 0755 /usr/local/bin/kubectl
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix conflicting curl flags.
Using both -o and -O is contradictory and may cause unexpected file naming. Remove -O when specifying the output file.

-    curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
+    curl -o /tmp/kubectl -fsL "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
sudo mv /tmp/kubectl /usr/local/bin/kubectl
sudo chown 0:0 /usr/local/bin/kubectl
sudo chmod 0755 /usr/local/bin/kubectl
}
curl -o /tmp/kubectl -fsL "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
sudo mv /tmp/kubectl /usr/local/bin/kubectl
sudo chown 0:0 /usr/local/bin/kubectl
sudo chmod 0755 /usr/local/bin/kubectl
}
🤖 Prompt for AI Agents
In scripts/user_setup_env.sh around lines 43 to 47, the curl command uses both
-o and -O flags, which conflict because -o specifies a filename and -O saves
with the remote name. Remove the -O flag and keep only -o with the desired
output path to ensure the file is saved correctly without naming conflicts.

Comment thread scripts/user_setup_env.sh
Comment thread scripts/user_setup_env.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (4)
scripts/user_setup_env.sh (4)

43-47: Remove conflicting curl flags

Avoid using both -o and -O together. Keep -o for specifying the output path:

-    curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
+    curl -o /tmp/kubectl -fsL "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"

52-54: Fix curl invocation when downloading krew

Similarly, drop -O to ensure the output file is named correctly:

-    curl -o "/tmp/${KREW}.tar.gz" -fsLO "https://github.com/kubernetes-sigs/krew/releases/download/${krew_version}/${KREW}.tar.gz"
+    curl -o "/tmp/${KREW}.tar.gz" -fsL "https://github.com/kubernetes-sigs/krew/releases/download/${krew_version}/${KREW}.tar.gz"

1-2: 🛠️ Refactor suggestion

Add strict mode for robust error handling

Enable fail-fast behavior and protect against unset variables by adding set -euo pipefail and IFS immediately after the shebang.

 #!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'

10-10: ⚠️ Potential issue

Correct architecture normalization to handle all variants

Add mapping for 32-bit x86 (i[3-6]86) and reorder patterns to avoid mis-normalizing aarch64. For example:

-ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')"
+ARCH="$(uname -m | sed \
+  -e 's/x86_64/amd64/' \
+  -e 's/i[3-6]86/386/' \
+  -e 's/aarch64$/arm64/' \
+  -e 's/\(arm\)\(64\)\?.*/\1\2/')"
🧹 Nitpick comments (3)
scripts/user_setup_env.sh (3)

31-38: Use temporary files safely

Avoid static /tmp names to prevent race conditions. Use mktemp for downloads:

 function install_talm() {
     log "Installing talm"
-
-    curl -o /tmp/talm -fsL "https://github.com/cozystack/talm/releases/download/${talm_version}/talm-${OS}-${ARCH}"
-    sudo mv /tmp/talm /usr/local/bin/talm
+    tmp=$(mktemp)
+    curl -fsL "https://github.com/cozystack/talm/releases/download/${talm_version}/talm-${OS}-${ARCH}" -o "$tmp"
+    sudo mv "$tmp" /usr/local/bin/talm
     sudo chown 0:0 /usr/local/bin/talm
     sudo chmod 0755 /usr/local/bin/talm
 }

57-59: Prevent duplicate PATH entries and guide shell reload

Guard against multiple .bashrc appends and inform the user to reload:

-    printf '# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
-    source ~/.bashrc
+    grep -qxF 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' ~/.bashrc || \
+      printf '# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
+    echo "Run 'source ~/.bashrc' or reopen your shell to activate krew."
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 58-58: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)


27-29: Enhance log function to support multiple arguments

Switch from $1 to $* so all passed parameters are logged:

 function log() {
-    echo "$(date '+%d-%m-%Y %H:%M:%S') - $1"
+    echo "$(date '+%d-%m-%Y %H:%M:%S') - $*"
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d4f94a and bb963f2.

📒 Files selected for processing (1)
  • scripts/user_setup_env.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/user_setup_env.sh

[warning] 58-58: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build

Comment thread scripts/user_setup_env.sh
Comment on lines +64 to +67
if [[ ! $(kubectl krew version) ]]; then
log "krew is not installed, install it first!"
return 1
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct plugin installation check

The current if [[ ! $(kubectl krew version) ]] test is unreliable. Instead, test the command’s exit status:

-    if [[ ! $(kubectl krew version) ]]; then
+    if ! kubectl krew version >/dev/null 2>&1; then
         log "krew is not installed, install it first!"
         return 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ ! $(kubectl krew version) ]]; then
log "krew is not installed, install it first!"
return 1
fi
if ! kubectl krew version >/dev/null 2>&1; then
log "krew is not installed, install it first!"
return 1
fi
🤖 Prompt for AI Agents
In scripts/user_setup_env.sh around lines 64 to 67, the check for whether krew
is installed uses command substitution which is unreliable. Replace the
condition to test the exit status of `kubectl krew version` directly by running
the command and checking if it fails, for example using `if ! kubectl krew
version > /dev/null 2>&1; then`. This ensures a reliable check based on the
command's success or failure.

@gwynbleidd2106

Copy link
Copy Markdown
Contributor Author

Andrei Kvapil (@kvaps)
made some changes as we discussed before. review when it's most convenient for ya

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (6)
hack/user_setup_env.sh (6)

3-12: Standardize version variables
You're mixing v-prefixed (e.g. talm_version="v0.13.0") and bare versions (fluxcd_version="2.6.1"). This inconsistency can lead to invalid URLs or redundant v characters. Either include the v prefix in all version vars or strip it when constructing URLs.


14-25: Halt on installer failure
All installers are chained without handling individual failures. With set -euo pipefail (per above), the script will exit on a failed install, but it's worth documenting this or wrapping calls to provide clearer context on which step failed.


27-29: Fix typo in log message
log "Start setuping user environment" → typo “setuping”. Consider:

-log "Start setuping user environment"
+log "Starting setup of user environment"

31-38: DRY up repetitive install functions
Each install_* repeats download → mv → chown → chmod. Extract a helper:

install_binary() {
  local name=$1 url=$2
  curl -fsSL "$url" -o "/tmp/$name"
  sudo mv "/tmp/$name" "/usr/local/bin/$name"
  sudo chown 0:0 "/usr/local/bin/$name"
  sudo chmod 0755 "/usr/local/bin/$name"
}

Then call:

install_binary talm "https://.../${talm_version}/talm-${OS}-${ARCH}"

This reduces duplication and eases future maintenance.

Also applies to: 40-47, 79-86, 88-96, 105-113


98-103: Idempotent Helm plugin installation
Re-running will fail if diff is already installed. Wrap with:

helm plugin list | grep -q '^diff ' || \
  helm plugin install https://github.com/databus23/helm-diff

116-116: Prevent unintended execution on sourcing
If someone sources this script, it will auto-run. Wrap the invocation:

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
  user_setup_env
fi

This clarifies entrypoint behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb963f2 and 57bdd6e.

📒 Files selected for processing (2)
  • Makefile (1 hunks)
  • hack/user_setup_env.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Makefile
🧰 Additional context used
🪛 Shellcheck (0.10.0)
hack/user_setup_env.sh

[warning] 58-58: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

Comment thread hack/user_setup_env.sh
Comment on lines +52 to +59
KREW="krew-${OS}_${ARCH}"
curl -o "/tmp/${KREW}.tar.gz" -fsLO "https://github.com/kubernetes-sigs/krew/releases/download/${krew_version}/${KREW}.tar.gz"
mkdir /tmp/krew && tar -xzf "/tmp/${KREW}.tar.gz" -C /tmp/krew/
"/tmp/krew/${KREW}" install krew
log "configure .bashrc for krew"
printf '# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
source ~/.bashrc
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make krew setup idempotent & satisfy SC1090

  • Use mkdir -p /tmp/krew and clean any stale data.
  • Guard appending to ~/.bashrc to avoid duplicates:
    grep -qxF 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' ~/.bashrc || \
      printf '\n# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
  • To appease ShellCheck SC1090:
    # shellcheck source=/dev/null
    source ~/.bashrc
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 58-58: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

🤖 Prompt for AI Agents
In hack/user_setup_env.sh around lines 52 to 59, make the krew setup idempotent
by using mkdir -p /tmp/krew and removing any existing contents in /tmp/krew
before extracting. Prevent duplicate PATH entries in ~/.bashrc by checking if
the export line already exists using grep before appending it. Add a shellcheck
directive comment before sourcing ~/.bashrc to satisfy SC1090 by including "#
shellcheck source=/dev/null" above the source command.

Comment thread hack/user_setup_env.sh
Comment on lines +1 to +3
#!/bin/bash

#### variables list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enforce strict error handling
The script currently risks silent failures and uninitialized variables. Add at the top:

+ set -euo pipefail
+ if [[ $EUID -ne 0 ]]; then
+   echo "Please run as root or with sudo"
+   exit 1
+ fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/bash
#### variables list
#!/bin/bash
+ set -euo pipefail
+ if [[ $EUID -ne 0 ]]; then
+ echo "Please run as root or with sudo"
+ exit 1
+ fi
#### variables list
🤖 Prompt for AI Agents
In hack/user_setup_env.sh at the beginning of the file (lines 1 to 3), add
strict error handling by including 'set -euo pipefail' right after the shebang
line. This will ensure the script exits on errors, treats unset variables as
errors, and fails on pipeline errors, preventing silent failures and
uninitialized variables.

Comment thread hack/user_setup_env.sh
Comment on lines +61 to +77
function install_krew_plugins() {
log "Installing krew plugins..."

if [[ ! $(kubectl krew version) ]]; then
log "krew is not installed, install it first!"
return 1
fi

log "Installing krew plugin: node-shell"
kubectl krew install node-shell

log "Installing krew plugin: virt"
kubectl krew install virt

log "Installing krew plugin: oidc-login"
kubectl krew install oidc-login
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve krew plugin install check
Testing with [[ ! $(kubectl krew version) ]] can misinterpret output. Prefer checking exit code:

- if [[ ! $(kubectl krew version) ]]; then
+ if ! kubectl krew version >/dev/null 2>&1; then
     log "krew is not installed, install it first!"
     return 1

Also guard against re-installing plugins already present.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function install_krew_plugins() {
log "Installing krew plugins..."
if [[ ! $(kubectl krew version) ]]; then
log "krew is not installed, install it first!"
return 1
fi
log "Installing krew plugin: node-shell"
kubectl krew install node-shell
log "Installing krew plugin: virt"
kubectl krew install virt
log "Installing krew plugin: oidc-login"
kubectl krew install oidc-login
}
function install_krew_plugins() {
log "Installing krew plugins..."
if ! kubectl krew version >/dev/null 2>&1; then
log "krew is not installed, install it first!"
return 1
fi
log "Installing krew plugin: node-shell"
kubectl krew install node-shell
log "Installing krew plugin: virt"
kubectl krew install virt
log "Installing krew plugin: oidc-login"
kubectl krew install oidc-login
}
🤖 Prompt for AI Agents
In hack/user_setup_env.sh around lines 61 to 77, the check for krew installation
uses output testing which can be unreliable. Change this to check the exit code
of `kubectl krew version` instead. Additionally, before installing each krew
plugin, verify if the plugin is already installed to avoid redundant
installations.

Comment thread hack/user_setup_env.sh
Comment on lines +43 to +44
curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
sudo mv /tmp/kubectl /usr/local/bin/kubectl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove conflicting curl flags
Using both -o /tmp/kubectl and -O is ambiguous—-O overrides -o. Drop -O so the download lands in /tmp/kubectl as intended:

-curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
+curl -fsSL -o /tmp/kubectl "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
sudo mv /tmp/kubectl /usr/local/bin/kubectl
curl -fsSL -o /tmp/kubectl "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
sudo mv /tmp/kubectl /usr/local/bin/kubectl
🤖 Prompt for AI Agents
In hack/user_setup_env.sh at lines 43-44, the curl command uses both -o and -O
flags, which conflict because -O overrides -o. Remove the -O flag so the file
downloads correctly to /tmp/kubectl as intended.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (4)
hack/user_setup_env.sh (4)

74-89: Robust check & idempotent plugin installation

[[ ! $(kubectl krew version) ]] mis-interprets output; rely on exit status.
Also skip plugins already present to avoid error spam.

-if [[ ! $(kubectl krew version) ]]; then
+if ! kubectl krew version >/dev/null 2>&1; then
     …
 fi
 …
-kubectl krew install node-shell
+kubectl krew list | grep -q '^node-shell$' || kubectl krew install node-shell

(repeat for other plugins)


1-3: Add strict error-handling & root guard at script entry
The script still risks silent failures and uninitialised variables, and CI shows “permission denied”. Add set -euo pipefail and a root / sudo guard right after the she-bang.

 #!/bin/bash
+set -euo pipefail
+
+if [[ $EUID -ne 0 ]]; then
+  echo "Please run as root or with sudo"
+  exit 1
+fi

56-57: Conflicting curl flags (-o + -O)
-O overrides -o ⇒ the file lands in the current dir, not /tmp. Drop -O.

-curl -o /tmp/kubectl -fsLO …
+curl -fsSL -o /tmp/kubectl …

62-72: Make krew install idempotent, fix curl flags & satisfy SC1090

  1. mkdir fails second run; use mkdir -p and wipe stale files.
  2. Same -o/-O flag issue.
  3. Appending to ~/.bashrc on every run duplicates PATH.
  4. Add ShellCheck directive before source.
 KREW="krew-${OS}_${ARCH}"
-curl -o "/tmp/${KREW}.tar.gz" -fsLO "https://github.com/kubernetes-sigs/krew/releases/download/${krew_version}/${KREW}.tar.gz"
-mkdir /tmp/krew && tar -xzf "/tmp/${KREW}.tar.gz" -C /tmp/krew/
+curl -fsSL -o "/tmp/${KREW}.tar.gz" "https://github.com/kubernetes-sigs/krew/releases/download/${krew_version}/${KREW}.tar.gz"
+mkdir -p /tmp/krew && rm -rf /tmp/krew/*
+tar -xzf "/tmp/${KREW}.tar.gz" -C /tmp/krew/-printf '# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
- source ~/.bashrc
+# Guard duplicate PATH entry
+grep -qxF 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' ~/.bashrc || \
+  printf '\n# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
+# shellcheck source=/dev/null
+source ~/.bashrc
🧹 Nitpick comments (3)
hack/user_setup_env.sh (3)

11-14: Remove noisy unconditional echo
echo $ARCH spams every invocation (including CI logs) and provides no functional value.

-echo $ARCH

30-32: Quote log payload to preserve whitespace
Protect against word-splitting in the log helper.

-echo "$(date '+%d-%m-%Y %H:%M:%S') - $1"
+echo "$(date '+%d-%m-%Y %H:%M:%S') - $*"

62-62: Inconsistent function definition style
Every other function uses function name(), but install_krew() omits the function keyword. Stick to one style.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57bdd6e and e7998ca.

📒 Files selected for processing (2)
  • Makefile (1 hunks)
  • hack/user_setup_env.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Makefile
🧰 Additional context used
🪛 Shellcheck (0.10.0)
hack/user_setup_env.sh

[warning] 71-71: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

🪛 GitHub Actions: Pull Request
hack/user_setup_env.sh

[error] 1-1: Permission denied when trying to execute the script. This caused 'make build' to fail with error code 127.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pre-commit
🔇 Additional comments (2)
hack/user_setup_env.sh (2)

47-51: Ensure downloaded binary is executable before move
curl … > /tmp/talm leaves the file without +x; rely on chmod after the move, not before—OK.
(No action required.)


129-129: Mark script executable in repo or call via bash
CI failure “permission denied” suggests the file lacks the executable bit. Either:

chmod +x hack/user_setup_env.sh

or invoke it with an explicit interpreter (bash hack/user_setup_env.sh) in the Makefile.

Comment thread hack/user_setup_env.sh
Comment on lines +37 to +41
curl -sSL https://github.com/cozystack/cozypkg/releases/download/${cozypkg_version}/cozypkg-${OS}-${ARCH}.tar.gz | \
tar xzvf - cozypkg
sudo mv /tmp/cozypkg /usr/local/bin/cozypkg
sudo chown 0:0 /usr/local/bin/cozypkg
sudo chmod 0755 /usr/local/bin/cozypkg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Broken extraction path for cozypkg
The archive is unpacked into the CWD, yet we later mv /tmp/cozypkg …, producing “No such file” on fresh machines.

-curl -sSL … | tar xzvf - cozypkg
-sudo mv /tmp/cozypkg /usr/local/bin/cozypkg
+curl -sSL … | tar -xzvf - -C /tmp
+sudo mv /tmp/cozypkg /usr/local/bin/cozypkg
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
curl -sSL https://github.com/cozystack/cozypkg/releases/download/${cozypkg_version}/cozypkg-${OS}-${ARCH}.tar.gz | \
tar xzvf - cozypkg
sudo mv /tmp/cozypkg /usr/local/bin/cozypkg
sudo chown 0:0 /usr/local/bin/cozypkg
sudo chmod 0755 /usr/local/bin/cozypkg
curl -sSL https://github.com/cozystack/cozypkg/releases/download/${cozypkg_version}/cozypkg-${OS}-${ARCH}.tar.gz | \
tar -xzvf - -C /tmp
sudo mv /tmp/cozypkg /usr/local/bin/cozypkg
sudo chown 0:0 /usr/local/bin/cozypkg
sudo chmod 0755 /usr/local/bin/cozypkg
🤖 Prompt for AI Agents
In hack/user_setup_env.sh around lines 37 to 41, the script extracts the cozypkg
archive into the current directory but then tries to move /tmp/cozypkg, which
does not exist, causing an error. Fix this by extracting the archive directly
into /tmp or adjusting the mv command to move cozypkg from the actual extraction
location to /usr/local/bin/cozypkg.

Add script to automatically install all required
packages on end-user system
Linux distro independent, MacOS ready

Signed-off-by: Ahmad Murzahmatov <gwynbleidd2106@yandex.com>
@gwynbleidd2106 gwynbleidd2106 changed the title Feature Setup end-user environment [feat] Setup end-user environment Jul 9, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (5)
hack/user_setup_env.sh (5)

1-3: Add strict mode & privilege guard at script start
Without set -euo pipefail, failures go unnoticed; uninitialised vars or broken pipes will silently continue. Also, many installs require root – abort early when the user is non-root instead of letting sudo prompts break CI.

 #!/bin/bash
+set -euo pipefail
+if [[ $EUID -ne 0 ]]; then
+  echo "Please run with sudo or as root"
+  exit 1
+fi

37-41: Broken extraction path: cozypkg never ends up in /tmp
tar xzvf - cozypkg extracts into CWD yet you later mv /tmp/cozypkg …, which fails on fresh machines.

-curl -sSL … | tar xzvf - cozypkg
-sudo mv /tmp/cozypkg /usr/local/bin/cozypkg
+curl -sSL … | tar -xzvf - -C /tmp
+sudo mv /tmp/cozypkg /usr/local/bin/cozypkg

56-56: Conflicting curl flags overwrite target file
-o /tmp/kubectl and -O together cause -O to win, the binary lands in $PWD. Use one flag:

-curl -o /tmp/kubectl -fsLO "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"
+curl -fsSL -o /tmp/kubectl "https://dl.k8s.io/release/${kubectl_version}/bin/${OS}/${ARCH}/kubectl"

65-72: Make krew setup idempotent & silence ShellCheck SC1090
Repeated runs keep appending PATH lines and sourcing non-constant paths trips SC1090.

-mkdir /tmp/krew && tar -xzf "/tmp/${KREW}.tar.gz" -C /tmp/krew/
+mkdir -p /tmp/krew && rm -rf /tmp/krew/*
+tar -xzf "/tmp/${KREW}.tar.gz" -C /tmp/krew/

-printf '# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
+# Guard against duplicates
+grep -qxF 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' ~/.bashrc || \
+  printf '\n# krew\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"\n' >> ~/.bashrc
+# shellcheck source=/dev/null

77-80: Use exit code to detect krew instead of output test
[[ ! $(kubectl krew version) ]] mis-fires when command prints to stderr. Prefer exit status:

-if [[ ! $(kubectl krew version) ]]; then
+if ! kubectl krew version >/dev/null 2>&1; then
🧹 Nitpick comments (1)
hack/user_setup_env.sh (1)

12-12: Remove stray debug echo
echo $ARCH pollutes stdout and interferes with callers piping the output.

-echo $ARCH
+# echo "$ARCH"   # Uncomment for debugging if needed
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7998ca and c5ead0c.

📒 Files selected for processing (2)
  • Makefile (1 hunks)
  • hack/user_setup_env.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Makefile
🧰 Additional context used
🧠 Learnings (1)
hack/user_setup_env.sh (1)
Learnt from: lllamnyp
PR: cozystack/cozystack#1025
File: packages/apps/kafka/charts/cozy-lib:1-1
Timestamp: 2025-06-04T06:22:17.306Z
Learning: Files in packages/apps/*/charts/cozy-lib that contain the path "../../../library/cozy-lib" are symbolic links, not regular files. Git diffs may display symlinks as regular files with their target path as content, which can be misleading in code review.
🪛 Shellcheck (0.10.0)
hack/user_setup_env.sh

[warning] 71-71: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

🪛 GitHub Actions: Pull Request
hack/user_setup_env.sh

[error] 1-1: Permission denied when trying to execute the script. This caused 'make build' to fail with error code 127.

Comment thread hack/user_setup_env.sh
}


user_setup_env No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

CI failure: script lacks execute bit – call via bash or chmod +x
GitHub Actions shows “Permission denied”. Either commit the file with chmod +x or invoke it explicitly:

-build-deps:
-	./hack/user_setup_env.sh
+build-deps:
+	bash hack/user_setup_env.sh

Failing to fix this blocks the whole pipeline.

🤖 Prompt for AI Agents
In hack/user_setup_env.sh at line 129, the script is being called without
execute permissions, causing a "Permission denied" error in CI. Fix this by
either adding execute permissions to the script file with chmod +x before
committing or by changing the invocation in the Makefile or CI config to
explicitly call it with bash, for example, replacing ./hack/user_setup_env.sh
with bash hack/user_setup_env.sh.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

This PR has had no activity for 60 days and was marked lifecycle/stale.
It will be closed in 14 days unless commented or labelled lifecycle/frozen.

@github-actions github-actions Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale label May 2, 2026
@lexfrei

Copy link
Copy Markdown
Contributor

This has been open for well over a year and the pins have aged out. The script installs kubectl v1.33.1, helm v3.18.2 and talm v0.13.0 against a tree that now defaults tenant clusters to v1.35, so merging it as-is would set up a stale toolchain for anyone who runs it.

Two things worth deciding before it moves. Are you still interested in refreshing it? And should this be a Makefile target that downloads binaries at all: main has since gained hack/check-host-runtime.sh behind make preflight, which diagnoses the host rather than installing into it, and a check-and-report shape may fit the client tools better than an installer that races the user's own package manager.

If you have moved on, say so and I will close it.

@lexfrei

Copy link
Copy Markdown
Contributor

Closing this, and I want to be clear that it is not a rejection of the idea.

The gap you spotted is real: nothing in this repository tells a newcomer how to get talm, cozypkg, virtctl and the rest onto their machine. But this repository is not where that answer belongs. Developer tooling is documented on the website, per docs/agents/contributing.md, which points at content/en/docs/next/development.md, and the install section there already covers the surrounding steps.

The form is the other half of it. A Makefile target that downloads binaries into a user's system competes with whatever package manager they already use, and it commits us to chasing versions forever. This PR shows how that ends: it pins kubectl v1.33.1 while the tree now defaults tenant clusters to v1.35, so merging it today would hand people a stale toolchain. The repo's own answer to the same need is make preflight, which diagnoses the host rather than installing into it.

If you are up for turning this into a page on the website instead, that would be genuinely useful and I would review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants