A lightweight Bash automation script for managing build processes with version control, file copying, and sensitive data protection.
- Overview
- Features
- Prerequisites
- Installation
- Usage
- How It Works
- Project Structure
- Configuration
- Example Output
- Troubleshooting
- Contributing
- License
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)
-
β 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 filessource/changelog.md
with version on first line (format:# Version X.X.X
)
-
Clone or download this repository:
git clone <your-repo-url> cd bash_automation
-
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
-
Make the script executable:
chmod +x script.sh
Run the build script with a single command:
./script.sh
The script will:
- Display the detected version from your changelog
- Ask for confirmation before proceeding
- Copy all source files to the
build/
directory (excluding sensitive files) - Show a summary of the build contents
# Method 1: Direct execution (if executable) ./script.sh # Method 2: Explicit bash invocation bash script.sh
# 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
The build automation script follows a simple, secure workflow:
- Reads the first line of
source/changelog.md
- Extracts version number using string parsing
- Displays version to user for confirmation
- Prompts user: "Do you want to continue? (enter '1' for yes, '0' for no)"
- Validates input (only accepts
1
or0
) - Exits gracefully on invalid input or user decline
- 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/
- Changes to
build/
directory - Lists all copied files
- Displays build version for verification
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
Your source/changelog.md
must start with a version line:
# Version 1.2.3 ## Changes - Feature A - Bug fix B
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
$ ./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
Solution: Make the script executable
chmod +x script.sh
Solution: Create the required changelog file
mkdir -p source echo "# Version 1.0.0" > source/changelog.md
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
Solution: Explicitly specify bash interpreter
bash script.sh
Solution: Check write permissions in project directory
ls -la | grep bash_automation chmod u+w . # Grant write permission if needed
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- 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
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!