#!/usr/bin/env bash
#

############## Setup #########################

function die {
    local status_code="$1"
    shift
    (>&2 echo "${@}")
    exit "$status_code"
}

function log {
    (>&2 echo "${@}")
}

############## Program #########################

function create_containing_directories {
    local full_dest="$1"
    shift 1
    local dirs_to_create=()
    local containing_directory="$full_dest"
    while true; do
        containing_directory=$(dirname "$containing_directory")
        if [ -e "$containing_directory" ] || [ "$containing_directory" = "/" ]; then
            break
        fi
        dirs_to_create+=($containing_directory)
    done

    for (( idx=${#dirs_to_create[@]}-1 ; idx>=0 ; idx-- )) ; do
        local containing_directory="${dirs_to_create[idx]}"
        log "Creating $containing_directory"
        $DRY_RUN_CMD install $VERBOSE_ARG -d "${@}" "$containing_directory"
    done

}
