#!/bin/sh
#
# Convert a .zip file from github into .tar.gz
#
# 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.
#

zip="$1"
tgz="$2"

status=1
here=`pwd`
tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1
trap "rm -rf $tmp; exit \$status" 0 1 2 3 15

if [ -z "$zip" -o -z "$tgz" ]
then
	echo "Usage: $0 zipfile tgzfile"
	exit 1
fi

cd $tmp
unzip -q "$zip"
cd *
tar czf "$tgz" *
cd "$here"
echo "Wrote: $tgz"

status=0
exit
