Skip to content

hperezrodal/bash-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BASH-LIBRARY

A comprehensive collection of reusable bash functions and scripts for common DevOps and system administration tasks, designed to make shell scripting more efficient and maintainable.

GitHub Release GitHub Issues GitHub Stars Code Style: ShellCheck Platform License

πŸš€ Features

  • Modular design for easy integration
  • Reusable functions for common operations
  • Well-documented code with examples
  • Cross-platform compatibility
  • Easy installation and setup
  • Docker-based development environment
  • Comprehensive DevOps tool integration

πŸ“‹ Prerequisites

Required Tools

  • Docker (20.10.0 or higher)
  • Git
  • Basic Shell Scripting knowledge
  • Development Environment (VS Code, Vim, etc.)

System Requirements

  • OS: Linux, macOS, or Windows with WSL2
  • CPU: 2+ cores recommended
  • RAM: 4GB minimum, 8GB recommended
  • Storage: 10GB free space minimum
  • Network: Stable internet connection

πŸ“¦ Installation

Quick Install

curl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/install-remote.sh | bash

Zsh Installation

If you're using zsh on macOS, you'll need to add the following to your ~/.zshrc file:

# Add bash-library to your PATH
export PATH="$PATH:/path/to/bash-library"

# Source the library
source /path/to/bash-library/lib-loader.sh

After adding these lines, reload your zsh configuration:

source ~/.zshrc

Manual Installation

  1. Clone the repository:
git clone https://github.com/hperezrodal/bash-library.git
cd bash-library
  1. Run the installation script:
./install.sh

Update

Remote Update

curl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/update-remote.sh | bash

For system-wide installations:

curl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/update-remote.sh | SYSTEM_INSTALL=true sudo -E bash

Uninstallation

System-wide Uninstallation (requires root)

sudo ./uninstall.sh

Remote Uninstallation

curl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/uninstall-remote.sh | bash

Zsh Uninstallation

For zsh users, remove the bash-library related lines from your ~/.zshrc file and run:

source ~/.zshrc

After uninstallation, you may need to restart your shell or run source ~/.zshrc for changes to take effect.

πŸ”§ Git Hooks Setup

Pre-commit Hook Setup

The repository includes a pre-commit hook that runs shfmt and shellcheck on all shell scripts. To set it up:

  1. Install Required Tools:

    For Linux (Debian/Ubuntu):

    sudo apt-get update
    sudo apt-get install shellcheck
    sudo snap install shfmt

    For macOS (using Homebrew):

    brew install shellcheck
    brew install shfmt
  2. Make the Hook Executable:

    chmod +x .git/hooks/pre-commit

The pre-commit hook will automatically:

  • Format all shell scripts using shfmt
  • Check for potential issues using shellcheck
  • Prevent commits if any issues are found

πŸ› οΈ Project Structure

bash-library/
β”œβ”€β”€ modules/               # Core function modules
β”œβ”€β”€ scripts/               # Utility scripts
β”œβ”€β”€ examples/              # Usage examples
β”œβ”€β”€ lib-loader.sh          # Library entry point and module loader
β”œβ”€β”€ version                # Current version
β”œβ”€β”€ install.sh             # Local installation script (requires root)
β”œβ”€β”€ install-remote.sh      # Remote installation script
β”œβ”€β”€ update-remote.sh       # Remote update script
β”œβ”€β”€ uninstall.sh           # Local uninstallation script (requires root)
β”œβ”€β”€ uninstall-remote.sh    # Remote uninstallation script
└── CONTRIBUTING.md        # Contribution guidelines

πŸ“š Available Modules

Core Utilities

Module Description
logging.sh Logging functions for bash scripts
datetime.sh Timestamp utilities
validate_params.sh Parameter validation for bash functions
files.sh File and directory copy operations
git.sh Git repository operations
docker.sh Docker image build and push operations

Infrastructure

Module Description
ssh.sh SSH tunnel management
psql.sh PostgreSQL client operations via Docker
mongosh.sh MongoDB shell client via Docker
redis_cli.sh Redis CLI client via Docker
ansible.sh Ansible automation and configuration management

Deployment & Operations

Module Description
bluegreen.sh Blue-green deployment for Docker + Traefik environments
smoke.sh HTTP health checks with retry logic
state.sh Deployment history recording and querying
pipeline.sh CI/CD pipeline orchestration for build, setup, and deployment

Cloud & Blockchain

Module Description
aws.sh AWS-related functions
kubernetes.sh Kubernetes cluster management and operations
eth_rpc.sh Ethereum RPC interaction

Each module is designed to be self-contained and can be used independently.

πŸ› οΈ Usage

Basic Usage

To use the library in your scripts, source the main functions file:

source /path/to/bash-library/lib-loader.sh

Available Modules

See the Available Modules section for the full list.

Available Scripts

After installation, scripts are automatically available in your PATH:

Script Description
aws-secrets AWS secrets management
mkp Deterministic password generator from a seed phrase
sql-client SQL client via kubectl port-forward

Using Scripts

# Direct execution (available after installation)
aws-secrets --help
mkp --help

# Or source in your script
source /path/to/bash-library/scripts/aws-secrets.sh

πŸ“š Examples

Check out the examples/ directory for practical usage examples of the library functions.

Contributing

Contributions are always welcome! Please read the contribution guidelines first.

License

MIT License - See LICENSE file for details


Made with ❀️ by hperezrodal

About

A comprehensive collection of reusable bash functions and scripts for common DevOps and system administration tasks, designed to make shell scripting more efficient and maintainable.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages