From 4966fded3d36d3388e7b23981ad9e923febe9874 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 16 Mar 2021 20:59:43 +0100 Subject: [PATCH] new: [0km] add ``vps-{space,update,mux}`` commands. Signed-off-by: Valentin Lab --- bin/0km | 130 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 106 insertions(+), 24 deletions(-) diff --git a/bin/0km b/bin/0km index dc3d343..c15bed0 100755 --- a/bin/0km +++ b/bin/0km @@ -165,7 +165,7 @@ ssh:run() { -o ControlMaster=auto -o ControlPersist=900 \ -o "StrictHostKeyChecking=no" \ "$hostname" "${ssh_options[@]}" -- "${cmd[@]}" - } 3>&1 1>&2 2>&3 | sed -r "s/^/$DARKCYAN$hostname$NORMAL $DARKRED\!$NORMAL /g" + } 3>&1 1>&2 2>&3 ## | sed -r "s/^/$DARKCYAN$hostname$NORMAL $DARKRED\!$NORMAL /g" set_errlvl "${PIPESTATUS[0]}" } 3>&1 1>&2 2>&3 } @@ -195,26 +195,87 @@ is_ovh_hostname() { return 1 } -vps_check() { +vps_connection_check() { local vps="$1" ip=$(resolve "$vps") || - { echo "no-resolve"; return; } + { echo "${DARKRED}no-resolve${NORMAL}"; return 1; } - ping -c 1 -w 1 "$ip" >/dev/null 2>&1 || - { echo "no-ping"; } - is-port-open "$ip" "22" || - { echo "no-port-22-open"; return; } + is-port-open "$ip" "22" /dev/null 2>&1 || - { echo "no-ssh-root-access"; return; } + { echo "${DARKRED}no-ssh-root-access${NORMAL}"; return 1; } +} + +vps_check() { + local vps="$1" + vps_connection_check "$vps" /dev/null 2>&1 || - { echo "no-backup"; return; } + { echo "${DARKRED}no-backup${NORMAL}"; return; } } +vps_udpate() { + local vps="$1" + vps_connection_check "$vps" || return 1 + ssh:run "root@$vps" -- myc-update &1 1>&2 2>&3 | sed -r "s/^/$DARKCYAN$label$NORMAL $DARKRED\!$NORMAL /g" + set_errlvl "${PIPESTATUS[0]}" + } 3>&1 1>&2 2>&3 | sed -r "s/^/$DARKCYAN$label$NORMAL $DARKGRAY\|$NORMAL /g" + set_errlvl "${PIPESTATUS[0]}" + ) & + done + wait +} + [ "$SOURCED" ] && return 0 @@ -367,21 +428,42 @@ cmdline.spec::cmd:vps-check:run() { : :posarg: [VPS...] 'Target host to check' - VPS=($(printf "%s\n" "${VPS[@]}" | sort)) - declare -A vps_done; - for vps in "${VPS[@]}"; do - [ "${vps_done[$vps]}" ] && { - warn "duplicate vps '$vps' provided. Ignoring." - continue - } - vps_done[$vps]=1 - ( - vps_check "$vps" 2>&1 | sed "s/^/$vps: /g" - [ "${PIPESTATUS[0]}" == 0 ] - ) & - done - wait + + echo "" | + vps_mux vps_check "${VPS[@]}" +} + + +cmdline.spec.gnu vps-update + +cmdline.spec::cmd:vps-update:run() { + + : :posarg: [VPS...] 'Target host to check' + + echo "" | + vps_mux vps_update "${VPS[@]}" } +cmdline.spec.gnu vps-mux +cmdline.spec::cmd:vps-mux:run() { + + : :posarg: [VPS...] 'Target host to check' + + cat | vps_mux vps_bash "${VPS[@]}" +} + + +cmdline.spec.gnu vps-space +cmdline.spec::cmd:vps-space:run() { + + : :posarg: [VPS...] 'Target host to check' + + echo "df /srv -h | tail -n +2 | sed -r 's/ +/ /g' | cut -f 2-5 -d ' '" | + vps_mux vps_bash "${VPS[@]}" +} + + + + cmdline::parse "$@"