rename funtion zbootstrap_message to zshlibs_log

This commit is contained in:
accel 2022-01-11 17:35:56 +03:00
parent bd50b0f33d
commit 3e308a76aa
2 changed files with 52 additions and 52 deletions

View File

@ -17,16 +17,16 @@ fi
function zshlibs_update() function zshlibs_update()
{ {
zbootstrap_message zlibs_update "preparing self update …" zshlibs_log zlibs_update "preparing self update …"
if [[ -n "$zshlibs_install" ]] if [[ -n "$zshlibs_install" ]]
then then
zbootstrap_message zlibs_update "cd into '$zshlibs_install' …" zshlibs_log zlibs_update "cd into '$zshlibs_install' …"
pushd $zshlibs_install 2>&1 > /dev/null pushd $zshlibs_install 2>&1 > /dev/null
zbootstrap_message zlibs_update "git pull …" zshlibs_log zlibs_update "git pull …"
( (
git pull 2>&1 |zbootstrap_message zlibs_update & # > "${HOME}/.log/z_zshlibs_update" & git pull 2>&1 |zshlibs_log zlibs_update & # > "${HOME}/.log/z_zshlibs_update" &
) )
zbootstrap_message zlibs_update "update done" zshlibs_log zlibs_update "update done"
popd 2>&1 > /dev/null popd 2>&1 > /dev/null
else else
echo "\$zshlibs_install not set!" echo "\$zshlibs_install not set!"
@ -41,25 +41,25 @@ function ztools_ensure()
typ=${1} typ=${1}
if ! test -e ${target} if ! test -e ${target}
then then
zbootstrap_message ztools_ensure "creating '${target}' ($typ) …" zshlibs_log ztools_ensure "creating '${target}' ($typ) …"
case $typ in case $typ in
-d) -d)
mkdir -p ${target} \ mkdir -p ${target} \
|| zbootstrap_message ztools_ensure "unable to create directory '${target}'" \ || zshlibs_log ztools_ensure "unable to create directory '${target}'" \
&& return 2 && return 2
;; ;;
-f) -f)
touch ${target} \ touch ${target} \
|| zbootstrap_message ztools_ensure "unable to create file '${target}'" \ || zshlibs_log ztools_ensure "unable to create file '${target}'" \
&& return 2 && return 2
esac esac
zbootstrap_message ztools_ensure "target '${target}' created" zshlibs_log ztools_ensure "target '${target}' created"
elif test ${typ} ${target} elif test ${typ} ${target}
then then
zbootstrap_message ztools_ensure "target '${target}' ($typ) present" zshlibs_log ztools_ensure "target '${target}' ($typ) present"
return 0 return 0
else else
zbootstrap_message ztools_ensure "target '${target}' already exists and it is not a directory" zshlibs_log ztools_ensure "target '${target}' already exists and it is not a directory"
return 1 return 1
fi fi
} }
@ -99,12 +99,12 @@ function zconfig_checkload()
typeset -a -g zconfig_loaded typeset -a -g zconfig_loaded
if [[ ! ${zconfig_loaded[(r)${1}]} ]] if [[ ! ${zconfig_loaded[(r)${1}]} ]]
then then
zbootstrap_message zbootstrap "sourcing config '$1'" zshlibs_log zbootstrap "sourcing config '$1'"
. -- $1 2>&1 >(zbootstrap_message zbootstrap) # >> "${HOME}/.log/z_zbootstrap.log" . -- $1 2>&1 >(zshlibs_log zbootstrap) # >> "${HOME}/.log/z_zbootstrap.log"
zconfig_loaded+=("$1") zconfig_loaded+=("$1")
zbootstrap_message zbootstrap "end sourcing config '$1'" zshlibs_log zbootstrap "end sourcing config '$1'"
else else
zbootstrap_message zbootstrap "config '$1' already loaded" zshlibs_log zbootstrap "config '$1' already loaded"
fi fi
} }
@ -131,7 +131,7 @@ function zconfigs_local_load()
fi fi
} }
function zbootstrap_message() function zshlibs_log()
{ {
local facility=$1 local facility=$1
shift shift
@ -146,7 +146,7 @@ function zbootstrap_message()
function zshlibs_boot() function zshlibs_boot()
{ {
# ensure log directory # ensure log directory
zbootstrap_message zbootstrap "ensure directory '${HOME}/.log/'" zshlibs_log zbootstrap "ensure directory '${HOME}/.log/'"
ztools_ensure -d "${HOME}/.log/" ztools_ensure -d "${HOME}/.log/"
# loading configs # loading configs
typeset -a -g zconfig_loaded typeset -a -g zconfig_loaded
@ -158,20 +158,20 @@ function zshlibs_boot()
function zbootstrap_noninteractive() function zbootstrap_noninteractive()
{ {
zbootstrap_message zbootstrap 'load global config' zshlibs_log zbootstrap 'load global config'
zconfig_checkload ${zconfig_shared_path}/global.config.zsh zconfig_checkload ${zconfig_shared_path}/global.config.zsh
zbootstrap_message zbootstrap 'load local configs' zshlibs_log zbootstrap 'load local configs'
zconfigs_local_load zconfigs_local_load
for zconfig in $config_extra; do for zconfig in $config_extra; do
zbootstrap_message zbootstrap 'load config extra $zconfig' zshlibs_log zbootstrap 'load config extra $zconfig'
zconfig_checkload ${zconfig_shared_path}/${zconfig}.config.zsh zconfig_checkload ${zconfig_shared_path}/${zconfig}.config.zsh
done done
# expanding settings # expanding settings
zbootstrap_message zbootstrap "expanding path with '$path_extra'" zshlibs_log zbootstrap "expanding path with '$path_extra'"
global_path_expand $path_extra global_path_expand $path_extra
zbootstrap_message zbootstrap "expanding fpath with '$fpath_extra'" zshlibs_log zbootstrap "expanding fpath with '$fpath_extra'"
global_fpath_expand vanilla global_fpath_expand vanilla
zbootstrap_message zbootstrap "done loading noninteractive config" zshlibs_log zbootstrap "done loading noninteractive config"
} }
function zbootstrap () function zbootstrap ()
@ -180,5 +180,5 @@ function zbootstrap ()
zbootstrap_noninteractive zbootstrap_noninteractive
zconfig_checkload ${zconfig_shared_path}/global.style.zsh zconfig_checkload ${zconfig_shared_path}/global.style.zsh
zshlibs_update zshlibs_update
zbootstrap_message zbootstrap "done loading interactive config" zshlibs_log zbootstrap "done loading interactive config"
} }

View File

@ -1,6 +1,6 @@
function zssh_boot() function zssh_boot()
{ {
zbootstrap_message zssh "zssh is booting up ----------------------------" zshlibs_log 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"
@ -14,7 +14,7 @@ function zssh_configure ()
{ {
if [[ -n "$zssh_host" ]] if [[ -n "$zssh_host" ]]
then then
zbootstrap_message zssh "zssh_host is set" zshlibs_log zssh "zssh_host is set"
ztools_ensure -d $zssh_private_keys ztools_ensure -d $zssh_private_keys
ztools_ensure -d $zssh_private_configs ztools_ensure -d $zssh_private_configs
ztools_ensure -d ${zssh_global_configs} ztools_ensure -d ${zssh_global_configs}
@ -22,18 +22,18 @@ function zssh_configure ()
zssh_enumeratenodes zssh_enumeratenodes
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" zshlibs_log zssh "zssh_host_config_accesses is set"
zbootstrap_message zssh "global our pubkey directory is $(zssh_host_info -K)" zshlibs_log zssh "global our pubkey directory is $(zssh_host_info -K)"
zbootstrap_message zssh "global our config directory is $(zssh_host_info -c)" zshlibs_log 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_host_info -K) #"${zssh_global_pubkey_hostdir}" ztools_ensure -d $(zssh_host_info -K) #"${zssh_global_pubkey_hostdir}"
ztools_ensure -d $(zssh_host_info -C) # "${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" zshlibs_log zssh "zssh_host_config_accesses is NOT set, not going to bother accepting keys"
fi fi
else else
zbootstrap_message zssh "zssh_host is NOT set, which means we cannot neither publish keys nor accept them" zshlibs_log zssh "zssh_host is NOT set, which means we cannot neither publish keys nor accept them"
fi fi
} }
@ -88,17 +88,17 @@ function zssh_process()
then then
if [[ ${#zssh_host_config_accesses} -gt 0 ]] if [[ ${#zssh_host_config_accesses} -gt 0 ]]
then then
zbootstrap_message zssh "processing ssh server setup" zshlibs_log zssh "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
zbootstrap_message zssh "publishing our configs …" zshlibs_log zssh "publishing our configs …"
zssh_publish_configs zssh_publish_configs
else else
zbootstrap_message zssh "no need to publish our configs" zshlibs_log zssh "no need to publish our configs"
fi fi
zssh_check_pubkeys zssh_check_pubkeys
fi fi
zbootstrap_message zssh "processing ssh client setup" zshlibs_log zssh "processing ssh client setup"
zssh_install_peers zssh_install_peers
zssh_publish_pubkeys zssh_publish_pubkeys
fi fi
@ -112,10 +112,10 @@ function zssh_check_pubkeys()
function zssh_install_peers() function zssh_install_peers()
{ {
[[ -n $zssh_host ]] || return 63 [[ -n $zssh_host ]] || return 63
zbootstrap_message zssh "installing peers" zshlibs_log zssh "installing peers"
for ssh_node in $zssh_nodes for ssh_node in $zssh_nodes
do do
zbootstrap_message zssh "installing peer $ssh_node" zshlibs_log zssh "installing peer $ssh_node"
zssh_generate_privkey4 $ssh_node zssh_generate_privkey4 $ssh_node
zssh_generate_config4 $ssh_node zssh_generate_config4 $ssh_node
done done
@ -136,10 +136,10 @@ 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
ztools_ensure -d $(zssh_node_info ${ssh_node} -K) ztools_ensure -d $(zssh_node_info ${ssh_node} -K)
zbootstrap_message zssh "sending '$(zssh_node_info ${ssh_node} -k) to '$(zssh_node_info ${ssh_node} -K ${zssh_host})'" zshlibs_log 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}) cp $(zssh_node_info ${ssh_node} -k) (zssh_node_info ${ssh_node} -K ${zssh_host})
else else
zbootstrap_message zssh "'$(zssh_node_info ${ssh_node} -K ${zssh_host})' already mailed" zshlibs_log zssh "'$(zssh_node_info ${ssh_node} -K ${zssh_host})' already mailed"
fi fi
} }
@ -148,10 +148,10 @@ function zssh_publish_configs()
[[ "${#zssh_host_config_accesses}" -gt 0 ]] || return 62 [[ "${#zssh_host_config_accesses}" -gt 0 ]] || return 62
for sshmatch in ${(k)zssh_host_config_accesses} for sshmatch in ${(k)zssh_host_config_accesses}
do do
zbootstrap_message zssh "generating our server access config '$(zssh_host_info -E ${sshmatch})'" # '${hostaccessconfig_file}'" zshlibs_log zssh "generating our server access config '$(zssh_host_info -E ${sshmatch})'" # '${hostaccessconfig_file}'"
zssh_generate_hostaccessconfig $sshmatch > "$(zssh_host_info -E ${sshmatch})" # "$hostaccessconfig_file" zssh_generate_hostaccessconfig $sshmatch > "$(zssh_host_info -E ${sshmatch})" # "$hostaccessconfig_file"
done done
zbootstrap_message zssh "updating mtime for $(zssh_host_info -C)" zshlibs_log zssh "updating mtime for $(zssh_host_info -C)"
touch "$(zssh_host_info -C)" touch "$(zssh_host_info -C)"
} }
@ -177,36 +177,36 @@ 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"
zbootstrap_message zssh "checking configs for $ssh_node" zshlibs_log zssh "checking configs for $ssh_node"
if [[ -d "$srcs" ]] && ! [[ $dst -nt $srcs ]] if [[ -d "$srcs" ]] && ! [[ $dst -nt $srcs ]]
then then
sshkey="$zssh_private_keys/$ssh_node.key" sshkey="$zssh_private_keys/$ssh_node.key"
zbootstrap_message zssh "found fresh configs directory for $ssh_node" zshlibs_log zssh "found fresh configs directory for $ssh_node"
zbootstrap_message zssh "config destination is '$dst'" zshlibs_log zssh "config destination is '$dst'"
zbootstrap_message zssh "tied ssh key is '$sshkey'" 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
zbootstrap_message zssh "sourcing $src" zshlibs_log zssh "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
zbootstrap_message zssh "done with $ssh_node" zshlibs_log zssh "done with $ssh_node"
} }
function zssh_generate_privkey4 function zssh_generate_privkey4
{ {
ssh_node="$1" ssh_node="$1"
zbootstrap_message zssh "checking keys for peer $ssh_node" zshlibs_log zssh "checking keys for peer $ssh_node"
local newkey=$zssh_private_keys/$ssh_node.key local newkey=$zssh_private_keys/$ssh_node.key
if ! [[ -s $newkey ]] if ! [[ -s $newkey ]]
then then
zbootstrap_message zssh "generate key for $ssh_node" zshlibs_log zssh "generate key for $ssh_node"
ssh-keygen -t ed25519 -N '' -C "$ssh_host($USER@$HOST) for $ssh_node" -f $newkey >> "${HOME}/.log/ssh-keygen.log" ssh-keygen -t ed25519 -N '' -C "$ssh_host($USER@$HOST) for $ssh_node" -f $newkey >> "${HOME}/.log/ssh-keygen.log"
if [[ "$ssh_node" == "$zssh_host" ]] if [[ "$ssh_node" == "$zssh_host" ]]
then then
zbootstrap_message zssh "Self accepting key: $ssh_node" zshlibs_log zssh "Self accepting key: $ssh_node"
cat "$newkey.pub" >> ${HOME}/.ssh/authorized_keys cat "$newkey.pub" >> ${HOME}/.ssh/authorized_keys
fi fi
fi fi
@ -216,7 +216,7 @@ function zssh_generate_privkey4
function zssh_enumeratenodes() function zssh_enumeratenodes()
{ {
typeset -g -a zssh_nodes; typeset -g -a zssh_nodes;
zbootstrap_message zssh "enumerating nodes" zshlibs_log zssh "enumerating nodes"
if [[ -d $zssh_global_configs ]] if [[ -d $zssh_global_configs ]]
then then
for __ssh_node in ${zssh_global_configs}/*(/) for __ssh_node in ${zssh_global_configs}/*(/)
@ -224,5 +224,5 @@ function zssh_enumeratenodes()
zssh_nodes+=($(basename $__ssh_node)) zssh_nodes+=($(basename $__ssh_node))
done done
fi fi
zbootstrap_message zssh "got ${#zssh_nodes} nodes" zshlibs_log zssh "got ${#zssh_nodes} nodes"
} }