summaryrefslogtreecommitdiff
path: root/engines/balou/scripts/balou-install-theme
blob: 0f889e41d4e4069a85f85505023fc3968a4b03f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
#
# $Id$
#
# 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.
#

leave()
{
  if test -d "${tmpdir}"; then
    rm -rf "${tmpdir}" >/dev/null 2>&1
  fi
  exit $1
}

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

tmpdir=""
themedir="${1}"
targetdir="${2}"

# ensure the target directory exists
if test ! -d "${targetdir}"; then
  mkdir -p "${targetdir}" >/dev/null 2>&1
  if test $? -ne 0; then
    echo "Unable to create themes directory ${targetdir}." >&2
    exit 1
  fi
fi

# if the source is a file, we expect it to be a tarball
if test -f "${themedir}"; then
  tmpdir=`mktemp -d "/tmp/balou-theme-XXXXXX"` || exit 1

  if echo "${themedir}" | grep '\.tar\.gz$' >/dev/null 2>&1; then
    tar xzf "${themedir}" -C "${tmpdir}" >/dev/null 2>&1
    if test $? -ne 0; then
      echo "Unable to extract theme." 2>&2
      leave 1
    fi
  else
    echo "Not a splash theme file: ${themedir}." >&2
    leave 1
  fi

  themerc=`ls ${tmpdir}/*/balou/themerc` || leave 1
  baloudir=`dirname "${themerc}"` || leave 1
  topdir=`dirname "${baloudir}"` || leave 1

  if test ! -d "${topdir}" -o ! -d "${topdir}/balou/"; then
    echo "Invalid theme file format." >&2
    leave 1
  fi

  themedir="${topdir}"
fi

# verify the theme content
if test -d "${themedir}"; then
  if test ! -d "${themedir}/balou/"; then
    echo "No balou sub directory in theme." >&2
    leave 1
  fi

  if test ! -r "${themedir}/balou/themerc"; then
    echo "No themerc file in theme." >&2
    leave 1
  fi
fi

# install the theme
themebase=`dirname "${themedir}"`
themename=`basename "${themedir}"`
(cd "${themebase}" \
   && tar cf - "${themename}/balou/" \
    | (cd "${targetdir}" && tar xf -)) >/dev/null 2>&1
if test $? -ne 0; then
  echo "Unable to install the theme ${themename} from ${themebase} to ${targetdir}." >&2
  leave 1
fi

# tell the caller the name of the installed plugin
echo "${themename}"
leave 0