Call this dependency from another bash script to safely install and remove:
- pip
- apt
- snap packages
- In your other repo, include a file named:
.gitmodules
that includes:
[submodule "dependencies/bash-package-installer"]
path = dependencies/bash-package-installer
url = https://github.com/hiveminds/bash-package-installer
- Create a file named
install-dependencies.sh
with content:
# Remove the submodules if they were still in the repo.
git rm --cached dependencies/bash-package-installer
# Remove and create a directory for the dependencies.
rm -r "$SCRIPT_PATH/dependencies"
mkdir -p "$SCRIPT_PATH/dependencies"
# (Re) add the BATS submodules to this repository.
git submodule add --force https://github.com/hiveminds/bash-package-installer dependencies/bash-package-installer
# Update all submodules
git submodule update --remote --recursive
- Install the submodule with:
chmod +x install-dependencies.sh
./install-dependencies.sh
After including this dependency you can use the functions in this module like:
#!/bin/bash
# Load the installer dependency.
source "$REPO_ROOT_PATH/"/bash-package-installer/src/main.sh
# Call the desired installation functions.
ensure_apt_pkg "curl" 1
ensure_snap_pkg "brave"
ensure_pip_pkg "twine" 1
# Call the desired installation functions.
apt_remove "curl" 0
snap_remove "brave"
pip_remove "twine" 1
The 0
and 1
after the package name indicate whether it will update the
package manager afterwards (0
= no update, 1
= package manager update after
installation/removal)
Put your unit test files (with extension .bats) in folder: /test/
(Re)-install the required submodules with:
chmod +x install-dependencies.sh
./install-dependencies.sh
Install:
sudo gem install bats
sudo apt install bats -y
sudo gem install bashcov
sudo apt install shfmt -y
pre-commit install
pre-commit autoupdate
Run pre-commit with:
pre-commit run --all
Run the tests with:
bats test
If you want to run particular tests, you could use the test.sh
file:
chmod +x test.sh
./test.sh
bashcov bats test
- Include bash code coverage in GitLab CI.
- Add additional (relevant) pre-commit hooks.
- Develop Bash documentation checks here, and add them to this pre-commit.