Skip to content

mattsebastianh/bash_automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Automation Script

A lightweight Bash automation script for managing build processes with version control, file copying, and sensitive data protection.

License: MIT Shell

Table of Contents

Overview

This script automates the build process for projects by intelligently copying source files to a build directory while maintaining version control and security best practices. It's designed to be simple, safe, and shell-agnostic.

Key capabilities:

  • πŸ“‹ Automatic version detection from changelog
  • πŸ”’ Sensitive file exclusion (prevents accidental exposure)
  • βœ… Interactive build confirmation
  • πŸ“¦ Clean build directory management
  • 🎯 Cross-shell compatibility (Bash & Zsh)

Features

  • βœ… Version Detection - Automatically extracts version from source/changelog.md

  • βœ… Interactive Confirmation - Prompts user before building to prevent accidents

  • βœ… Security Filtering - Excludes sensitive files (like secretinfo.md) from builds

  • βœ… Input Validation - Handles invalid user input gracefully

  • βœ… Build Management - Creates and manages build directory automatically

  • βœ… Build Summary - Lists all files included in the build

  • βœ… Cross-Shell Support - Works seamlessly with Bash and Zsh## Prerequisites

  • Shell: Bash 3.0+ or Zsh 5.0+

  • OS: macOS, Linux, or WSL (Windows Subsystem for Linux)

  • Required Files:

    • source/ directory with your source files
    • source/changelog.md with version on first line (format: # Version X.X.X)

Installation

  1. Clone or download this repository:

    git clone <your-repo-url> cd bash_automation
  2. Set up your source files:

    # Ensure your source directory exists mkdir -p source # Create a changelog with version information echo "# Version 1.0.0" > source/changelog.md
  3. Make the script executable:

    chmod +x script.sh

Usage

Quick Start

Run the build script with a single command:

./script.sh

The script will:

  1. Display the detected version from your changelog
  2. Ask for confirmation before proceeding
  3. Copy all source files to the build/ directory (excluding sensitive files)
  4. Show a summary of the build contents

For Bash

# Method 1: Direct execution (if executable) ./script.sh # Method 2: Explicit bash invocation bash script.sh

For Zsh

# Method 1: Direct execution (if executable) ./script.sh # Method 2: Run with bash (recommended for compatibility) bash script.sh # Method 3: Run with zsh zsh script.sh

How It Works

The build automation script follows a simple, secure workflow:

1. Version Detection

  • Reads the first line of source/changelog.md
  • Extracts version number using string parsing
  • Displays version to user for confirmation

2. User Confirmation

  • Prompts user: "Do you want to continue? (enter '1' for yes, '0' for no)"
  • Validates input (only accepts 1 or 0)
  • Exits gracefully on invalid input or user decline

3. File Processing

  • Iterates through all files in source/ directory
  • Security check: Skips source/secretinfo.md to prevent sensitive data exposure
  • Creates build/ directory if it doesn't exist
  • Copies each non-sensitive file to build/

4. Build Summary

  • Changes to build/ directory
  • Lists all copied files
  • Displays build version for verification

Project Structure

bash_automation/ β”œβ”€β”€ LICENSE # MIT License β”œβ”€β”€ README.md # This file β”œβ”€β”€ script.sh # Main build automation script β”œβ”€β”€ .gitignore # Git ignore rules β”œβ”€β”€ source/ # Source files directory β”‚ β”œβ”€β”€ changelog.md # Version information (REQUIRED) β”‚ β”œβ”€β”€ secretinfo.md # Sensitive file (excluded from build) β”‚ β”œβ”€β”€ bar.js # Example source files β”‚ β”œβ”€β”€ buzz.css β”‚ β”œβ”€β”€ foo1.html β”‚ β”œβ”€β”€ foo2.html β”‚ └── foo3.html └── build/ # Generated build directory (gitignored) β”œβ”€β”€ changelog.md # Copied files β”œβ”€β”€ bar.js β”œβ”€β”€ buzz.css β”œβ”€β”€ foo1.html β”œβ”€β”€ foo2.html └── foo3.html 

Configuration

Changelog Format

Your source/changelog.md must start with a version line:

# Version 1.2.3 ## Changes - Feature A - Bug fix B

Excluding Files from Build

To exclude additional files, modify the condition in script.sh:

if [ $filename == "source/secretinfo.md" ] || [ $filename == "source/another-file.md" ] then echo "Not copying $filename with sensitive info" fi

Example Output

$ ./script.sh πŸ”₯πŸ”₯πŸ”₯Beginning build!! πŸ”₯πŸ”₯πŸ”₯ You are building version 1.2.3 Do you want to continue? (enter "1" for yes, "0" for no) 1 OK source/bar.js Copying source/bar.js source/buzz.css Copying source/buzz.css source/changelog.md Copying source/changelog.md source/foo1.html Copying source/foo1.html source/foo2.html Copying source/foo2.html source/foo3.html Copying source/foo3.html source/secretinfo.md Not copying source/secretinfo.md with sensitive info Build version 1.2.3 contains: bar.js buzz.css changelog.md foo1.html foo2.html foo3.html

Troubleshooting

Issue: "Permission denied" error

Solution: Make the script executable

chmod +x script.sh

Issue: "No such file or directory: source/changelog.md"

Solution: Create the required changelog file

mkdir -p source echo "# Version 1.0.0" > source/changelog.md

Issue: Version shows as empty or incorrect

Problem: Changelog format is incorrect
Solution: Ensure first line of source/changelog.md matches: # Version X.X.X

# Correct format echo "# Version 1.0.0" > source/changelog.md # Verify head -n 1 source/changelog.md

Issue: Script runs on wrong shell

Solution: Explicitly specify bash interpreter

bash script.sh

Issue: Build directory not created

Solution: Check write permissions in project directory

ls -la | grep bash_automation chmod u+w . # Grant write permission if needed

Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Ideas for Contributions

  • Add support for custom exclude patterns (regex or glob)
  • Implement logging to a build log file
  • Add timestamp to build directory names
  • Support for multiple build configurations
  • Add pre/post-build hooks
  • Create a config file for settings

License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License Summary:

  • βœ… Commercial use
  • βœ… Modification
  • βœ… Distribution
  • βœ… Private use
  • ❌ Liability
  • ❌ Warranty

Made with ❀️ for build automation

Need help? Open an issue or contribute to make this tool better!

About

Lightweight bash build automation with version control and security filtering

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages