181 lines
3.3 KiB
Bash
181 lines
3.3 KiB
Bash
|
|
# Workllow
|
|
#
|
|
# API
|
|
# i <ident>
|
|
# i status <ident>
|
|
# i switch <ident>
|
|
# i disable <ident>
|
|
# i help
|
|
# i FORWARD
|
|
|
|
# ${debian_chroot:+($debian_chroot)}\u@\h:\w\$
|
|
|
|
|
|
#IAM_BIN=/home/jez/volumes/data/prj/jez/lab/iam-python/.direnv/python-3.11.3/bin/iam
|
|
IAM_BIN=$(command -v iam)
|
|
IAM_IDENT=
|
|
|
|
i_usage ()
|
|
{
|
|
echo "iam shell wrapper"
|
|
|
|
cat << EOF
|
|
|
|
Usage:
|
|
i [status] Show shell status
|
|
i switch IDENT Enable shell identity
|
|
i disable Disable shell identity
|
|
i kill Disable and kill shell identity
|
|
i help Show this help
|
|
|
|
Informations:
|
|
IAM_BIN=${IAM_BIN}
|
|
SHELL_IDENT=${SHELL_IDENT:-_}
|
|
|
|
EOF
|
|
}
|
|
|
|
i ()
|
|
{
|
|
# set -x
|
|
|
|
# Get status
|
|
target_ident=_
|
|
current_ident=${SHELL_IDENT:-_}
|
|
available_idents=$($IAM_BIN shell idents -O words)
|
|
|
|
# Internal vars
|
|
remaining_args=
|
|
idents_pattern=:${available_idents// /:}:
|
|
index=0
|
|
action=
|
|
|
|
|
|
while [[ -n "${1-}" ]] ; do
|
|
local arg=$1
|
|
|
|
case "$arg" in
|
|
status|st)
|
|
action=status
|
|
shift 1
|
|
if [[ -n "${1}" ]]; then
|
|
target_ident=$1
|
|
shift 1
|
|
fi
|
|
;;
|
|
switch|enable|en)
|
|
action=switch
|
|
shift 1
|
|
if [[ -n "${1}" ]]; then
|
|
target_ident=$1
|
|
shift 1
|
|
fi
|
|
;;
|
|
disable|dis|q)
|
|
action=disable
|
|
shift 1
|
|
;;
|
|
kill|k)
|
|
action=kill
|
|
shift 1
|
|
;;
|
|
stop|K)
|
|
action=kill_all
|
|
shift 1
|
|
;;
|
|
help|--help|-h)
|
|
action=help
|
|
shift 1
|
|
;;
|
|
*)
|
|
if [[ "$idents_pattern" == *":$arg:"* ]]; then
|
|
action=switch
|
|
target_ident=$arg
|
|
shift 1
|
|
else
|
|
remaining_args="$remaining_args $arg"
|
|
shift 1
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
((index++))
|
|
done
|
|
|
|
if [[ -z "$action" ]]; then
|
|
action="idents"
|
|
fi
|
|
|
|
|
|
# echo "Current Ident: $current_ident"
|
|
# echo "Target Ident: $target_ident"
|
|
# echo "Action: $action"
|
|
|
|
case "$action" in
|
|
idents)
|
|
echo "Iam path: ${IAM_BIN}"
|
|
echo "Current ident: ${SHELL_IDENT:-<None>}"
|
|
echo "Available identities: $($IAM_BIN shell idents -O words)"
|
|
;;
|
|
|
|
switch)
|
|
# if [[ "$current_ident" != '_' ]]; then
|
|
# eval $IAM_BIN shell disable $current_ident
|
|
# fi
|
|
# $IAM_BIN shell switch $target_ident
|
|
|
|
if [[ "$target_ident" != '_' ]]; then
|
|
>&2 echo "DEBUG: eval: $IAM_BIN shell switch $target_ident"
|
|
eval "$($IAM_BIN shell switch $target_ident)"
|
|
fi
|
|
;;
|
|
|
|
disable)
|
|
if [[ "$current_ident" != '_' ]]; then
|
|
>&2 echo "DEBUG: eval: $IAM_BIN shell switch"
|
|
eval "$($IAM_BIN shell disable)"
|
|
fi
|
|
;;
|
|
|
|
kill)
|
|
if [[ "$current_ident" != '_' ]]; then
|
|
>&2 echo "DEBUG: eval: $IAM_BIN shell switch --kill"
|
|
eval "$($IAM_BIN shell disable --kill)"
|
|
fi
|
|
;;
|
|
|
|
kill_all)
|
|
eval "$($IAM_BIN shell kill -a)"
|
|
;;
|
|
|
|
status)
|
|
echo "IAM_BIN=${IAM_BIN}"
|
|
echo "SHELL_IDENT=${SHELL_IDENT:-_}"
|
|
|
|
#echo $IAM_BIN shell status $current_ident
|
|
;;
|
|
help)
|
|
i_usage
|
|
;;
|
|
esac
|
|
|
|
|
|
|
|
set +x
|
|
return
|
|
|
|
|
|
# Source or switch
|
|
if $source_output; then
|
|
out=($IAM_BIN $@)
|
|
echo "SOURCE: $out"
|
|
else
|
|
echo $IAM_BIN $@
|
|
fi
|
|
|
|
set +x
|
|
}
|
|
|
|
#i2 $@
|