#!/bin/bash # verify-p12 - Verify WebDAV cartridge access with Bearer or Basic auth (optionally mTLS) # # Usage: # verify-p12 [p12_password] [p12_file] # verify-p12 -b|--basic [p12_password] [p12_file] # verify-p12 -h # # Options: # -b, --basic Use Basic auth instead of Bearer # hostname Instance hostname (e.g. dev01-web-example.demandware.net) # token Bearer token for authorization (default auth mode) # user:pass Username and password for Basic auth (with --basic) # p12_password (optional) Password for the .p12 client certificate # p12_file (optional) Path to .p12 file (default: $USER-hostname.p12) # -h, --help Show help message _verify_p12() ( local SCRIPT_NAME; SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")" case "${BASH_SOURCE[0]}" in /dev/*|/proc/*) SCRIPT_NAME="" ;; esac case "$SCRIPT_NAME" in ""|bash|sh|zsh|dash) SCRIPT_NAME="verify-p12" ;; esac _error() { echo "[ERR][$SCRIPT_NAME] $*" >&2; } _expand_short_opts() { # $1 = string of short-opt letters that take a value (e.g. "nXHd"); "" for flag-only scripts # $2..$N = "$@" # Populates _EXPANDED; caller does: set -- "${_EXPANDED[@]}"; unset _EXPANDED local value_opts="$1"; shift _EXPANDED=() local passthru="" local arg local rest local c for arg in "$@"; do if [ -n "$passthru" ]; then _EXPANDED+=("$arg"); continue; fi case "$arg" in --) passthru=1; _EXPANDED+=("$arg") ;; --*|-|"") _EXPANDED+=("$arg") ;; -[a-zA-Z]?*) rest="${arg#-}" while [ -n "$rest" ]; do c="${rest%"${rest#?}"}"; rest="${rest#?}" _EXPANDED+=("-$c") case "$value_opts" in *"$c"*) [ -n "$rest" ] && _EXPANDED+=("$rest") rest="" ;; esac done ;; *) _EXPANDED+=("$arg") ;; esac done } _show_help() { local s; [ -t 1 ] && s=$'\033[4m' local r; [ -t 1 ] && r=$'\033[24m' cat <&2 # Print the HTTP status line and file URLs # -i == include response headers in output curl -si -X GET \ --url "$url" \ -H "$auth_header" \ "${p12_args[@]}" \ | tr -d '\r' \ | grep -e '^HTTP/[.0-9]\{1,3\} [0-9]\{3\} [ A-Za-z]*$' \ -e '.*$||' ) _verify_p12 "$@" __verify_p12_rc=$? unset -f _verify_p12 if [ -n "${BASH_SOURCE[0]}" ] && [ "${BASH_SOURCE[0]}" != "$0" ]; then eval "unset __verify_p12_rc; return $__verify_p12_rc" fi eval "unset __verify_p12_rc; exit $__verify_p12_rc"