+#!/usr/bin/sh -e
+
+usage() {
+ echo 'Usage: kiss send-build [command] [options]
+build KISS packages on a remote server
+
+Options:
+ -h, --help show this help message
+
+Subcommands:
+ build [package] initiate a remote build
+ status get current remote status
+ get [package] receive a built package
+
+Configuration:
+ Done via environment variables
+
+ $KISS_SERV_HOST remote host to connect to
+ (defaults to localhost)
+ $KISS_SERV_USER remote host to connect to
+ (defaults to $(whoami))
+ $KISS_SERV_PORT remote port to connect to
+ (defaults to 22)'
+}
+
+parse_err() {
+ echo "$1"
+ $2
+ exit 2
+}
+
+sshexec() {
+ $sshcmd kiss serv $1 $2
+ exit
+}
+
+get() {
+ contents=$sshcmd 'ls -1 ~/.cache/kiss/bin/'
+ pkg=$(echo $contents | sort | grep -m 1 "$2")
+ rsync -azre "ssh -p $sshcmd" "$user"@"$host":/home/"$user"/.cache/kiss/bin/"$pkg" \
+ ~/.cache/kiss/bin
+}
+
+port=${KISS_SERV_PORT:-22}
+host=${KISS_SERV_HOST:-localhost}
+user=${KISS_SERV_USER:-$(whoami)}
+sshcmd="ssh -p $port $user@$host"
+
+while [ "$1" != "" ]; do
+ case $1 in
+ -h | --help)
+ usage
+ exit
+ ;;
+ build)
+ build "$@"
+ ;;
+ status | get)
+ sshexec "$@"
+ ;;
+ get)
+ get "$@"
+ ;;
+ *)
+ parse_err "ERROR: unknown option $1 \n" usage
+ ;;
+ esac
+ shift 2
+done
+parse_err "ERROR: no command given\n" usage