Featured image of post bashutils

bashutils

bash scripting utilities

Writing production-ready Bash scripts and reuse them across multiple projects ensuring predictable automation behavior across local environments and CI/CD pipelines alike, is really important.

We have developed and have been using bashutils for a while.

How to use it?

download the helper script into the root of your project, with:

1
2
curl -fsSL https://raw.githubusercontent.com/tgedr/bashutils/main/bashutils-template.sh \
    -o ./helper.sh && chmod +x ./helper.sh

if eventually you experience issues with the corporation proxy, try (python needed):

1
2
3
curl -fsSL "https://api.github.com/repos/tgedr/bashutils/contents/bashutils-template.sh" \
| python3 -c "import sys,json,base64; print(base64.b64decode(json.load(sys.stdin)['content']).decode())" \
    > ./helper.sh && chmod +x ./helper.sh

have a go, run ./helper.sh

  • if non-existent, it creates the files .variables (should be version-managed), .local_variables and .secrets (these 2 are for personal development purposes and should NOT be version-managed) next to the script
  • it downloads .bashutils on the first run,m it gets then included from now on
  • it provides a set of logging functions
  • on later runs it checks for updates at most once per day and replaces the local .bashutils from main only when newer
  • every downloaded .bashutils file is verified with SHA256 using .bashutils.checksum
  • you can now reuse .bashutils functions by referencing functions in your own .helper.sh:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    
    case "$1" in
        reqs)
        reqs
        ;;
        verify)
        verify_env
        ;;
        deploy)
        databricks_bundle_deploy "$2" "$3"
        ;;
        destroy)
        databricks_bundle_destroy "$2" "$3"
        ;;
        *)
        usage
        ;;
    esac
    
  • you can also add your own functions directly to the .helper.sh script
  • you are encouraged to submit PR’s to contribute with new functionality to .bashutils

do check it.

info@tgedr.com
Built with Hugo
Theme Stack designed by Jimmy