{"id":13495333,"url":"https://github.com/cyberark/bash-lib","last_synced_at":"2025-04-04T21:07:58.035Z","repository":{"id":35714226,"uuid":"181513803","full_name":"cyberark/bash-lib","owner":"cyberark","description":"Library for bash utility methods and tools","archived":false,"fork":false,"pushed_at":"2024-01-04T15:48:17.000Z","size":250,"stargazers_count":663,"open_issues_count":3,"forks_count":25,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-03-28T20:07:27.781Z","etag":null,"topics":["bash","conjbot-notify","utility"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cyberark.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-15T15:19:12.000Z","updated_at":"2025-03-26T05:43:12.000Z","dependencies_parsed_at":"2024-01-07T21:04:59.354Z","dependency_job_id":"7d25f8b4-7114-40a8-8de0-41d23d2bb979","html_url":"https://github.com/cyberark/bash-lib","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberark%2Fbash-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberark%2Fbash-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberark%2Fbash-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberark%2Fbash-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyberark","download_url":"https://codeload.github.com/cyberark/bash-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249525,"owners_count":20908212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","conjbot-notify","utility"],"created_at":"2024-07-31T19:01:33.658Z","updated_at":"2025-04-04T21:07:58.021Z","avatar_url":"https://github.com/cyberark.png","language":"Shell","readme":"# bash-lib\n\nIntroductory blog post: https://www.conjur.org/blog/stop-bashing-bash/\n\n```\n                   _______________  _______________\n                 .'               .'               .|\n               .'               .'               .' |\n             .'_______________.'______________ .'   |\n             | ___ _____ ___ || ___ _____ ___ |     |\n             ||_=_|__=__|_=_||||_=_|__=__|_=_||     |\n       ______||_____===_____||||_____===_____||     | __________\n    .'       ||_____===_____||||_____===_____||    .'          .'|\n  .'         ||_____===_____||||_____===_____||  .'          .'  |\n.'___________|_______________||_______________|.'__________.'    |\n|.----------.|.-----___-----.||.-----___-----.||    |_____.----------.\n|]          |||_____________||||_____________|||  .'      [          |\n||          ||.-----___-----.||.-----___-----.||.'        |          |\n||          |||_____________||||_____________|||==========|          |\n||          ||.-----___-----.||.-----___-----.||    |_____|          |\n|]         o|||_____________||||_____________|||  .'      [        'o|\n||          ||.-----___-----.||.-----___-----.||.'        |          |\n||          |||             ||||_____________|||==========|          |\n||          |||             |||.-----___-----.||    |_____|          |\n|]          |||             ||||             |||  .'      [          |\n||__________|||_____________||||_____________|||.'________|__________|\n''----------'''------------------------------'''----------''\n            (o)LGB                           (o)\n```\n\nThe place to store functions that are used in pipelines for multiple repos.\n\nPlease add whatever is useful to you, but keep it tidy so its still useful to everyone else :)\n\n## Release Status: Alpha\nTL;DR: Ready for use, but needs expansion.\n\nThe functions in this repo are tested and ready for use, but certain libs\nare pretty much place holders (eg logging). Those need further contributions\nbefore they provide a comprehensive solution.\n\n## License: Apache 2.0\nSee the [license file](LICENSE)\n\n## Usage\n\nAdd bash-lib into your project in the way that best fits your workflow. The only requirement is that you **pin the version of\nbash-lib that you use**. This is important so that changes to bash-lib do not have the power to break all projects that use\nbash-lib. Your project can then test updates to bash-lib and roll forward periodically.\n\nOptions:\n* Add a submodule: they are an easy way to integrate bash-lib and automatically use a single SHA until manually updated. Submodules add a pointer from a mount point in your repo to the external repo (bash-lib), and require workflow changes to ensure that pointer is derferenced during clone, checkout and some other opertaions.\n* Add a subtree: This repo uses subtrees to pull in test dependencies. Subtrees copy an external repo into a subdirectory of the host repo, no workflow changes are required. Subtrees naturally keep a single version of bash-lib until explicitly updated. Note that subtree merge commits do not rebase well :warning:, so best to keep subtree updates in separate PRs from normal commits.\n* Clone bash-lib in your deployment process, bash-lib doesn't have to be within your repo, just needs to be somewhere where your scripts can source [init](init). This is where it's most important that you implement a mechanism to always use the same SHA, as a **clone will track master by default, which is not an allowed use of bash-lib**.\n\nOnce you have bash-lib cloned in your project, you source two things:\n\n1. Source `bash-lib/init`. This ensures submodules are initalised and sets the BASH_LIB_DIR env var to the absolute path to the bash-lib dir. This makes it easy to source libraries from other scripts.\n2. Source `${BASH_LIB_DIR}/lib-name/lib` for any libraries you are interested in.\n\nYou are now ready to use bash-lib functions :)\n\n## Structure\nThe `/init` script sets up everything required to use the library, most\nimportantly the `BASH_LIB_DIR` variable which gives the absolute path to the root\nof the library and should be used for sourcing the modules.\n\nThe repo is organized into libraries, each library is a directory that has a\nlib file. Sourcing the lib for a library should expose all the functions\nthat library offers. The lib file may source or reference other supporting\nfiles within it's directory.\n\n```\n.\n├── libname\n│   ├── lib\n│   └── supporting-file\n├── init # init script, source this first\n├── run-tests # top level test script, executes all tests\n├── secrets.yml # secrets required for executing tests\n├── test-utils\n│   ├── bats # git subtree\n│   ├── bats-assert-1 # git subtree\n│   ├── bats-support # git subtree\n│   ├── lib\n│   └── tap2junit\n└── tests-for-this-repo\n    ├── filehandling.bats\n    ├── fixtures #\n    │   └── libname # Dir containing test fixtures for a library\n    ├── tap2junit\n    ├── libname.bats # contains tests for libname/lib\n    ├── python-lint # supporting files for python lint\n    ├── run-bats-tests # script to run bats tests\n    ├── run-gitleaks # script to check for leaked secrets\n    └── run-python-lint # script to run python lint\n```\n\n## Contents\n\n\u003c!-- html table due to markdown's lack of support for lists within tables --\u003e\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eLibrary\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n      \u003cth\u003eFunctions\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"filehandling/lib\"\u003efilehandling\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eFunctions relating to file and path handling\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_abs_path\u003c/b\u003e: Ensure a path is absolute\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"git/lib\"\u003egit\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eGit helpers\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_git_available\u003c/b\u003e: True if git binary or function is available\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_in_git_repo\u003c/b\u003e: True if current directory is a git working directory\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_github_owner_repo\u003c/b\u003e: returns $owner/$repo extracted from the url of the origin remote\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_repo_root\u003c/b\u003e: Find the root of the current git repo.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_all_files_in_repo\u003c/b\u003e: List files tracked by git, excludes submodules.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_remote_latest_tag\u003c/b\u003e: Returns the symbolic name of the latest tag from a remote.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_remote_latest_tagged_commit\u003c/b\u003e: Returns the SHA of the most recently tagged commit in a remote repo (\u003ccode\u003etag^{}\u003c/code\u003e).\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_remote_sha_for_ref\u003c/b\u003e: Returns the SHA for a given ref from a named remote.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_remote_tag_for_sha\u003c/b\u003e: Returns the tag corresponding to a SHA from a named remote - if there is one.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_tracked_files_excluding_subtrees\u003c/b\u003e: List files tracked by git, but excluding any files that are in paths listed in \u003ccode\u003e.gittrees\u003c/code\u003e.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_gittrees_present\u003c/b\u003e: Succeeds if .gittrees is present in the root of the repo, otherwise fails.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_cat_gittrees\u003c/b\u003e: Returns the contents of .gittrees from the top level of the repo, excluding any comments. Fails if .gittrees is not present.\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"github/lib\"\u003egithub\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eGithub Related Functions\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_available\u003c/b\u003e: True if hub binary or function is available\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_creds_available\u003c/b\u003e: True if hub creds are available (file or env vars)\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_check\u003c/b\u003e: Preflight check for hub, true if git installed, in git repo, hub installed and hub creds are available\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_download_latest\u003c/b\u003e: Download latest hub binary from github and install to ~/bin or specified path\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_issue_number_for_title\u003c/b\u003e: Find the issue number for an issue from its title, searches open issues in the current repo. (current repo = workding directory, repo is found by origin remote). If multiple issues match the supplied title string, only the first is returned.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_add_issue_comment\u003c/b\u003e: Add a comment to an issue\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_hub_comment_or_create_issue\u003c/b\u003e: Create issue if an issue matching the title doesn't exist. If a match is found, add a comment to it\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n      \u003ctd\u003e\u003ca href=\"helpers/lib\"\u003ehelpers\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eBash scripting helpers\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_die\u003c/b\u003e: print message and exit 1\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_fail\u003c/b\u003e: print message and return 1\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_spushd/bl_spopd\u003c/b\u003e: Safe verisons of pushd \u0026 popd that call die if the push/pop fails, they also drop stdout. \u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_is_num\u003c/b\u003e: Check if a value is a number via regex\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_retry\u003c/b\u003e: Retry a command until it succeeds up to a user specified maximum number of attempts. Escalating delay between attempts.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_retry_constant\u003c/b\u003e: Retry a command until it succeeds with a\n          constant delay between attempts\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"k8s/lib\"\u003ek8s\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eUtils for connecting to K8s\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_build_gke_image\u003c/b\u003e: Build docker image for running kubectl commands against GKE.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_delete_gke_image\u003c/b\u003e: Delete image from GKE.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_run_docker_gke_command\u003c/b\u003e: Run command in gke-utils container, already authenticated to k8s cluster.\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"logging/lib\"\u003elogging\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eHelpers related to logging.\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_announce\u003c/b\u003e: Echo message in ascii banner to distinguish it from other log messages.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_log\u003c/b\u003e: Log a message at the specified level. Default log level is info, change level by setting environment variable BASH_LIB_LOG_LEVEL\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_check_log_level\u003c/b\u003e: Check if a value is a valid bash lib\n          log level\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_debug\u003c/b\u003e: Log a message at debug level\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_info\u003c/b\u003e: Log a message at info level\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_warning\u003c/b\u003e: Log a message at warning level\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_error\u003c/b\u003e: Log a message at error level\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_fatal\u003c/b\u003e: Log a message at fatal level\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"ruby/lib\"\u003eRuby\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eHelpers related to ruby infrastructure\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_gem_latest_version\u003c/b\u003e: Return the latest version of a gem from rubygems.org\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_jq_available\u003c/b\u003e: Check jq binary is available\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_curl_available\u003c/b\u003e: Check curl binary is available\u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ca href=\"test-utils/lib\"\u003etest-utils\u003c/a\u003e\u003c/td\u003e\n      \u003ctd\u003eHelpers for executing tests\u003c/td\u003e\n      \u003ctd\u003e\n        \u003col\u003e\n          \u003cli\u003e\u003cb\u003ebl_shellcheck_script\u003c/b\u003e: Execute shellcheck against a script, uses docker.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_find_scripts\u003c/b\u003e: Find git tracked files with extension.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_tap2junit\u003c/b\u003e: Convert a subset of \u003ca href=\"http://testanything.org/\"\u003eTAP\u003c/a\u003e to JUnit XML. Retains logs for errors.\u003c/li\u003e\n          \u003cli\u003e\u003cb\u003ebl_validate_changelog\u003c/b\u003e: Check CHANGELOG.md (or a specified file) complies with keepachangelog.com format. \u003c/li\u003e\n        \u003c/ol\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n# Contributing\nFor further information on contributing, style \u0026 testing, please see [CONTRIBUTING.md](CONTRIBUTING.md)\n\n# Maintainers\n* [Hugh Saunders](https://github.com/hughsaunders)\n","funding_links":[],"categories":["Libraries","Shell","bash"],"sub_categories":["Reusable Things"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberark%2Fbash-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyberark%2Fbash-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberark%2Fbash-lib/lists"}