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.
PKG_HOST='seblu@white.seblu.net'
PKG_BASE='packages'
PKG_REGEX=''
ARCH_REGEX="($(uname -m)|any)"
SSH_OPTIONS=('-v' '-oStrictHostKeyChecking=no' '-oUserKnownHostsFile=/dev/null')
echo "usage: ${0##*/} [options] <list|get|install> [PKG_REGEX]" >&2
echo " -h: host address (current: $PKG_HOST)" >&2
echo " -b: base path (current: $PKG_BASE)" >&2
echo " -a: arch regex (current: $ARCH_REGEX)" >&2
sshinit() {
# default ssh program
SSH=ssh
SCP=scp
if [[ -n $SSH_AUTH_SOCK ]] && ssh-add -l &>/dev/null; then
# we using ssh-agent
true
elif type -P sshpass &>/dev/null; then
read -rs SSHPASS
echo
if [[ -z "$SSHPASS" ]]; then
echo 'Empty pass, sshpass not needed'
return
fi
export SSHPASS
SSH='sshpass -e ssh'
SCP='sshpass -e scp'
else
echo 'Nor ssh-agent, nor sshpass detected. You wil tap your pass more than once.'
fi
}
while getopts 'h:b:a:' opt; do
case $opt in
a) ARCH_REGEX=$OPTARG;;
b) PKG_BASE=$OPTARG;;
h) PKG_HOST=$OPTARG;;
*) usage;;
esac
done
shift $((OPTIND - 1));
(( $# >= 1 )) || usage
case $1 in
$SSH "${SSH_OPTIONS[@]}" "$PKG_HOST" \
"find '$PKG_BASE' -type f \
-regextype posix-egrep -regex '.*/$PKG_REGEX.*-$ARCH_REGEX.pkg\.tar\.xz'" \
</dev/null >"$list_tmp" 2>/dev/null
if (( $? != 0 )); then
echo 'Unable to list remote files. Check your password!'
exit 1
fi
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
;;
install)
(( EUID == 0 )) && pacman='pacman' || pacman='sudo pacman'
pkg_tmp=$(mktemp)
$SCP "${SSH_OPTIONS[@]}" "$PKG_HOST:$line" "$pkg_tmp" && $pacman -U "$pkg_tmp"