%define pck_majver %(echo %version | cut -d. -f1-3)
%define pck_minver %(echo %version | cut -d. -f4)
Name:          virtualbox-extension-pack
Version:       @SRPMVERSION@
Release:       @SRPMRELEASE@
Epoch:         1
Summary:       VirtualBox Extension Pack
Group:         Applications/Emulators
Vendor:        @vendor@
Distribution:  @distribution@
Packager:      Silvan Calarco <silvan.calarco@mambasoft.it>
URL:           http://www.virtualbox.org/
Source:        LICENSE
License:       Not Distributable
Requires(post):VirtualBox
BuildRoot:     %{_tmppath}/%{name}-%{version}-root

%description
VirtualBox Extension Pack.

%prep
%setup -c -n %{name}-%{version} -T

[ -r /etc/sysconfig/@sysconfigfile@ ] || exit 1
declare -A SRPMVERSION SRPMRELEASE
. /etc/sysconfig/@sysconfigfile@

[ "${VIRTUALBOX_EXTENSION_PACK_PCK}" ] || exit 1
[ "${VIRTUALBOX_EXTENSION_PACK_URL}" ] || exit 1

wget -nv --timeout=10 --tries=2 \
   ${VIRTUALBOX_EXTENSION_PACK_URL}${VIRTUALBOX_EXTENSION_PACK_PCK} -O ${VIRTUALBOX_EXTENSION_PACK_PCK}

[ -f ${VIRTUALBOX_EXTENSION_PACK_PCK} ] || exit 1

%build

%install
[ "%{buildroot}" != / ] && rm -rf %{buildroot}
declare -A SRPMVERSION SRPMRELEASE
. /etc/sysconfig/@sysconfigfile@

install -D -m0644 ${VIRTUALBOX_EXTENSION_PACK_PCK} %{buildroot}/opt/VirtualBox/extension/${VIRTUALBOX_EXTENSION_PACK_PCK}
cp %{S:0} LICENSE

%clean
[ "%{buildroot}" != / ] && rm -rf %{buildroot}

%post
#VBoxManage extpack uninstall Oracle_VM_VirtualBox_Extension_Pack || true
VBoxManage extpack install /opt/VirtualBox/extension/Oracle_VM_VirtualBox_Extension_Pack-%{pck_majver}%{?pck_minver:%pck_minver}.vbox-extpack --replace
# not working
:

%files
%defattr(-,root,root)
/opt/VirtualBox/extension/Oracle_VM_VirtualBox_Extension_Pack-%{pck_majver}%{?pck_minver:%pck_minver}.vbox-extpack
%doc LICENSE

%changelog
* Tue Aug 16 2011 Silvan Calarco <silvan.calarco@mambasoft.it> 4.1.2.73507-1mamba
- specfile created
