Reusable shell functions for infrastructure automation and developer experience

  • Installation
  • Installation instructions

  • Download
  • Secure and reliable data retrieval from remote servers

  • File
  • Utilities for local file operations

  • Software
  • Tooling setup for local development and continuous integration environments

  • Log
  • Generic console and logging and helpers

  • Text
  • Constants for console text formatting

  • AWS
  • Utilities for the AWS cloud API

  • Terraform
  • Wrappers and helpers for Terraform

  • Python
  • Wrappers and helpers for Python

All functions are tested on the following distributions

  • Amazon Linux 2
  • Debian 10
  • Debian 11
  • Ubuntu 20.04
  • Ubuntu 22.04

Kitchen Sink Usage Example

#!/usr/bin/env bash

set -eu -o pipefail

DIR="$(cd "$(dirname "$0")" ; pwd -P)"


# self contained function for initial Solidblocks bootstrapping
function bootstrap_solidblocks() {
  local default_dir="$(cd "$(dirname "$0")" ; pwd -P)"
  local install_dir="${1:-${default_dir}/.solidblocks-shell}"

  local temp_file="$(mktemp)"

  curl -v -L "${SOLIDBLOCKS_BASE_URL:-}/pellepelster/solidblocks/releases/download/${SOLIDBLOCKS_SHELL_VERSION}/solidblocks-shell-${SOLIDBLOCKS_SHELL_VERSION}.zip" > "${temp_file}"
  echo "${SOLIDBLOCKS_SHELL_CHECKSUM}  ${temp_file}" | sha256sum -c

  mkdir -p "${install_dir}" || true
      cd "${install_dir}"
      unzip -o -j "${temp_file}" -d "${install_dir}"
      rm -f "${temp_file}"

# makes sure all needed shell functions functions are available and all bootstrapped software is on the $PATH
function ensure_environment() {

  if [[ ! -d "${DIR}/.solidblocks-shell" ]]; then
    echo "environment is not bootstrapped, please run ./do bootstrap first"
    exit 1

  # included needed shell functions
  source "${DIR}/.solidblocks-shell/"
  source "${DIR}/.solidblocks-shell/"
  source "${DIR}/.solidblocks-shell/"

  # ensure $PATH contains all software downloaded via the `software_ensure_*` functions

# bootstrap Solidblocks, and all other software needed using the software installer helpers from
function task_bootstrap() {

# run the downloaded terraform version, ensure_environment ensures the downloaded versions takes precedence over any system binaries
function task_terraform {
  terraform -version

function task_log {
    log_info "info message"
    log_success "success message"
    log_warning "warning message"
    log_debug "debug message"
    log_error "error message"

function task_text {
    echo "${FORMAT_DIM}Dim${FORMAT_RESET}"
    echo "${FORMAT_UNDERLINE}Underline${FORMAT_RESET}"
    echo "${FORMAT_BOLD}Bold${FORMAT_RESET}"
    echo "${COLOR_RED}Red${COLOR_RESET}"
    echo "${COLOR_GREEN}Green${COLOR_RESET}"
    echo "${COLOR_YELLOW}Yellow${COLOR_RESET}"
    echo "${COLOR_BLACK}Black${COLOR_RESET}"
    echo "${COLOR_BLUE}Blue${COLOR_RESET}"
    echo "${COLOR_MAGENTA}Magenta${COLOR_RESET}"
    echo "${COLOR_CYAN}Cyan${COLOR_RESET}"
    echo "${COLOR_WHITE}White${COLOR_RESET}"

# provide some meaningful help using shell formatting from
function task_usage {
  cat <<EOF
Usage: $0

  bootstrap             initialize the development environment
  terraform             run terraform
  log                   log some stuff
  text                  print soe fancy text formats
  exit 1

shift || true

# if we see the bootstrap command assume Solidshell is not yet initialized and skip environment setup
case "${ARG}" in
  bootstrap) ;;
  *) ensure_environment ;;

case ${ARG} in
  bootstrap) task_bootstrap "$@" ;;
  terraform) task_terraform "$@" ;;
  log)       task_log "$@" ;;
  text)      task_text "$@" ;;
  *) task_usage ;;