#!/bin/bash -e

if [ $# -ne 2 ]; then
	echo "Usage: $0 <shim.rpm> <prefix>"
	echo "ex: $0 shim-0.9-18.9.x86_64.rpm sle12-sp1"
	exit 1
fi

RPM=$1
PREFIX=$2

if [ ! -e $RPM ]; then
	echo "$RPM doesn't exist"
	exit 1
fi

VERSION=`echo $RPM | cut -d '-' -f 2`

WORK_DIR=`mktemp -d`

cp $RPM $WORK_DIR
pushd $WORK_DIR
unrpm $RPM
tar jcvf ${PREFIX}-update-${VERSION}.tar.bz2 etc/uefi/ usr/lib64/
popd

mv ${WORK_DIR}/${PREFIX}-update-${VERSION}.tar.bz2 .
rm -rf ${WORK_DIR}
