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.
- 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
- Docker (20.10.0 or higher)
- Git
- Basic Shell Scripting knowledge
- Development Environment (VS Code, Vim, etc.)
- 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
curl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/install-remote.sh | bashIf 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.shAfter adding these lines, reload your zsh configuration:
source ~/.zshrc- Clone the repository:
git clone https://github.com/hperezrodal/bash-library.git
cd bash-library- Run the installation script:
./install.shcurl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/update-remote.sh | bashFor system-wide installations:
curl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/update-remote.sh | SYSTEM_INSTALL=true sudo -E bashsudo ./uninstall.shcurl -sSL https://raw.githubusercontent.com/hperezrodal/bash-library/main/uninstall-remote.sh | bashFor zsh users, remove the bash-library related lines from your ~/.zshrc file and run:
source ~/.zshrcAfter uninstallation, you may need to restart your shell or run source ~/.zshrc for changes to take effect.
The repository includes a pre-commit hook that runs shfmt and shellcheck on all shell scripts. To set it up:
-
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
-
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
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
| 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 |
| 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 |
| 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 |
| 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.
To use the library in your scripts, source the main functions file:
source /path/to/bash-library/lib-loader.shSee the Available Modules section for the full list.
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 |
# Direct execution (available after installation)
aws-secrets --help
mkp --help
# Or source in your script
source /path/to/bash-library/scripts/aws-secrets.shCheck out the examples/ directory for practical usage examples of the library functions.
Contributions are always welcome! Please read the contribution guidelines first.
MIT License - See LICENSE file for details
Made with β€οΈ by hperezrodal