update zssh

This commit is contained in:
accel 2021-11-22 18:41:59 +03:00
parent 4e720dfb9f
commit 2125b49716

View File

@ -1,5 +1,6 @@
function zssh_boot() function zssh_boot()
{ {
zbootstrap_message zssh "zssh is booting up ----------------------------"
typeset -g zssh_ssh_dotdir="${HOME}/.ssh" typeset -g zssh_ssh_dotdir="${HOME}/.ssh"
typeset -g zssh_private_keys="${zssh_ssh_dotdir}/keystore" typeset -g zssh_private_keys="${zssh_ssh_dotdir}/keystore"
typeset -g zssh_private_configs="${zssh_ssh_dotdir}/config.d" typeset -g zssh_private_configs="${zssh_ssh_dotdir}/config.d"
@ -22,10 +23,12 @@ function zssh_configure ()
if [[ ${#zssh_host_config_accesses} -gt 0 ]] if [[ ${#zssh_host_config_accesses} -gt 0 ]]
then then
zbootstrap_message zssh "zssh_host_config_accesses is set" zbootstrap_message zssh "zssh_host_config_accesses is set"
zbootstrap_message zssh "global our pubkey directory is $(zssh_host_info -K)"
zbootstrap_message zssh "global our config directory is $(zssh_host_info -c)"
typeset -g zssh_global_config_hostdir="${zssh_global_configs}/${zssh_host}" typeset -g zssh_global_config_hostdir="${zssh_global_configs}/${zssh_host}"
typeset -g zssh_global_pubkey_hostdir="${zssh_global_pubkeys}/${zssh_host}" typeset -g zssh_global_pubkey_hostdir="${zssh_global_pubkeys}/${zssh_host}"
ztools_ensure -d "${zssh_global_pubkey_hostdir}" ztools_ensure -d $(zssh_host_info -K) #"${zssh_global_pubkey_hostdir}"
ztools_ensure -d "${zssh_global_config_hostdir}" ztools_ensure -d $(zssh_host_info -C) # "${zssh_global_config_hostdir}"
else else
zbootstrap_message zssh "zssh_host_config_accesses is NOT set, not going to bother accepting keys" zbootstrap_message zssh "zssh_host_config_accesses is NOT set, not going to bother accepting keys"
fi fi
@ -34,6 +37,51 @@ function zssh_configure ()
fi fi
} }
function zssh_host_info()
{
local=ssh_node=${zssh_host}
zssh_node_info ${zssh_host} $@
}
function zssh_node_info()
{
local ssh_node=$1
shift
while getopts 'kKcCM:E:' opt
do
case $opt in
(s)
# private privkey
echo "$zssh_private_keys/${ssh_node}.key"
;;
(k)
# private pubkey
echo "$zssh_private_keys/${ssh_node}.key.pub"
;;
(M)
# public pubkey mail file
echo "$zssh_global_pubkeys/${ssh_node}/${OPTARG}.key.pub"
;;
(K)
# public pubkey bucket
echo "$zssh_global_pubkeys/${ssh_node}"
;;
(c)
# private ssh hostconfig
echo "$zssh_private_configs/${ssh_node}.sshconf"
;;
(C)
# public config bucket
echo "$zssh_global_configs/${ssh_node}"
;;
(E)
# public config bucket piece
echo "$zssh_global_configs/${ssh_node}/${OPTARG}.sshconf"
;;
esac
done
}
function zssh_process() function zssh_process()
{ {
if [[ -n "$zssh_host" ]] if [[ -n "$zssh_host" ]]
@ -41,13 +89,14 @@ function zssh_process()
if [[ ${#zssh_host_config_accesses} -gt 0 ]] if [[ ${#zssh_host_config_accesses} -gt 0 ]]
then then
zbootstrap_message zssh "processing ssh server setup" zbootstrap_message zssh "processing ssh server setup"
if [[ "${HOME}/.config/zsh/local.config.zsh" -nt "${zssh_global_config_hostdir}" ]] if [[ "${HOME}/.config/zsh/local.config.zsh" -nt $(zssh_host_info -c) ]]
then then
zbootstrap_message zssh "publishing our configs …" zbootstrap_message zssh "publishing our configs …"
zssh_publish_configs zssh_publish_configs
else else
zbootstrap_message zssh "not publishing our configs" zbootstrap_message zssh "no need to publish our configs"
fi fi
zssh_check_pubkeys
fi fi
zbootstrap_message zssh "processing ssh client setup" zbootstrap_message zssh "processing ssh client setup"
zssh_install_peers zssh_install_peers
@ -55,6 +104,11 @@ function zssh_process()
fi fi
} }
function zssh_check_pubkeys()
{
[[ ${#zssh_host_config_accesses} -gt 0 ]] || return 62
}
function zssh_install_peers() function zssh_install_peers()
{ {
[[ -n $zssh_host ]] || return 63 [[ -n $zssh_host ]] || return 63
@ -79,23 +133,26 @@ function zssh_mail_pubkey2()
{ {
[[ -n $zssh_host ]] || return 63 [[ -n $zssh_host ]] || return 63
ssh_node="$1" ssh_node="$1"
local targetspool="$zssh_global_pubkeys/$ssh_node" ztools_ensure -d $(zssh_node_info ${ssh_node} -K)
local srcpk="$zssh_private_keys/$ssh_node.key.pub" if ! [[ $(zssh_node_info ${ssh_node} -k) -ot "$(zssh_node_info ${ssh_node} -K)/$zssh_host.key.pub" ]]
ztools_ensure -d "${targetspool}" then
cp -t "$targetspool" "$srcpk" zbootstrap_message zssh "sending '$(zssh_node_info ${ssh_node} -k) to '$(zssh_node_info ${ssh_node} -K ${zssh_host})'"
cp $(zssh_node_info ${ssh_node} -k) (zssh_node_info ${ssh_node} -K ${zssh_host})
else
zbootstrap_message zssh "'$(zssh_node_info ${ssh_node} -K ${zssh_host})' already mailed"
fi
} }
function zssh_publish_configs() function zssh_publish_configs()
{ {
[[ -n "$zssh_host_config_accesses" ]] || return 62 [[ "${#zssh_host_config_accesses}" -tf 0 ]] || return 62
for sshmatch in ${(k)zssh_host_config_accesses} for sshmatch in ${(k)zssh_host_config_accesses}
do do
hostaccessconfig_file="${zssh_global_config_hostdir}/${sshmatch}.sshconf" zbootstrap_message zssh "generating our server access config '$(zssh_host_info -E ${sshmatch})'" # '${hostaccessconfig_file}'"
zbootstrap_message zssh "generating our server access config '${hostaccessconfig_file}'" zssh_generate_hostaccessconfig $sshmatch > "$(zssh_host_info -E ${sshmatch})" # "$hostaccessconfig_file"
zssh_generate_hostaccessconfig $sshmatch > "$hostaccessconfig_file"
done done
zbootstrap_message zssh "updating mtime for ${zssh_global_config_hostdir}" zbootstrap_message zssh "updating mtime for $(zssh_host_info -C)"
touch "${zssh_global_config_hostdir}" touch "$(zssh_host_info -C)"
} }
function zssh_generate_hostaccessconfig() function zssh_generate_hostaccessconfig()