This commit is contained in:
accel 2022-01-11 21:17:16 +03:00
parent a912b4a00a
commit e994994c38

View File

@ -14,7 +14,7 @@ function zssh_configure ()
{ {
if [[ -n "$zssh_host" ]] if [[ -n "$zssh_host" ]]
then then
zshlibs_log zssh "zssh_host is set" zshlibs_log zssh_configure "zssh_host is set"
zshlibs_ensure -d $zssh_private_keys zshlibs_ensure -d $zssh_private_keys
zshlibs_ensure -d $zssh_private_configs zshlibs_ensure -d $zssh_private_configs
zshlibs_ensure -d ${zssh_global_configs} zshlibs_ensure -d ${zssh_global_configs}
@ -22,24 +22,23 @@ function zssh_configure ()
zssh_enumeratenodes zssh_enumeratenodes
if [[ ${#zssh_host_config_accesses} -gt 0 ]] if [[ ${#zssh_host_config_accesses} -gt 0 ]]
then then
zshlibs_log zssh "zssh_host_config_accesses is set" zshlibs_log zssh_configure "zssh_host_config_accesses is set"
zshlibs_log zssh "global our pubkey directory is $(zssh_host_info -K)" zshlibs_log zssh_configure "global our pubkey directory is $(zssh_host_info -K)"
zshlibs_log zssh "global our config directory is $(zssh_host_info -c)" zshlibs_log zssh_configure "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}"
zshlibs_ensure -d $(zssh_host_info -K) #"${zssh_global_pubkey_hostdir}" zshlibs_ensure -d $(zssh_host_info -K) #"${zssh_global_pubkey_hostdir}"
zshlibs_ensure -d $(zssh_host_info -C) # "${zssh_global_config_hostdir}" zshlibs_ensure -d $(zssh_host_info -C) # "${zssh_global_config_hostdir}"
else else
zshlibs_log zssh "zssh_host_config_accesses is NOT set, not going to bother accepting keys" zshlibs_log zssh_configure "zssh_host_config_accesses is NOT set, not going to bother accepting keys"
fi fi
else else
zshlibs_log zssh "zssh_host is NOT set, which means we cannot neither publish keys nor accept them" zshlibs_log zssh_configure "zssh_host is NOT set, which means we cannot neither publish keys nor accept them"
fi fi
} }
function zssh_host_info() function zssh_host_info()
{ {
local=ssh_node=${zssh_host}
zssh_node_info ${zssh_host} $@ zssh_node_info ${zssh_host} $@
} }
@ -88,17 +87,17 @@ function zssh_process()
then then
if [[ ${#zssh_host_config_accesses} -gt 0 ]] if [[ ${#zssh_host_config_accesses} -gt 0 ]]
then then
zshlibs_log zssh "processing ssh server setup" zshlibs_log zssh_server "processing ssh server setup"
if [[ "${HOME}/.config/zsh/local.config.zsh" -nt $(zssh_host_info -c) ]] if [[ "${HOME}/.config/zsh/local.config.zsh" -nt $(zssh_host_info -c) ]]
then then
zshlibs_log zssh "publishing our configs …" zshlibs_log zssh_server "publishing our configs …"
zssh_publish_configs zssh_publish_configs
else else
zshlibs_log zssh "no need to publish our configs" zshlibs_log zssh_server "no need to publish our configs"
fi fi
zssh_check_pubkeys zssh_check_pubkeys
fi fi
zshlibs_log zssh "processing ssh client setup" zshlibs_log zssh_client "processing ssh client setup"
zssh_install_peers zssh_install_peers
zssh_publish_pubkeys zssh_publish_pubkeys
fi fi
@ -107,6 +106,8 @@ function zssh_process()
function zssh_check_pubkeys() function zssh_check_pubkeys()
{ {
[[ ${#zssh_host_config_accesses} -gt 0 ]] || return 62 [[ ${#zssh_host_config_accesses} -gt 0 ]] || return 62
zshlibs_log zssh_server "checking received pubkeys …"
zshlibs_log zssh_server "done checking received pubkeys"
} }
function zssh_install_peers() function zssh_install_peers()
@ -123,10 +124,12 @@ function zssh_install_peers()
function zssh_publish_pubkeys() function zssh_publish_pubkeys()
{ {
zshlibs_log zssh_client "pushing out pubkey to parties …"
for ssh_node in $zssh_nodes for ssh_node in $zssh_nodes
do do
zssh_mail_pubkey2 $ssh_node zssh_mail_pubkey2 $ssh_node
done done
zshlibs_log zssh_client "done pushing out pubkey to parties"
} }
function zssh_mail_pubkey2() function zssh_mail_pubkey2()
@ -136,23 +139,25 @@ function zssh_mail_pubkey2()
if ! [[ $(zssh_node_info ${ssh_node} -k) -ot "$(zssh_node_info ${ssh_node} -K)/$zssh_host.key.pub" ]] if ! [[ $(zssh_node_info ${ssh_node} -k) -ot "$(zssh_node_info ${ssh_node} -K)/$zssh_host.key.pub" ]]
then then
zshlibs_ensure -d $(zssh_node_info ${ssh_node} -K) zshlibs_ensure -d $(zssh_node_info ${ssh_node} -K)
zshlibs_log zssh "sending '$(zssh_node_info ${ssh_node} -k) to '$(zssh_node_info ${ssh_node} -K ${zssh_host})'" zshlibs_log zssh_client "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}) cp $(zssh_node_info ${ssh_node} -k) (zssh_node_info ${ssh_node} -K ${zssh_host})
else else
zshlibs_log zssh "'$(zssh_node_info ${ssh_node} -K ${zssh_host})' already mailed" zshlibs_log zssh_client "'$(zssh_node_info ${ssh_node} -K ${zssh_host})' already mailed"
fi fi
} }
function zssh_publish_configs() function zssh_publish_configs()
{ {
[[ "${#zssh_host_config_accesses}" -gt 0 ]] || return 62 [[ "${#zssh_host_config_accesses}" -gt 0 ]] || return 62
zshlibs_log zssh_server "generating access configs for parties …"
for sshmatch in ${(k)zssh_host_config_accesses} for sshmatch in ${(k)zssh_host_config_accesses}
do do
zshlibs_log zssh "generating our server access config '$(zssh_host_info -E ${sshmatch})'" # '${hostaccessconfig_file}'" zshlibs_log zssh_server "generating our server access config '$(zssh_host_info -E ${sshmatch})'"
zssh_generate_hostaccessconfig $sshmatch > "$(zssh_host_info -E ${sshmatch})" # "$hostaccessconfig_file" zssh_generate_hostaccessconfig $sshmatch > "$(zssh_host_info -E ${sshmatch})"
done done
zshlibs_log zssh "updating mtime for $(zssh_host_info -C)" zshlibs_log zssh_server "updating mtime for $(zssh_host_info -C)"
touch "$(zssh_host_info -C)" touch "$(zssh_host_info -C)"
zshlibs_log zssh_server "done generating access configs for parties"
} }
function zssh_generate_hostaccessconfig() function zssh_generate_hostaccessconfig()
@ -177,22 +182,23 @@ function zssh_generate_config4
ssh_node="$1" ssh_node="$1"
dst="$zssh_private_configs/$ssh_node.sshconf" dst="$zssh_private_configs/$ssh_node.sshconf"
srcs="$zssh_global_configs/$ssh_node" srcs="$zssh_global_configs/$ssh_node"
zshlibs_log zssh "checking configs for $ssh_node" zshlibs_log zssh_client "checking configs for $ssh_node"
if [[ -d "$srcs" ]] && ! [[ $dst -nt $srcs ]] if ! [[ -d "$srcs" ]]
then
zshlibs_log zssh_client "$ssh_node does not have config"
elif ! [[ $dst -nt $srcs ]]
then then
sshkey="$zssh_private_keys/$ssh_node.key" sshkey="$zssh_private_keys/$ssh_node.key"
zshlibs_log zssh "found fresh configs directory for $ssh_node" zshlibs_log zssh_client "generating '$dst' with key '$sshkey'"
zshlibs_log zssh "config destination is '$dst'"
zshlibs_log zssh "tied ssh key is '$sshkey'"
rm "$dst" 2> /dev/null rm "$dst" 2> /dev/null
for src in "$srcs"/*.sshconf(N) for src in "$srcs"/*.sshconf(N)
do do
zshlibs_log zssh "sourcing $src" zshlibs_log zssh_client "sourcing $src"
cat "$src" >> "$dst" cat "$src" >> "$dst"
printf "\n IdentityFile %s\n\n" "$sshkey" >> "$dst" printf "\n IdentityFile %s\n\n" "$sshkey" >> "$dst"
done done
fi fi
zshlibs_log zssh "done with $ssh_node" zshlibs_log zssh_client "done with $ssh_node"
} }
function zssh_generate_privkey4 function zssh_generate_privkey4