deploypkg.zsh: Take a list of machines to install on

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2021-12-02 13:50:15 -05:00
parent 0ca7ac8d86
commit 54d5c4784c
4 changed files with 38 additions and 6 deletions

View File

@ -2,6 +2,7 @@ import termcolor
import re
import sys
prefix = sys.argv[1] if len(sys.argv) > 1 else None
pacman_colors = dict()
pacman_attrs = dict()
@ -13,9 +14,13 @@ add_color_attr("==>", "green", "bold")
add_color_attr("->", "blue", "bold")
for line in sys.stdin:
if prefix:
print(prefix, end=" ")
if "==>" in line or "->" in line:
for part in re.split(r'(\s+)', line):
color = pacman_colors.get(part, "white")
attrs = pacman_attrs.get(part, ["bold"])
termcolor.cprint(part, color, attrs=attrs, end="")
else:
print(line, end="")

14
colors/vm.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/python
import sys
import termcolor
VMs = sys.argv[1:]
pad = max([ len(vm) for vm in VMs ])
colors = [ "green", "yellow", "blue", "magenta", "cyan", "red", "grey", "white" ]
for i, vm in enumerate(sys.argv[1:]):
open = termcolor.colored("[", attrs=["bold"])
name = termcolor.colored(vm.rjust(pad), colors[i%len(colors)], attrs=["bold"])
close = termcolor.colored("]", attrs=["bold"])
print(f"{open}{name}{close}")

View File

@ -3,7 +3,7 @@
function _deploypkg.zsh() {
_arguments \
'1:package:_files -g "**/*.pkg.tar.*"' \
':destination: _alternative
'*:destination: _alternative
"hosts:hosts: _ssh_hosts"
"domains:domains:($(virsh list --all --name))"'
}

View File

@ -1,10 +1,23 @@
#!/bin/zsh
colors="/home/anna/bin/colors"
if [ "$#" -ne 2 ]; then
echo "Usage: $0 /path/to/package {libvirt VM}"
if [ "$#" -lt 2 ]; then
echo "Usage: $0 /path/to/package {remote host, ...}"
exit 1
fi
ssh.zsh $2 "mkdir -p pkg"
scp $1 $2:pkg/
ssh.zsh $2 "sudo pacman --noconfirm -U pkg/$(basename $1)" | python /home/anna/bin/colors/pacman.py
pkg=$(basename $1)
shift
function deploy_package() {
ssh.zsh $1 "mkdir -pv pkg" 2>&1 | sed -e "s/^/$2 /"
script -q -c "scp $pkg $1:pkg/ 2>&1" 2>&1 | sed -e "s/^/$2 /"
ssh.zsh $1 "sudo pacman --noconfirm -U pkg/$pkg" | python $colors/pacman.py $2
}
tags=($(python $colors/vm.py $*))
for ((i=1; i<=$#; i++)); do
deploy_package ${@[i]} ${tags[i]} &
done
wait $(jobs -pr)