#!/bin/bash # Copyright © Sébastien Luttringer # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. pkg_host='root@whooper.v.seblu.net' pkg_base='/root/packages' pkg_regex='' arch_regexp="($(uname -m)|any)" usage() { echo "usage: ${0##*/} [options] [pkg_regex]" >&2 echo 'options:' echo " -h: host address (current: $pkg_host)" echo " -b: base path (current: $pkg_base)" echo " -a: arch regex (current: $arch_regexp)" exit 1 } while getopts 'h:b:a:' opt; do case $opt in a) arch_regexp=$OPTARG;; b) pkg_base=$OPTARG;; h) pkg_host=$OPTARG;; *) usage;; esac done shift $((OPTIND - 1)); (( $# >= 1 )) || usage case $1 in list|get|install) action="$1";; *) usage;; esac pkg_regex="$2" list_tmp=$(mktemp) ssh "$pkg_host" \ "find '$pkg_base' -type f \ -regextype posix-egrep -regex '.*/$pkg_regex.*-$arch_regexp.pkg\.tar\.xz'" \ "$list_tmp" 2>/dev/null exec 3<>"$list_tmp" while read -u 3 -r line; do [[ $line ]] || continue case $action in list) echo "$line" ;; get) [[ -f $(basename $line) ]] && echo "==> $(basename $line): already exists. skipped!" && continue scp "$pkg_host:$line" . ;; install) (( EUID == 0 )) && pacman='pacman' || pacman='sudo pacman' pkg_tmp=$(mktemp) scp "$pkg_host:$line" "$pkg_tmp" && $pacman -U "$pkg_tmp" rm -f "$pkg_tmp" ;; esac done rm -f "$list_tmp" # vim:set ts=2 sw=2 ft=sh noet: