diff --git a/colors/pacman.py b/colors/pacman.py index c50be3a..d39718b 100644 --- a/colors/pacman.py +++ b/colors/pacman.py @@ -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="") diff --git a/colors/vm.py b/colors/vm.py new file mode 100644 index 0000000..e0ca2b7 --- /dev/null +++ b/colors/vm.py @@ -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}") diff --git a/completions/_deploypkg.zsh b/completions/_deploypkg.zsh index 2aeb850..2a28b10 100644 --- a/completions/_deploypkg.zsh +++ b/completions/_deploypkg.zsh @@ -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))"' } diff --git a/deploypkg.zsh b/deploypkg.zsh index 41300e4..6fd1378 100755 --- a/deploypkg.zsh +++ b/deploypkg.zsh @@ -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)