From 8a73ed3a6177ea7c28e1d68a843722ffcf1962c5 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 29 Nov 2021 17:02:55 -0500 Subject: [PATCH] Create a deploypkg.zsh command For installing a package created through makepkg onto a remote machine Signed-off-by: Anna Schumaker --- colors/pacman.py | 21 +++++++++++++++++++++ completions/_deploypkg.zsh | 9 +++++++++ deploypkg.zsh | 10 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 colors/pacman.py create mode 100644 completions/_deploypkg.zsh create mode 100755 deploypkg.zsh diff --git a/colors/pacman.py b/colors/pacman.py new file mode 100644 index 0000000..c50be3a --- /dev/null +++ b/colors/pacman.py @@ -0,0 +1,21 @@ +import termcolor +import re +import sys + +pacman_colors = dict() +pacman_attrs = dict() + +def add_color_attr(field, color, *attrs): + pacman_colors[field] = color + pacman_attrs[field] = attrs + +add_color_attr("==>", "green", "bold") +add_color_attr("->", "blue", "bold") + +for line in sys.stdin: + 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="") diff --git a/completions/_deploypkg.zsh b/completions/_deploypkg.zsh new file mode 100644 index 0000000..2aeb850 --- /dev/null +++ b/completions/_deploypkg.zsh @@ -0,0 +1,9 @@ +#compdef deploypkg.zsh + +function _deploypkg.zsh() { + _arguments \ + '1:package:_files -g "**/*.pkg.tar.*"' \ + ':destination: _alternative + "hosts:hosts: _ssh_hosts" + "domains:domains:($(virsh list --all --name))"' +} diff --git a/deploypkg.zsh b/deploypkg.zsh new file mode 100755 index 0000000..41300e4 --- /dev/null +++ b/deploypkg.zsh @@ -0,0 +1,10 @@ +#!/bin/zsh + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 /path/to/package {libvirt VM}" + 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