#!/bin/bash VERSION="1.0.0" type=$1 title=$2 text=$3 label=${4//_/__} # "Escape" underscores} init=$5 ADDITIONAL_ARGS=6 function help { ( echo "Usage: oidc-prompt TITLE TEXT LABEL [INIT] [LIST_ELEMENTS ...]" echo "oidc-prompt -- An interface for prompting the user." echo echo "This tool is intended as a internal tool of oidc-agent. Different oidc-agent components use it to prompt the user for information. The user should not call oidc-prompt." )>&2 } case "$1" in "-?"|-h|--help) usage help exit ;; --usage) help exit ;; -V|--version) echo "oidc-prompt $VERSION" exit ;; esac if [ $# -le 2 ]; then help exit fi # To use another dialog creation tool, create a shell script that provides the # needed functions and include it here. function password { yad --no-markup --title "$title" --center --skip-taskbar --splash --text "$text" --button gtk-cancel:1 --button gtk-ok:0 --image dialog-password --entry --entry-label "$label" --entry-text "$init" --hide-text --completion #--ricon gohome --ricon-action "echo hallo" exit $? } function input { yad --no-markup --title "$title" --center --skip-taskbar --splash --text "$text" --button gtk-cancel:1 --button gtk-ok:0 --image dialog-question --entry --entry-label "$label" --entry-text "$init" --completion #--ricon gohome --ricon-action "echo hallo" exit $? } function confirm_default_no { yad --no-markup --title "$title" --center --skip-taskbar --splash --text "$text" --button gtk-no:1 --button gtk-yes:0 --image dialog-question ret=$? if [ $ret == 0 ]; then echo "yes" fi exit $ret } function confirm_default_yes { yad --no-markup --title "$title" --center --skip-taskbar --splash --text "$text" --button gtk-yes:0 --button gtk-no:1 --image dialog-question ret=$? if [ $ret == 0 ]; then echo "yes" fi exit $ret } function _select { h=$((125 + 22 * $#)) yad --no-markup --title "$title" --width 400 --height $h --center --skip-taskbar --splash --text "$text" --button gtk-cancel:1 --button gtk-ok:0 --image dialog-question --list --separator "" --search-column 1 --regex-search --column "$label" "$init" "${@}" } function select2 { if [ "$type" == "select-other" ]; then out=$(_select ${@} "Other") else out=$(_select ${@}) fi ret=$? out=${out//\\n/} if [ $ret != 0 ]; then exit $ret fi if [ "$out" != "Other" ]; then echo $out exit $ret else text=${text//Select/Enter} text=${text//select/enter} input fi } function multiple { printf '%s\n' "${@}" | head -c -1 | yad --no-markup --title "$title" --width 400 --height 222 --center --skip-taskbar --splash --text "$text" --button gtk-cancel:1 --button gtk-ok:0 --image dialog-question --label "$label" --text-info --editable | grep -v '^$' } case $type in "password") password ;; "input") input ;; "confirm-default-no") confirm_default_no ;; "confirm-default-yes") confirm_default_yes ;; "confirm") confirm_default_yes ;; select*) select2 "${@:$ADDITIONAL_ARGS}" ;; "multiple") multiple "$init" "${@:$ADDITIONAL_ARGS}" ;; *) >&2 echo "unknown type" exit 1 ;; esac