#! /bin/sh
#
# Copyright (c) 2015 Red Hat.
# 
# 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.
#
#
# This script can be used to launch various pcp containers. On the 'atomic'
# platform, the atomic command should be used (it will use the RUN label
# defined in the Dockerfile. e.g. "atomic run pcp-collector".  On other
# platforms, use this script or some variant thereof.
#
# This requires docker version 1.4 or later.
#
[ $# -lt 1 ] && echo Usage $0 "container-id [program [args ..]]" && exit 1

id=$1
shift

cmd=`docker inspect $id | awk -F\" '/\"RUN\"/ {print $4; exit}'`
[ -z "$cmd" ] && echo "Error: failed to extract the RUN label" && exit 1
$cmd $*
