Skip to content
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

Improve Installation Script Robustness and Compliance #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matbrgz
Copy link

@matbrgz matbrgz commented Mar 4, 2025

Overview

This pull request introduces significant improvements to the installation script for bum. The modifications focus on increasing robustness, security, and maintainability while ensuring the script adheres to ShellCheck recommendations and providing a more user-friendly experience.

Key Changes

  • Helper Functions:

    • Added error(), info(), and info_bold() functions to standardize error handling and logging.
  • Dependency Checks:

    • Incorporated checks for essential commands (bun, curl, tar, uname, mkdir, mv, rm) to ensure all dependencies are met before execution.
  • Bun Installation:

    • Added logic to automatically install Bun if it's not already available on the system.
  • Architecture Detection:

    • Improved system architecture detection using uname -ms with a robust case statement to correctly set the target platform.
  • Download and Extraction Enhancements:

    • Downloads the compressed executable using curl with progress feedback.
    • Extracts the tarball into a temporary directory using mktemp and sets a trap to guarantee cleanup in case of errors.
    • Moves the executable into the designated installation directory and ensures proper cleanup of temporary files.
  • ShellCheck Compliance:

    • Applied ShellCheck recommendations by guarding variables in the rm -rf command using ${var:?} to prevent dangerous expansions.
    • Modified the tildify function to correctly handle tilde expansion by quoting variable expansions appropriately.
  • Environment Configuration:

    • Added a modular function add_commands_to_file to append environment variable configuration to the user's shell configuration file (supports Fish, Zsh, and Bash).
    • Provides clear instructions for manual configuration if automatic file modification is not possible.
    • Displays a refresh command to help users update their shell environment immediately.

Impact

These changes make the installation script:

  • More Robust: Handles errors gracefully and prevents accidental removal of system directories.
  • More Secure: Verifies dependencies and uses temporary directories to minimize risks.
  • More User-Friendly: Provides clear feedback and instructions, improving the overall installation experience.
  • Maintainable: Modular code structure and standardized logging simplify future updates and troubleshooting.

Feel free to review the changes and provide feedback.

@owenizedd
Copy link
Owner

Did you test this change?
And can you tell me which change fix the bugs?

info_bold() { echo -e "\e[1m$*\e[0m"; }

# --- Dependency Check ---
for cmd in bun curl tar uname mkdir mv rm; do
Copy link
Owner

Choose a reason for hiding this comment

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

this is contradictory with line 18 no? you check bun here but will never reach line 18 (installing bun)

Copy link
Author

Choose a reason for hiding this comment

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

My fault. Fixing it.

@owenizedd
Copy link
Owner

I see that you added the info, I took this as reference from bun repo and I already push it to main for that particular code, however other improvements looks good if you updated it and tested to be working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants