Flexible bash script runner.
Project description
packe
packe is a script runner for executing configuration scripts in bulk. Supports flexible script selection and hierachical structure.
Features
- Execute indexed bash scripts in order.
- Script output prefixed with identifier.
- Organize scripts into indexed packs (folders).
- Use prerun scripts to conditionally run packs.
- Use a config file to define script roots.
- Flexible script selection using run selectors with ranges and wildcards.
- Extra bash commands for colored output in scripts.
Script
A packe script is a bash file that is executed by packe. packe script files must end with .bash or .sh. They also need to be indexed, kind of like conf.d files.
You can index scripts using - or . as separators. Scripts are normally indexed using numbers, but you can also use underscores. Underscored scripts can only be executed explicitly by name.
Here are some examples of valid script filenames:
01-setup.bash
02.install.bash
_.do-stuff.bash
_-do-more-stuff.sh
Files that aren't indexed using numbers or underscores aren't considered executable by packe.
Script pack
A script pack is an indexed folder that contains more indexed scripts or packs. Script packs are indexed using numbers or underscores, just like scripts.
Here is an example folder structure with several script packs:
root/
1.first/
001.setup.bash
002.install.bash
2.second/
01.setup.bash
02.install.bash
When a script pack is executed, all its numbered contents are executed recursively in lexicographic order. This doesn’t include _ scripts or packs.
Packs let you organize scripts into groups. For example, you can have a pack for setting up a database, and another for setting up a web server.
Folders that aren't indexed using numbers or underscores aren't considered executable by packe.
Root
A root is a special script pack that is defined in the config file. A root can contain other packs or scripts. It doesn't have any naming requirements.
Run selector
A run selector is a glob-like path that determines which scripts to run. It can include ranges and wildcards.
Run selectors are made of path segments separated by /. Each segment can be one or more references to a script or pack. There are several ways to reference scripts or packs.
Here are some examples of valid run selectors:
one/hello/1-5
folder/%/3
root/1,3,5
root/web,db/4-5/install
Run selectors match all scripts and packs that fit the criteria.
Numbers
Numbers match index of the script or pack. For example, 1 matches:
01-setup.bash
1-folder/
Numbers can still match multiple files.
Ranges
You can also use ranges. For example, 1-3 would match:
01-setup.bash
02-install.bash
03-configure.bash
Names
Names match the unindexed name part of the script or pack. For example, run/setup would match:
01-setup.bash
02-setup.bash
1-setup/
Names are the only way to match unnumbered scripts and packs. However, unnumbered packs can still contain numbered scripts that can be matched using numbers or ranges.
Commas
Commas let you combine multiple references. For example, 1,3,go would match:
01-setup.bash
03-install.bash
1-go/
Wildcards
The % symbol acts as a wildcard that matches all numbered scripts and packs in a folder. For example, folder/%/3 would match:
root/1-first/03-configure.bash
root/2-second/03-configure.bash
Config file
packe uses a YAML file to define script roots. The config file is a YAML file.
Here is an example of a config file:
before: ./before.bash
entrypoints:
one:
path: ./one
two:
path: ./two
You can pass the config file to packe using the -C/--config option or by setting the PACKE_CONFIG environment variable.
Usage
First you need to give packe a config file. You can do this in two ways:
- The
-C/--configoption which should appear before any command. - The
PACKE_CONFIGenv var.
Examples:
packe -C example/config.yaml run root/1
export PACKE_CONFIG=example/config.yaml
packe run root/1
In the following examples, we’ll assume PACKE_CONFIG is set accordingly.
Run
This lets you run script based on run selectors. You can use more than one run selector, separated by spaces.
Scripts will be executed in the order specified and lexicographic order within each selector.
packe run SELECTOR1 [SELECTOR2 SELECTOR2 ...]
packe run folder/1-5,extra/5,9,db root/2/stuff
List
Works like run but lists the names of scripts and packs that would be run by a list of selectors. This doesn’t run prerun scripts.
packe list SELECTOR1 [SELECTOR2 SELECTOR2 ...]
packe list folder/%/4
This pretty prints scripts contents with syntax highlighting. All the matched scripts will be printed. For example, this will print script 2 in pack 1:
packe print SELECTOR1 [SELECTOR2 SELECTOR3 ...]
packe print folder/1/2
Extra features
packe scripts have some extra features that make them easier to use.
Prerun scripts
A prerun script is a special script that determines whether to execute a given pack. They're used as a failsafe to make sure sensitive configuration scripts are only executed when certain conditions are met.
Prerun scripts must be named packe.pre.bash or packe.pre.sh.
When you execute a run command, packe will go down the pack tree and execute every prerun script it finds. If a prerun script exits with a non-zero status, the entire pack is skipped.
These prerun scripts will always be executed, no matter how you match the scripts.
For example, let's say you have:
root/
packe.pre.bash
1.first/
packe.pre.bash
001.setup.bash
002.install.bash
2.second/
01.setup.bash
02.install.bash
And you run the selector root/1/setup. packe will execute the prerun files in the following order:
root/packe.pre.bash
root/1.first/packe.pre.bash
The script won't be executed if either of those files exits with a non-zero status.
Note that each prerun is executed only once per run command, even if multiple scripts in the pack are matched explicitly or you use multiple selectors.
Echo with colors
packe scripts can use special echo commands to print colored text to the terminal. These commands are:
echo.red "This text will be red"
echo.green "This text will be green"
echo.yellow "This text will be yellow"
echo.white "This text will be white"
echo.blue "This text will be blue"
Echo with levels
packe scripts can also use special echo commands to print text with different levels of importance. These commands are:
echo.info "Informational"
echo.warn "Warning"
echo.error "Error"
echo.section "Clearly visible section across several rows"
All of these commands print to standard output, but they format the output based on the log level.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file packe-0.6.1.tar.gz.
File metadata
- Download URL: packe-0.6.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.0 CPython/3.11.2 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7c6a77afe3ef27a42006f099ccab0ecf1418f525ab815a19d101ee51dad898e
|
|
| MD5 |
47d14c4e7a1c717336bef6d786aee555
|
|
| BLAKE2b-256 |
4757199173299b5d5f7675908151f6b4973ee843e3f9678bf4089bce93ef9d19
|
File details
Details for the file packe-0.6.1-py3-none-any.whl.
File metadata
- Download URL: packe-0.6.1-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.0 CPython/3.11.2 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
115528041c02f8ca4c29c9faeaf7e2cb4c87415e6684e3d4b4431d605789561d
|
|
| MD5 |
8b880c53bfdc636e076bf67618a4c6b5
|
|
| BLAKE2b-256 |
fabbe3cbe9a4794715c97c5dc8d99cbd798443b95ac8b05daf37567c7e38cf32
|