Skip to content

Create curl | bash Installation Script for Bash-Modules via SHAR #24

@vlisivka

Description

@vlisivka

The current installation process for bash-modules is cumbersome. To streamline and standardize it, we propose using self-extracting SHAR (Shell Archive) files for distribution. This will significantly simplify the installation script, as all unpacking and file placement logic will be encapsulated within the SHAR itself. Additionally, we need to implement "live" installation capabilities directly from other Bash scripts, along with robust update and uninstallation procedures.

Goal

To create a flexible and reliable installation system for bash-modules via curl | bash, leveraging SHAR archives for release packaging.

Tasks

  1. SHAR Archive Creation for bash-modules Releases

    • Each bash-modules release on GitHub must include a bash-modules-.shar file.
    • This SHAR archive should contain the complete file structure of bash-modules (scripts, modules, test cases, documentation, etc.).
    • SHAR Internal Logic: Upon execution, the SHAR archive must:
      • Unpack import.sh into $HOME/bin/ (creating the directory if it doesn't exist).
      • Unpack the main module files into $HOME/.local/bash-modules/ (creating the directory if it doesn't exist).
      • Conditional PATH Modification (in .bashrc/.zshrc):
        • Check if $HOME/bin is missing from the $PATH environment variable.
        • Only if $HOME/bin is not in $PATH, the SHAR must offer the user to add export PATH="$HOME/bin:$PATH" to their .bashrc (or .zshrc if Zsh is the default shell).
        • The SHAR must explicitly ask the user for permission to modify their shell configuration files.
      • Progress Display: Output informative messages about each step the SHAR archive performs (unpacking, copying, PATH configuration, testing).
      • Post-Installation Testing: After successful installation, the SHAR must run a basic set of tests to ensure bash-modules functions correctly. This might include running a simple module or verifying the presence of core functions. The test results (success/failure) should be displayed.
      • Idempotency: The SHAR must be idempotent. Repeated execution should not cause errors, duplicate entries in configuration files, or overwrite files unless they have changed.
  2. Direct SHAR download

    For installing a specific version: curl -sSL https://github.com/bash-modules/bash-modules/releases/download/<version_tag>/bash-modules.shar | bash -s

  3. Support for "Live" Installation within Other Bash Scripts

    Something like that:

    command -pv import.sh >/dev/null || { echo "ERROR: import.sh from bash-modules is not found in $PATH. Insall bash-modules using command: curl -sSL https://github.com/vlisivka/bash-modules/releases/download/4.0.2/bash-modules.shar | bash -s"; exit 1 }
    
    . import.sh log arguments
    
    
  4. Update Functionality

  • The import.sh script (or a dedicated bash-modules utility) should provide an update mechanism.
  • This mechanism should check for a newer version of bash-modules on GitHub Releases.
  • If a newer version is found, it should prompt the user to download and execute the corresponding SHAR file, effectively performing an upgrade.
  • Consider a command like bash-modules --update or similar.
  1. Uninstallation Functionality
  • Provide a clear way to uninstall bash-modules.
  • Consider a command like bash-modules --uninstall or similar.
  • The uninstallation process should:
    • Remove $HOME/bin/import.sh.
    • Remove $HOME/.local/bash-modules/ directory.
    • Remove any modifications made to .bashrc or .zshrc related to bash-modules (e.g., the PATH modification, if it was added).
    • Prompt the user for confirmation before removing files.

Security Considerations

  • curl | bash Warning: Clearly warn users about the risks of executing arbitrary code from the internet. Recommend always reviewing the contents of the SHAR archive before execution (e.g., curl .../bash-modules.shar | less).
  • Integrity Check: If GitHub provides checksums for releases, integrate their verification into the SHAR archive. Otherwise, rely on HTTPS for integrity during download.
  • Permissions: The SHAR archive and installation logic must operate under the user's permissions, avoiding sudo and root privileges unless absolutely necessary (e.g., for system-wide changes that require explicit consent).

Expected Outcome

  • A straightforward and unified bash-modules installation procedure using curl | bash and SHAR archives.
  • The ability to easily install both the latest and specific versions.
  • Automatic PATH configuration with user confirmation, and no unconditional source line.
  • Execution of basic post-installation tests.
  • Standardized, "live" installation block for other scripts to automatically resolve bash-modules dependencies.
  • Robust update and uninstallation mechanisms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions