This project is a simple framework that provides some common utilities to facilitate shell script development. It includes a main execution script along with utility functions for tasks such as logging and file operations.
-
fire.sh:
The main script that:- Validates that it is running under Bash and has the necessary execute permissions.
- Changes the working directory to the script’s location.
- Creates a
logsdirectory if it doesn’t exist. - Executes within a subshell to ensure environment isolation.
- Sources
scripts/utils.sh, which offers a set of common utility functions. - Sources
scripts/run.shfor additional runtime logic (customize as needed). - Logs all output to a dated log file in the
logsdirectory. - Automatically cleans up log files older than 30 days.
-
scripts/utils.sh:
Provides a collection of common utility functions, including:- Logging functions:
info(),warn(), anderror()for different log levels. - A helper function
cp_if_diff()that copies a file only if its SHA256 checksum differs from the destination file.
Note: These utilities are meant as a basic toolkit for common operations and can be extended or modified to suit your needs.
- Logging functions:
-
scripts/run.sh:
Intended for executing additional commands or custom logic. It is currently empty and ready to be customized.
- Bash: Ensure you are using Bash to run these scripts.
- Execute Permission: The scripts, especially
fire.sh, must have execute permissions. You can set this with:chmod +x fire.sh
- Log Directory: The script will automatically create a
logsdirectory in its directory if it does not exist.
- Navigate to the project directory where
fire.shis located. - Run the script:
./fire.sh
- Review Logs: All output is recorded in the
logs/directory with filenames in the formatYYYY-MM-DD.log.
- Extending the Framework:
This framework provides a basic structure and a set of common utilities. You can extend it by:- Adding new utility functions in
scripts/utils.sh. - Implementing additional logic in
scripts/run.sh.
- Adding new utility functions in
- Utility Functions:
The functions provided inscripts/utils.shserve as a starting point for common operations. Customize them as needed.
The fire.sh script automatically cleans up log files older than 30 days to manage disk space.