#!/bin/sh
#
# $Id: balou-export-theme 4648 2004-08-24 12:39:59Z benny $
#
# Copyright (c) 2004 Benedikt Meurer <benny@xfce.org>
# All rights reserved.
#
# 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, 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.
#                                                                              
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#

if test $# -ne 2; then
  echo "Usage: balou-export-theme <themerc> <targetfile>" >&2
  exit 1
fi

themerc="${1}"
targetfile="${2}"

# check theme
baloudir=`dirname "${themerc}"`
basedir=`dirname "${baloudir}"`
themesdir=`dirname "${basedir}"`
themename=`basename "${basedir}"`
if test ! -d "${baloudir}" -o ! -d "${basedir}" -o ! -d "${themesdir}"; then
  echo "Broken theme detected." >&2
  exit 1
fi

# tarup theme
(cd "${themesdir}" \
  && (tar cf - "${themename}/balou" \
      | gzip --best > "${targetfile}")) > /dev/null 2>&1
if test $? -ne 0; then
  echo "Unable to export theme ${themename} to file ${targetfile}" >&2
  exit 1
fi

exit 0
