From 2125b497161c10e283fa4f1e7cdfe49288dfe4cd Mon Sep 17 00:00:00 2001 From: accel Date: Mon, 22 Nov 2021 18:41:59 +0300 Subject: [PATCH] update zssh --- zssh.funcs.zsh | 85 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/zssh.funcs.zsh b/zssh.funcs.zsh index a4b0386..2fb922a 100644 --- a/zssh.funcs.zsh +++ b/zssh.funcs.zsh @@ -1,5 +1,6 @@ function zssh_boot() { + zbootstrap_message zssh "zssh is booting up ----------------------------" typeset -g zssh_ssh_dotdir="${HOME}/.ssh" typeset -g zssh_private_keys="${zssh_ssh_dotdir}/keystore" typeset -g zssh_private_configs="${zssh_ssh_dotdir}/config.d" @@ -22,10 +23,12 @@ function zssh_configure () if [[ ${#zssh_host_config_accesses} -gt 0 ]] then 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_pubkey_hostdir="${zssh_global_pubkeys}/${zssh_host}" - ztools_ensure -d "${zssh_global_pubkey_hostdir}" - ztools_ensure -d "${zssh_global_config_hostdir}" + ztools_ensure -d $(zssh_host_info -K) #"${zssh_global_pubkey_hostdir}" + ztools_ensure -d $(zssh_host_info -C) # "${zssh_global_config_hostdir}" else zbootstrap_message zssh "zssh_host_config_accesses is NOT set, not going to bother accepting keys" fi @@ -34,6 +37,51 @@ function zssh_configure () 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() { if [[ -n "$zssh_host" ]] @@ -41,13 +89,14 @@ function zssh_process() if [[ ${#zssh_host_config_accesses} -gt 0 ]] then 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 zbootstrap_message zssh "publishing our configs …" zssh_publish_configs else - zbootstrap_message zssh "not publishing our configs …" + zbootstrap_message zssh "no need to publish our configs" fi + zssh_check_pubkeys fi zbootstrap_message zssh "processing ssh client setup" zssh_install_peers @@ -55,6 +104,11 @@ function zssh_process() fi } +function zssh_check_pubkeys() +{ + [[ ${#zssh_host_config_accesses} -gt 0 ]] || return 62 +} + function zssh_install_peers() { [[ -n $zssh_host ]] || return 63 @@ -79,23 +133,26 @@ function zssh_mail_pubkey2() { [[ -n $zssh_host ]] || return 63 ssh_node="$1" - local targetspool="$zssh_global_pubkeys/$ssh_node" - local srcpk="$zssh_private_keys/$ssh_node.key.pub" - ztools_ensure -d "${targetspool}" - cp -t "$targetspool" "$srcpk" + ztools_ensure -d $(zssh_node_info ${ssh_node} -K) + if ! [[ $(zssh_node_info ${ssh_node} -k) -ot "$(zssh_node_info ${ssh_node} -K)/$zssh_host.key.pub" ]] + then + 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() { - [[ -n "$zssh_host_config_accesses" ]] || return 62 + [[ "${#zssh_host_config_accesses}" -tf 0 ]] || return 62 for sshmatch in ${(k)zssh_host_config_accesses} do - hostaccessconfig_file="${zssh_global_config_hostdir}/${sshmatch}.sshconf" - zbootstrap_message zssh "generating our server access config '${hostaccessconfig_file}'" - zssh_generate_hostaccessconfig $sshmatch > "$hostaccessconfig_file" + zbootstrap_message zssh "generating our server access config '$(zssh_host_info -E ${sshmatch})'" # '${hostaccessconfig_file}'" + zssh_generate_hostaccessconfig $sshmatch > "$(zssh_host_info -E ${sshmatch})" # "$hostaccessconfig_file" done - zbootstrap_message zssh "updating mtime for ${zssh_global_config_hostdir}" - touch "${zssh_global_config_hostdir}" + zbootstrap_message zssh "updating mtime for $(zssh_host_info -C)" + touch "$(zssh_host_info -C)" } function zssh_generate_hostaccessconfig()