#!/bin/bash
#coding : utf8

#            ▞▀▖    ▌   ▌
#   ▞▀▖▛▚▀▖   ▗▘  ▞▀▌▞▀▖▛▀▖       Make .deb, .rpm or slackware .tgz from SuperKaramba theme for Plasma
#   ▌ ▖▌▐ ▌  ▗▘   ▌ ▌▛▀ ▌ ▌       Originaly made for Crystal Monitor 8.1.1
#   ▝▀ ▘▝ ▘  ▀▀▘  ▝▀▘▝▀▘▀▀        Requies: make, checkinstall
#
#   Version: 0.2                              
#   Author: Mihael Simonič
#   Released under the terms of GPLv2 license

#   VARIABLES
#   Replace values to achieve your own needs

#Name
CMNAME="CrystalMonitor"
CMSHORTNAME="cm"
#Version
CMVERSION="9neta"
CMMAKEVERSION="9beta"    #For plasma configuration file
VERSION=$CMMAKEVERSION  #For Makefile
#Number of avaible translations in loKalizer
CMLANG="8"
#Website
CMSITE="http://odprtakoda.tuxfamily.org"
CMDOWN="$CMSITE/downloads/$CMSHORTNAME$CMMAKEVERSION.skz"
#Author and license
CMAUTHOR="Mihael Simonič"
CMEMAIL="smihael@gmail.com"
CMLICENSE="GPL"
#Package
CMDESC="CrystalMonitor $CMVERSION is free open-source SuperKaramba theme by Mihael Simonič. It is designed for use in Plasma desktop and provides many useful functions:
    * Kernel version: Display your kernel version
    * WindowManager version: Display KDE and QT version
    * CPU monitor: Display your processor name, temperature, and usage graph (user / system / total)
    * RAM/Swap monitor: RAM/Swap usage
    * Hard disk monitor: Display usage of Root and Home partitions + hard disk temperature
    * NetworkMonitor: Downstream/upstream traffic monitor for eth0 with graph
And at last, but not at least it's translated to $CMLANG languages and thanks to SuperKaramba great structure it's fully skinable. You can download scripts from project homepage."
CMSHORTDESC="SuperKaramba theme with a lot of system information"
CMREQ="hddtemp,lm-sensors,superkaramba"
CMTYPE="D" #D - debian, R - RedHat, S -Slackware
CMARCH="all" #all, i386, amd64
CMGROUP="kde"
#Files
KDEDIR=/usr/share/kde4
CMFILE="Crystal.theme"
CMICON="icon.svg"


#   End of variables
#   EDIT ONLY IF YOU KNOW WHAT ARE YOU DOING!

#Remove files from previous instalations
rm -f maindata.xml
rm -f plasma-applet-sk_$CMSHORTNAME$VERSION.desktop
rm -f Makefile
rm -f description-pak
rm -f $CMSHORTNAME$VERSION.skz 

#Generate maindata.xml
echo "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE superkaramba_theme>
<superkaramba_theme>
	<themefile>$CMFILE</themefile>
	<name>$CMNAME $CMVERSION</name>
	<icon>$CMICON</icon>
	<description>$CMSHORTDESC</description>
	<author>$CMAUTHOR</author>
	<homepage>$CMSITE</homepage>
	<version>$CMVERSION</version>
	<license>$CMLICENSE</license>
</superkaramba_theme>
" >> maindata.xml

#Generate plasma configuration file
echo "[Desktop Entry]
Comment=SuperKaramba Theme
Encoding=UTF-8
Icon=plasma_applet_sk_$CMSHORTNAME$CMMAKEVERSION/icon.svg
Name=CrystalMonitor $CMVERSION
Type=Service
X-KDE-Plasmagik-ApplicationName=
X-KDE-Plasmagik-RequiredVersion=
X-KDE-PluginInfo-Author=$CMAUTHOR
X-KDE-PluginInfo-Category=SuperKaramba
X-KDE-PluginInfo-Email=$CMEMAIL
X-KDE-PluginInfo-EnabledByDefault=true
X-KDE-PluginInfo-License=$CMLICENSE
X-KDE-PluginInfo-Name=sk_$CMSHORTNAME$CMMAKEVERSION
X-KDE-PluginInfo-Version=$CMVERSION
X-KDE-PluginInfo-Website=$CMSITE
X-KDE-ServiceTypes=Plasma/Applet,Plasma/Containment
X-Plasma-API=superkaramba" >> plasma-applet-sk_$CMSHORTNAME$VERSION.desktop

#Generate Makefile
echo "VERSION="$CMMAKEVERSION"
KDEDIR=/usr/share/kde4
 
all: zip install clean 

zip:
	zip -r $CMSHORTNAME$VERSION.skz * -x Makefile -x plasma-applet-sk_$CMSHORTNAME$VERSION.desktop

install:
	rm -Rf $KDEDIR/apps/plasma/plasmoids/sk_$CMSHORTNAME$VERSION/
	mkdir $KDEDIR/apps/plasma/plasmoids/sk_$CMSHORTNAME$VERSION/
	cp -f $CMSHORTNAME$VERSION.skz $KDEDIR/apps/plasma/plasmoids/sk_$CMSHORTNAME$VERSION/
	cp -f icon.svg $KDEDIR/apps/plasma/plasmoids/sk_$CMSHORTNAME$VERSION/
	cp -f plasma-applet-sk_$CMSHORTNAME$VERSION.desktop $KDEDIR/services/

clean:
	rm -f *.skz

clean_backups:
	rm -f *~" >> Makefile

#Make superkaramba zip
make zip

#Generate description-pak
echo "$CMSHORTDESC

$CMDESC" >> description-pak

#Generate package
checkinstall -$CMTYPE --pkggroup $CMGROUP --pkgarch $CMARCH --pkgsource $CMDOWN --maintainer $CMEMAIL --requires $CMREQ --pkgname $CMNAME --provides $CMNAME --pkgversion $CMVERSION --pkglicense $CMLICENSE