1#!/bin/bash
2# If you make any improvements, feel free to email me any changes. nbargnesi at den-4.com
3# PACKAGENAME is the final tarred, compressed, iconset.
4PACKAGENAME="Lime-Rade8-3.1"
5REQUIRED_SIZES="32x32 22x22 16x16"
6
7# DEFINE NEW SIZES HERE
8#	These are sizes for everything except the actions folder, which contains
9#	menu and toolbar related stuff for KDE.  Add or remove a size here, I
10#	would recommend not removing the 32, 22, and 16 sizes.
11SIZES="96x96 72x72 64x64 48x48 $REQUIRED_SIZES"
12DIRS="apps devices filesystems mimetypes" # no actions directory needed, its hardcoded
13
14CONVERT_PATH=
15TAR_PATH=
16COMPRESSOR=
17function checkCompressor() {
18	echo -ne "Checking for bzip2... "
19	FOUND=`which bzip2`
20	if [ "$FOUND" != "" ]; then
21		echo -ne "found $FOUND\n"
22		COMPRESSOR=$FOUND
23		return
24	else
25		echo -ne " no.\n"
26		echo -ne "Checking for gzip... "
27		FOUND=`which gzip`
28		if [ "$FOUND" != "" ]; then
29			echo -ne "found $FOUND\n"
30			COMPRESSOR=$FOUND
31			return
32		else
33			echo -ne " no.\n"
34			echo -ne "\nNo compressor found (bzip2 | gzip).\n"
35			exit 1
36		fi
37	fi
38}
39function checkNeeded() {
40	echo -ne "Checking for tar... "
41	FOUND=`which tar`
42	if [ "$FOUND" != "" ]; then
43		echo -ne " found $FOUND\n"
44		TAR_PATH=$FOUND
45		echo -ne "Checking for convert... "
46		FOUND=`which convert`
47		if [ "$FOUND" != "" ]; then
48			echo -ne " found $FOUND\n"
49			CONVERT_PATH=$FOUND
50			return
51		else
52			echo -ne " no.\n"
53			echo -ne "\nNo convert found in path.\n"
54			exit 1
55		fi
56	else
57		echo -ne " no.\n"
58		echo -ne "\nNo tar found in path.\n"
59		exit 1
60	fi
61}
62function printFound() {
63	echo -ne "\nDependencies met - this script is using:\n"
64	echo -ne "\t\t$COMPRESSOR as compressor\n"
65	echo -ne "\t\t$TAR_PATH as tar path\n"
66	echo -ne "\t\t$CONVERT_PATH as convert path\n"
67}
68
69echo -ne "This script builds an installable KDE iconset using bash and convert.\n"
70echo -ne "Change what you want, add additional sizes, whatever... :)\n"
71echo
72
73checkCompressor
74checkNeeded
75printFound
76echo
77echo -ne "You get your choice of kmenu icons.  Select from: \n"
78echo -ne "\n\tgentoo, xeyes, redhat, mandrake, suse, openbsd, or nvidia and enter it now\n"
79read KMENU_ICON
80echo -ne "Using $KMENU_ICON.png as your kmenu icon.\n"
81if test -f 128x128/apps/$KMENU_ICON.png
82	then
83		cp -f 128x128/apps/$KMENU_ICON.png 128x128/apps/kmenu.png
84		cp -f 128x128/apps/$KMENU_ICON.png 128x128/apps/go.png
85	else
86		echo -ne "Invalid selection ($KMENU_ICON), exiting...\n"
87		exit 1
88fi
89echo -ne "Ready to go!  Converting all icons! (about 15 seconds on an Athlon 64)\n"
90echo
91
92#Loop directory creation according to SIZES specified at startup
93for size in $SIZES
94do
95	mkdir -p $size/apps $size/devices $size/mimetypes $size/filesystems
96done
97
98# Required sizes for actions
99mkdir -p 22x22/actions 16x16/actions
100
101# Mmmm... loops...
102for dir in $DIRS
103do
104	cd 128x128/$dir
105	for icon in *
106	do
107		# Loop the specified sizes
108		for size in $SIZES
109		do
110			convert "$icon" -resize $size ../../$size/$dir/"$icon"
111		done
112	done
113	# Move from 128x128/$directory to toplevel
114	cd ../../
115done
116
117# Move from 128x128/ to 32x32/
118cd 32x32/actions
119for icon in *
120do
121	convert "$icon" -resize 22x22 ../../22x22/actions/"$icon"
122	convert "$icon" -resize 16x16 ../../16x16/actions/"$icon"
123done
124
125# Move to top directory
126cd ../../
127
128mkdir $PACKAGENAME
129cp -R 128x128 $PACKAGENAME
130cp -R 32x32 $PACKAGENAME
131cp index.desktop $PACKAGENAME
132
133# Move/Remove the created directories so the user can rebuild if needed.
134rm -fr 32x32/apps 32x32/devices 32x32/mimetypes 32x32/filesystems
135for size in $SIZES
136do
137	if [ "$size" != "32x32" ]; then # Already did the 32x32 size above
138		mv $size $PACKAGENAME
139	fi
140done
141
142echo -ne "Done with conversions.\n"
143echo -ne "Tarring and compressing.\n"
144if test -f $COMPRESSOR
145	then
146		tar cf $PACKAGENAME.tar $PACKAGENAME && $COMPRESSOR $PACKAGENAME.tar
147		echo -ne "$PACKAGENAME has been built.  Use kcontrol to install it.\n"
148		echo && ls -sh $PACKAGENAME.tar* && echo
149fi
150echo -ne "Removing temporary directory...\n"
151rm -fr $PACKAGENAME
152
153echo -ne "\nAll done. ;)\n"
154
155