{"id":46391708,"url":"https://github.com/terraform-ibm-modules/common-bash-library","last_synced_at":"2026-03-05T09:03:13.704Z","repository":{"id":325722224,"uuid":"1101450444","full_name":"terraform-ibm-modules/common-bash-library","owner":"terraform-ibm-modules","description":"A library of bash functions for common tasks.","archived":false,"fork":false,"pushed_at":"2026-02-24T17:05:13.000Z","size":29,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-24T20:52:31.289Z","etag":null,"topics":["bash","common","core-team","ibm-cloud","library","shell"],"latest_commit_sha":null,"homepage":null,"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/terraform-ibm-modules.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-21T17:32:37.000Z","updated_at":"2026-02-24T20:51:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/terraform-ibm-modules/common-bash-library","commit_stats":null,"previous_names":["terraform-ibm-modules/common-bash-library"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/terraform-ibm-modules/common-bash-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-ibm-modules%2Fcommon-bash-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-ibm-modules%2Fcommon-bash-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-ibm-modules%2Fcommon-bash-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-ibm-modules%2Fcommon-bash-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terraform-ibm-modules","download_url":"https://codeload.github.com/terraform-ibm-modules/common-bash-library/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-ibm-modules%2Fcommon-bash-library/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30117486,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T08:19:04.902Z","status":"ssl_error","status_checked_at":"2026-03-05T08:17:37.148Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","common","core-team","ibm-cloud","library","shell"],"created_at":"2026-03-05T09:03:13.173Z","updated_at":"2026-03-05T09:03:13.683Z","avatar_url":"https://github.com/terraform-ibm-modules.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Common Bash Library\n\nA library of bash functions for common tasks.\n\n## [common](common)\n\u003cdetails\u003e\n  \u003csummary\u003eassert_eq\u003c/summary\u003e\n\nAssert that two input argument strings are equal.\n\n**Arguments:**\n- `$1`: First input argument string (required)\n- `$2`: Second input argument string (required)\n\n**Returns:**\n- `0` - Success (strings are equal)\n- `1` - Failure (exit if strings are not equal)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\nassert_eq \"test\" \"test\"\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eassert_pass\u003c/summary\u003e\n\nAssert that input argument is 0.\n\n**Arguments:**\n- `$1`: Return code to check (required)\n\n**Returns:**\n- `0` - Success (input argument is 0)\n- `1` - Failure (exit if input argument is not 0)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\nassert_pass 0\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eassert_fail\u003c/summary\u003e\n\nAssert that input argument is not 0.\n\n**Arguments:**\n- `$1`: Return code to check (required)\n\n**Returns:**\n- `0` - Success (input argument is not 0)\n- `1` - Failure (exit if input argument is 0)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\nassert_fail 1\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003echeck_env_vars\u003c/summary\u003e\n\nChecks if environment variables are set.\n\n**Environment Variables:**\n- `VERBOSE`: If set to true, print verbose output (optional, defaults to false)\n\n**Arguments:**\n- `$1..n`: environment variables to check\n\n**Returns:**\n- `0` - Success (all environment variables are set)\n- `1` - Failure (if any of the environment variables are not set)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\ncheck_env_vars PATH HOME\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003echeck_required_bins\u003c/summary\u003e\n\nChecks if binary exists by running `command -v \u003cbinary\u003e`.\n\n**Environment Variables:**\n- `VERBOSE`: If set to true, print verbose output (optional, defaults to false)\n\n**Arguments:**\n- `$1..n`: binaries to check\n\n**Returns:**\n- `0` - Success (all binaries are found)\n- `1` - Failure (if any of the binaries are not found)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\ncheck_required_bins git jq\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003einstall_jq\u003c/summary\u003e\n\nInstalls jq binary.\n\n**Environment Variables:**\n- `VERBOSE`: If set to true, print verbose output (optional, defaults to false)\n\n**Arguments:**\n- `$1`: version of jq to install (optional, defaults to latest). Example format of valid version is \"1.8.1\"\n- `$2`: location to install jq to (optional, defaults to /usr/local/bin)\n- `$3`: if set to true, skips installation if jq is already detected (optional, defaults to true)\n- `$4`: the exact url to download jq from (optional, defaults to https://github.com/jqlang/jq/releases/latest/download/jq-${os}-${arch})\n\n**Returns:**\n- `0` - Success (jq installed successfully)\n- `1` - Failure (installation failed)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\ninstall_jq \"latest\" \"/usr/local/bin\" \"true\"\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003einstall_kubectl\u003c/summary\u003e\n\nInstalls the kubectl binary.\n\n**Environment Variables:**\n- `VERBOSE`: If set to true, print verbose output (optional, defaults to false)\n\n**Arguments:**\n- `$1`: version of kubectl to install (optional, defaults to current latest stable). Example format: \"v1.34.2\"\n- `$2`: location to install kubectl (optional, defaults to /usr/local/bin)\n- `$3`: if set to true, skips installation if kubectl is already detected (optional, defaults to true)\n- `$4`: the exact URL to download kubectl from (optional, defaults to https://dl.k8s.io/release/\u003cversion\u003e/bin/\u003cos\u003e/\u003carch\u003e/kubectl)\n\n**Returns:**\n- `0` - Success (kubectl installation successful)\n- `1` - Failure (kubectl installation failed)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\ninstall_kubectl \"latest\" \"/usr/local/bin\" \"true\"\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eis_boolean\u003c/summary\u003e\n\nDetermine if value is a boolean.\n\n**Arguments:**\n- `$1`: value to check (required)\n\n**Returns:**\n- `0` - Success (value is a boolean - true, True, false or False)\n- `1` - Failure (value is not a boolean)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\nis_boolean \"true\"\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003ereturn_mac_architecture\u003c/summary\u003e\n\nReturns the architecture of the MacOS.\n\n**Arguments:** n/a\n\n**Returns:**\n- `0` - Success\n  - `\"amd64\"` - if the OS is macOS and the CPU is Intel\n  - `\"arm64\"` - if the OS is macOS and the CPU is Apple Silicon\n- `2` - Failure (Did not detect MacOS)\n\n**Usage:**\n```bash\narch=$(return_mac_architecture)\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n## [ibmcloud/iam](ibmcloud/iam.sh)\n\u003cdetails\u003e\n  \u003csummary\u003egenerate_iam_bearer_token\u003c/summary\u003e\n\nGenerates an IBM Cloud IAM bearer token from an API key.\n\n**Environment Variables:**\n- `IBMCLOUD_API_KEY`: IBM Cloud API key (required)\n- `IBMCLOUD_IAM_API_ENDPOINT`: IBM Cloud IAM API endpoint (optional, defaults to https://iam.cloud.ibm.com)\n\n**Arguments:** n/a\n\n**Returns:**\n- `0` - Success (token printed to stdout)\n- `1` - Failure (error message printed to stderr)\n\n**Usage:**\n```bash\nIBMCLOUD_API_KEY=XXX; token=$(generate_iam_bearer_token)\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n## [ibmcloud/cli](ibmcloud/cli.sh)\n\u003cdetails\u003e\n  \u003csummary\u003einstall_ibmcloud\u003c/summary\u003e\n\nInstalls the IBM Cloud CLI (ibmcloud).\n\n**Environment Variables:**\n- `VERBOSE`: If set to true, prints verbose output (optional, defaults to false)\n\n**Arguments:**\n- `$1`: version of IBM Cloud CLI to install (optional, defaults to \"latest\"). Example format: `\"2.41.0\"` or `\"latest\"`\n- `$2`: location to install ibmcloud binary (optional, defaults to /tmp)\n- `$3`: skip installation if ibmcloud is already detected (optional, defaults to \"true\"). Accepts `\"true\"` or `\"false\"`\n- `$4`: exact installer URL (optional, overrides automatic URL construction)\n\n**Returns:**\n- `0` - Success (IBM Cloud CLI installed successfully or skipped if already present)\n- `1` - Failure (installation failed)\n- `2` - Failure (incorrect usage of function, e.g., invalid boolean for $3)\n\n**Usage:**\n```bash\n# Install latest version\ninstall_ibmcloud\n\n# Install specific version\ninstall_ibmcloud \"2.41.0\" \"/usr/local/bin\" \"true\"\n```\n\u003c/details\u003e\n\n\u003c!------------------------------------------------\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003einstall_ibmcloud_plugins\u003c/summary\u003e\n\nInstalls one or more IBM Cloud CLI plugins.\n\n**Environment Variables:**\n- `VERBOSE`: If set to true, print verbose output (optional, defaults to false)\n\n**Arguments:**\n- `$1`: comma-separated plugin name(s) (required). Can specify version using `@` syntax. Spaces after commas are automatically trimmed. Examples: `\"code-engine\"` or `\"container-service@1.0.506,secrets-manager@0.1.25\"` or `\"container-registry, code-engine\"`\n- `$2`: custom directory for plugin installation (optional, uses default IBM Cloud home directory if not specified)\n- `$3`: if set to true, skips installation if plugin is already installed (optional, defaults to \"true\")\n\n**Returns:**\n- `0` - Success (all plugins installed successfully)\n- `1` - Failure (one or more plugins failed to install)\n- `2` - Failure (incorrect usage of function)\n\n**Usage:**\n```bash\n# Install latest version of a single plugin\ninstall_ibmcloud_plugins \"code-engine\"\n\n# Install multiple plugins (latest versions) - store in variable first\nplugins=\"code-engine,container-service,cloud-object-storage\"\ninstall_ibmcloud_plugins \"${plugins}\"\n\n# Install multiple plugins with spaces after commas (also supported)\ninstall_ibmcloud_plugins \"container-registry, code-engine\"\n\n# Install plugins with specific versions using @ syntax\nplugins=\"container-service@1.0.506,secrets-manager@0.1.25\"\ninstall_ibmcloud_plugins \"${plugins}\"\n\n# Install to custom location\nplugins=\"code-engine,container-service@1.0.506\"\ninstall_ibmcloud_plugins \"${plugins}\" \"/tmp\" \"true\"\n\n# Force reinstall (skip_if_detected = false)\ninstall_ibmcloud_plugins \"code-engine\" \"\" \"false\"\n```\n\n**Important Notes:**\n- The `@version` syntax allows you to specify exact plugin versions (e.g., `container-service@1.0.506`)\n- Multiple plugins can be installed in a single command using comma separation\n- When using a custom directory (via `$2`), you must set `IBMCLOUD_HOME` environment variable in any script that uses the plugins\n- Example: `export IBMCLOUD_HOME=\"/tmp\"` before running `ibmcloud` commands\n- This ensures `ibmcloud` can locate the installed plugins\n\n\u003c/details\u003e\n\n\n\u003c!------------------------------------------------\u003e\n\n## Usage\n\n### Sourcing the Library\n\nTo use functions from this library, source the desired module(s):-\n\n```bash\nsource /path/to/common-bash-library/\u003cmodule\u003e/\u003cfile\u003e.sh\n```\n\n\n### Running Tests\n\nThe library includes built-in unit tests. To run them, execute this script:\n\n```bash\ntests/run-tests.sh\n```\n\nNOTE: Some unit tests are configured to make api calls. These are disabled by default, but can be enabled by setting `MAKE_API_CALLS=true`. This will require setting environment variable `IBMCLOUD_API_KEY` with a valid IBM Cloud API key.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterraform-ibm-modules%2Fcommon-bash-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterraform-ibm-modules%2Fcommon-bash-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterraform-ibm-modules%2Fcommon-bash-library/lists"}