summaryrefslogtreecommitdiff
path: root/copy-gnome-icons.sh
blob: 5d19c7181c77263c6f6566840c4fd93bc6b286ae (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
#!/bin/bash
#Copyright (C) 2014, 2021 Ben Asselstine
#This script is licensed under the terms of the GNU GPL version 3 or later.
#
# Pares down the gnome icons for distribution in the windows version of
# LordsAWar!.   There are just too many megabytes of them to include with
# this game, so this script tries to take a useful subset of them.
#
# This script copies the icon files, removes cache files, removes the icons 
# that we don't want, and then finally it updates the INI files appropriately.
# The INI files are called index.theme.
#
# This script does it's work in /tmp/, and then drops a newly created 
# share/ directory in the current working directory.
#
# We've removed the stock icons in the glade files but still the default icons
# on the title bar are required (e.g. minimize, maxmimize, close.)

#process these directories of icons in /usr/share/icons/
dirs="Adwaita"

if [ -d share ]; then
  echo "There is already a share/ directory here!"
  exit 1
fi
#remove these sizes
adwaitabadsizes="scalable scalable-up-to-32 8x8 22x22 24x24 32x32 48x48 64x64 96x96 256x256"

remove_ini_section()
{
  inifile=$1
  name=$2
  count="0"
  tmpfile=`mktemp /tmp/bar.XXXXXX`
  while IFS='' read -r line || [[ -n $line ]]; do
    echo $line | grep "^\[$name.*\]$" 2>/dev/null >/dev/null
    ret="$?"
    if [ "x$count" != "x0" ]; then
      count=`expr $count + 1`
    fi
    if [ "x$ret" == "x0" ]; then
      count="1"
    fi
    if [ "$count" == "0" ]; then
      echo $line >> $tmpfile
    fi
    if [ "x$line" == "x" ]; then
      count="0"
    fi
  done < "$inifile"
  cp $tmpfile $inifile
  rm $tmpfile
}

fixup_ini () 
{
  inifile=$1
  shift
  badsizes=$*
  for b in $badsizes; do
    remove_ini_section $inifile $b
  done
  for b in $badsizes; do
    sed -i -e "s/$b\/[A-Za-z0-9\/]*,*//g" $inifile
  done
}

tmpdir=`mktemp -d /tmp/foo.XXXXXX`

mkdir -p $tmpdir/share/icons

for d in $dirs; do
  cp -r /usr/share/icons/$d $tmpdir/share/icons/
  rm $tmpdir/share/icons/$d/icon-theme.cache
  badsizes=""
  if [ "$d" == "Adwaita" ]; then
    badsizes=$adwaitabadsizes
    rm -rf $tmpdir/share/icons/$d/cursors
  fi
  for delsize in $badsizes; do
    if [ -d $tmpdir/share/icons/$d/$delsize ]; then
      rm -rf $tmpdir/share/icons/$d/$delsize
    fi
  done
  fixup_ini $tmpdir/share/icons/$d/index.theme $badsizes
done

mkdir -p $tmpdir/share/glib-2.0/schemas
cp /usr/share/glib-2.0/schemas/gschemas.compiled $tmpdir/share/glib-2.0/schemas

mv $tmpdir/share ./
rmdir $tmpdir