]> git.armaanb.net Git - asd-repo.git/blob - kiss-serv/files/kiss-send-build
kiss-serv: updates, bugfixes
[asd-repo.git] / kiss-serv / files / kiss-send-build
1 #!/usr/bin/sh -e
2
3 usage() {
4   echo 'Usage: kiss send-build [command] [options]
5 build KISS packages on a remote server
6
7 Options:
8   -h, --help    show this help message
9
10 Subcommands:
11   build [package]   initiate a remote build
12   status            get current remote status
13   get [package]     receive a built package
14
15 Configuration:
16   Done via environment variables
17
18   $KISS_SERV_HOST    remote host to connect to
19                        (defaults to localhost)
20   $KISS_SERV_USER    remote host to connect to
21                        (defaults to $(whoami))
22   $KISS_SERV_PORT    remote port to connect to
23                        (defaults to 22)'
24 }
25
26 parse_err() {
27   echo "$1"
28   $2
29   exit 2
30 }
31
32 sshexec() {
33   $sshcmd kiss serv $1 $2
34   exit
35 }
36
37 get() {
38   pkg=$($sshcmd 'ls -1 ~/.cache/kiss/bin/' | sort | grep -m 1 "$2")
39   rsync -azre "ssh -p $port" "$user@$host":/home/"$user"/.cache/kiss/bin/"$pkg" \
40     ~/.cache/kiss/bin
41   echo "fetched $pkg from $host"
42   exit
43 }
44
45 port=${KISS_SERV_PORT:-22}
46 host=${KISS_SERV_HOST:-localhost}
47 user=${KISS_SERV_USER:-$(whoami)}
48 sshcmd="ssh -p $port $user@$host env KISS_PATH=$KISS_PATH"
49
50 while [ "$1" != "" ]; do
51   case $1 in
52     -h | --help)
53       usage
54       exit
55       ;;
56     status | build)
57       sshexec "$@"
58       ;;
59     get)
60       get "$@"
61       ;;
62     *)
63       parse_err "ERROR: unknown option $1 \n" usage
64       ;;
65   esac
66   shift 2
67 done
68 parse_err "ERROR: no command given\n" usage