Newer
Older
# 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.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pkg_host='root@whooper.v.seblu.net'
pkg_base='/root/packages'
pkg_regex=''
arch_regexp="($(uname -m)|any)"
usage() {
echo "usage: ${0##*/} <list|get|install> [pkg_regex] [arch_regexp] [pkg_base] [pkg_host]" >&2
echo 'default:'
echo " pkg_host: $pkg_host"
echo " pkg_regex: $pkg_regex"
echo " pkg_base: $pkg_base"
echo " arch_regex: $arch_regexp"
exit 1
}
(( $# >= 1 )) || usage
case $1 in
list|get|install) action="$1";;
*) usage;;
esac
[[ -n "$2" ]] && pkg_regex=$2
[[ -n "$3" ]] && arch_regexp=$3
[[ -n "$4" ]] && pkg_base=$4
[[ -n "$5" ]] && pkg_host=$5
list_tmp=$(mktemp)
ssh "$pkg_host" \
"find '$pkg_base' -type f \
-regextype posix-egrep -regex '.*/$pkg_regex.*-$arch_regexp.pkg\.tar\.xz'" \
</dev/null >"$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: