summaryrefslogtreecommitdiff
path: root/git-compiz
blob: b4e418840b496780b5fa4771385ff2bea6709874 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
#!/bin/bash
########################################################################################################################################
# GiT-CoMpIz															       #
######################################################################################################################################## 
# Copyright (C) 2009 omega
#
# 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 3 of the License, 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.
#########################################################################################################################################
####### DO NOT EDIT THIS FILE ! #########################################################################################################
#########################################################################################################################################
SPPID=0

trap "kill $SPPID" EXIT

## Locales
# check if locale file to import exist, then import them, else set default locale (english)
LC_USER=`echo $LANG | cut -d _ -f1`
if [ ! -f po/$LC_USER.po ]; then
        source po/en.po 
else
        source po/$LC_USER.po
fi

## Data files
# check if files to import exist, then import them
if [ ! -f $0.def ]; then
	echo $ERROR_DEF_FILE
	echo $ERROR_EXIT
	exit 4
else
	source $0.def
fi
if [ ! -f $0.dep ]; then
	echo $ERROR_DEP_FILE
	echo $ERROR_EXIT
	exit 4
else
	source $0.dep
fi

test -f $0.local && source $0.local

#LOG_FILE=/tmp/`echo $0 | sed -e s,./,,`-$$.log
LOGDIR=$(mktemp -d /tmp/git-compiz.XXXXXXXX)

## Check arch for libdir
ARCH=`uname -m`
if [ -f /etc/SuSE-release -o -f /etc/fedora-release ] && [ $ARCH == "x86_64" ]; then
        LIBDIR=lib64
else
        LIBDIR=lib
fi

## Help menu'
help_me()
{
echo -e $HELP
exit 0
}

# Log any command to $LOG_FILE, or to there and stdin
logcmd()
{
if [ $1 == "echo" -o $DEBUG != "false" -o $1 == "git clone" ]; then
        $@ 2>&1 | tee -a $LOG_FILE
else
        $@ >>$LOG_FILE 2>&1
fi
}

root()
{
case $ROOT in
	sudo)
		if [ $DEBUG == "false" ]; then
			sudo "$@" >>$LOG_FILE 2>&1
		else
			sudo "$@" 2>&1 | tee -a $LOG_FILE
		fi
		;;
	user)
		if [ $DEBUG == "false" ]; then
			$@ >>$LOG_FILE 2>&1
		else
			$@ 2>&1 | tee -a $LOG_FILE
		fi
		;;		
	*)
		if [ $DEBUG == "false" ]; then
			su -c "$@" root >>$LOG_FILE 2>&1
		else
			su -c "$@" root 2>&1 | tee -a $LOG_FILE
		fi
		;;
esac
}

## Add Fusion-Icon to startup
fix_startup()
{
echo -n $INFO_FIX_STARTUP
if [ ! -f $HOME/.config/autostart/fusion-icon.desktop ]; then
        cp extras/fusion-icon.desktop $HOME/.config/autostart &>/dev/null
        ln -s /usr/bin/fusion-icon $HOME/.kde/Autostart/fusion-icon &>/dev/null
fi
echo $INFO_OK
exit 1
}

## Fix Python path
fix_python()
{
echo -n $INFO_FIX_PYTHON
if [ -d $DESTDIR$PREFIX/$LIBDIR/python2.6/dist-packages -a ! -f $DESTDIR$PREFIX/$LIBDIR/python2.6/dist-packages/compiz_path.pth ]; then
	sudo bash -c "echo $DESTDIR$PREFIX/$LIBDIR/python2.6/site-packages >> $DESTDIR$PREFIX/$LIBDIR/python2.6/dist-packages/compiz_path.pth"
fi
echo $INFO_OK
exit 1
} 

## Check and install dependencies for your distro (if it's supported)
check_distro_dependencies()
{
case `lsb_release -cs` in
	sid) sudo aptitude update ; sudo aptitude -y install $sid_check_dep
		;;
	lenny) sudo aptitude update ; sudo aptitude -y install $lenny_check_dep
		;;
	gutsy) sudo aptitude update ; sudo aptitude -y install $gutsy_check_dep
		;;
	hardy) sudo aptitude update ; sudo aptitude -y install $hardy_check_dep
		;;
	intrepid) sudo aptitude update ; sudo aptitude -y install $intrepid_check_dep
		;;
	jaunty) sudo aptitude update ; sudo aptitude -y install $jaunty_check_dep
		;;
	karmic) sudo aptitude update ; sudo aptitude -y install $karmic_check_dep
		;;
	lucid) sudo aptitude update ; sudo aptitude -y install $lucid_check_dep
		;;
	maverick) sudo aptitude update ; sudo aptitude -y install $maverick_check_dep
		;;
	*)
		if [ -f /etc/SuSE-release ]; then
			su -c "zypper ref ; zypper in $suse_check_dep"
		elif [ -f /etc/fedora-release ]; then
			su -c "yum update ; yum -y install $fedora_check_dep"
		elif [ -f /etc/slackware-version ]; then
			su -c "slapt-get update ; slapt-get install $slackware_check_dep"
		elif [ -f /etc/arch-release ]; then
			su -c "pacman -Sy $arch_check_dep"
		elif [ -f /etc/mandriva-release ]; then
			su -c "urpmi.update -a ; urpmi $mandriva_check_dep"
		else
			echo $ERROR_CHECK_DEP_1
		fi
		;;
esac
	exit 1;
}

## Purge all data/packages installed by this script/distro
purge_compiz()
{
case `lsb_release -cs` in
        hardy|intrepid|jaunty|karmic) sudo aptitude purge $ubuntu_purge
                ;;
	*)
		;;
esac

if [ x$ROOT == x"sudo" ]; then
	sudo rm -rvf $data_to_purge
else 
	su -c "rm -rvf $data_to_purge"
fi
exit 0
}

## Fix Gnome-WM
gwm_fix()
{
LOG_FILE=/dev/null
if [ -f /etc/SuSE-release ]; then
	echo $ERROR_GWM_SUSE
	exit 2
else
	GNOME_WM=`which gnome-wm`
	if [ -f $GNOME_WM ]; then
		echo $ERROR_GWM
		exit 1
	fi
	root bash -c "mv $GNOME_WM $GNOME_WM.real && install -g root -o root -m 755 extras/gnome-wm.replacement $GNOME_WM"
	echo $INFO_GWM
fi
}

## Get the parameter of --x= type arg
ARGS_SCRIPT=$@
get_arg()
{
(for myarg in $ARGS_SCRIPT; do echo $myarg; done) | grep -e $1 | sed -e s,$1,, -e s,\",,
}

for singlearg in $ARGS_SCRIPT; do
	case $singlearg in
		--branch=*)
			BRANCH=`get_arg --branch=`
			;;
		--check)
			wget http://blogage.de/files/9124/download -O scripts/compiz-check
			chmod +x scripts/compiz-check
			./scripts/compiz-check
			exit 0;
			;;
		--check-dep)
                        check_distro_dependencies;
                        ;;
		--destdir=*)
			DESTDIR=`get_arg --destdir=`
			;;
		--disable-icons)
			UNOFFICIAL_ICONS="no"
			;;
		--disable-protobuf)
			ARGS="$ARGS --disable-protobuf"
			;;
		--enable-gwm-compiz)
			gwm_fix
			exit 0
			;;
		--enable-headtracking)
			OPENCV="yes"
			PLUGINS="
			$PLUGINS
			users/klange/headtracking
			"
			;;
		--fix-python)
			fix_python;
			;;
		--fix-startup)
			fix_startup;
			;;
		--force-switch)
			SWITCH_BRANCH="force"
			;;
		--help)
			help_me
			;;
		--jobs=*)
			JOBS=`get_arg --jobs=`
			;;
		--purge)
			purge_compiz
			;;
		--prefix=*)
			PREFIX=`get_arg --prefix=`
			;;
		--rebuild=*)
			FORCE_REBUILT=`get_arg --rebuild=`
			;;
		--root=*)
			ROOT=`get_arg --root=`
			;;
		--skip-build)
			NOBUILD="yes"
			;;
		--skip-install)
			SKIP_INSTALL="true"
			;;
		--skip-update)
			SKIP_UPDATE="true"
			;;
		--undo=*)
			FORCE_REBUILT=`get_arg --undo=`
			UNDO_LAST_UPDATE="yes"
			;;
		--verbose)
			DEBUG="true"
			;;
		--with-desktop=all)
			ARGS="--enable-gconf --enable-kconfig --enable-kde4"
			DE="
			fusion/compizconfig/compizconfig-backend-gconf 
			fusion/compizconfig/compizconfig-backend-kconfig4
			fusion/compizconfig/simple-ccsm
			users/seli/simple-ccsm-kde
			"
			;;
		--with-desktop=gnome)
			ARGS="--enable-gconf --disable-kconfig --disable-kde --disable-kde4"  
                        DE="
			fusion/compizconfig/compizconfig-backend-gconf
			fusion/compizconfig/simple-ccsm
			"
			UNOFFICIAL_ICONS_THEME="tango"
			;;
		--with-desktop=kde)
			ARGS="--disable-gconf --disable-gtk --disable-metacity --disable-gnome --disable-gnome-keybindings --disable-kde4" 
                        DE="
			fusion/compizconfig/compizconfig-backend-kconfig
			"
			UNOFFICIAL_ICONS_THEME="oxygen"
			;;
		--with-desktop=kde4)
			ARGS="--disable-gconf --disable-gtk --disable-metacity --disable-gnome --disable-gnome-keybindings --disable-kde"
                        DE="
			fusion/compizconfig/compizconfig-backend-kconfig4
			users/seli/simple-ccsm-kde
			"
			;;
		*)
                        echo "$ERROR_INVALID_OPTION $singlearg";
                        exit 1
                        ;;
	esac
done

# Prints updates
# $1  == Type
# $2+ == What to print (depends on output type)
# TODO: Perhaps add colors to info and error (green and red?)
printinfo()
{
OTHER_ARGS="`echo $@ | sed -e s:$1\ :: `"
case $1 in
	space)
		echo "_____________________________________________________"
		echo
		;;
	info)
		echo -n " * $OTHER_ARGS"
		;;
	trail)
		echo "...........$OTHER_ARGS"
		;;
	error)
		echo " -> $OTHER_ARGS"
		;;
	warning)
		echo "    WARNING: $OTHER_ARGS"
		;;
esac
}

## Check minimal dependencies to use this script
check_minimal_dependencies()
{
printinfo info $INFO_CHECK_DEP;
printinfo echo

# If any dependencies fail, alert the user
if (for onedep in tee svn git make python cmake; do (which $onedep &>/dev/null) || break ; done ); then
	printinfo trail $INFO_OK
	printinfo space
else
	printinfo trail $INFO_ERROR
	printinfo error $ERROR_CHECK_DEP_2
	printinfo space
	exit 1;
fi
}

## Check internet status
check_internet_status()
{
if [ "$SKIP_UPDATE" != "true" ]; then
printinfo info $INFO_INTERNET_STATUS;
	if ! ping -c 2 google.com &>/dev/null; then
		printinfo trail $INFO_ERROR
		return 1;
	fi
	printinfo trail $INFO_OK
	printinfo space
fi
}

## Asks if we want to bail out.
bail_ask()
{
echo "$1"
echo  -n $INFO_ABORT
read -p " [Y/n]: " -n1 continue;
if [ "$(echo $continue | tr [:upper:] [:lower:])" = "y" -o "$continue" = "" ]; then
	echo 
	exit 3;
fi
echo
printinfo space
}

# Our Nice little spinner
spinner()
{
MESSAGE=$@
if [ x$DEBUG == x"false" ]; then
	until test -f $LOGDIR/stop; do
		echo -en "\r | $MESSAGE"
		sleep 0.1
		echo -en "\r / $MESSAGE"
		sleep 0.1
		echo -en "\r - $MESSAGE"
		sleep 0.1
		echo -en "\r \\ $MESSAGE"
		sleep 0.1
	done
	echo -e "\r * $MESSAGE"
	rm $LOGDIR/stop
else
	echo " * $MESSAGE"
fi
}

## Checks if a local directory for $1 exist (last part of it), 
## if it does; attempts to git pull, otherwise git clone.
# TODO: Extend this to support svn, bzr, hg or any others (should be flexible)
# TODO: put the downloaded files from this function into a separate folder (git/ or something similar)
get_repo()
{
if (echo $1 | grep -q '%writeto%'); then
			b=`echo $1 | sed 's|.*%writeto%||'`
else
			b=`echo $1 | sed 's/.*\///g'`
fi
echo ">> $b <<"
echo

test -f branches/$BRANCH || echo "${ERROR_BRANCH//%s/branches/$BRANCH}"

# Get the branch
CURRENT_ITEM=$b source branches/$BRANCH

here=$PWD
if [ -d $b -o -d $b-http ]; then
	([ -d $b-http ] && cd $b-http) || cd $b
	# Revert any patched files
	if (find . 2>/dev/null | grep -q '\.orig'); then
		printinfo info $INFO_REVERT_PATCH;
		echo
		for orig in `find . -name '*.orig'`; do
			mv $orig `echo $orig | sed 's,.orig,,'` >/dev/null
		done
	fi
	if [ "$SKIP_UPDATE" != "true" -a "$UNDO_LAST_UPDATE" != "yes" -a -z "`echo $b | grep -e tar.bz2 -e tar.gz -e zip`" ]; then
		spinner "${INFO_UPDATE//%s/$b}" &
		SPPID=$!
		git pull | grep -q "Already up-to-date."
		test=`echo $?`
		touch $LOGDIR/stop
		sleep 0.4
		if (! (echo $GIT_BRANCH | grep -qie HEAD -qie master)) && \
		   (git show-branch $GIT_BRANCH &>/dev/null) && \
		   [ x$SWITCH_BRANCH == x"force" ]; then
			printinfo info "${INFO_SWITCH//%s/'$(echo $GIT_BRANCH | sed 's|.*/||g')'}";
			echo
			git checkout -b $(echo $GIT_BRANCH | sed 's|.*/||g') --track $GIT_BRANCH
		fi
		cd $here
	elif [ "$UNDO_LAST_UPDATE" == "yes" -a -z "`echo $b | grep -e tar.bz2 -e tar.gz -e zip`" ]; then
		printinfo info "${INFO_UNDO//%s/$b}";
		echo
		git reset --hard HEAD^ &>/dev/null
		test=1
	else 	test=0
	fi
	cd $here
else
	if ! (echo $b | grep -qe zip -qe tar.gz -qe tar.bz2); then
		printinfo info "${INFO_CLONE//%s/$b}";
		echo
		git clone $2$1
		cd $b
		if (! (echo $GIT_BRANCH | grep -qie HEAD -qie master)) && \
		   (git show-branch $GIT_BRANCH &>/dev/null); then
			printinfo info "${INFO_SWITCH//%s/'$(echo $GIT_BRANCH | sed 's|.*/||g')'}";
			echo
			git checkout -b $(echo $GIT_BRANCH | sed 's|.*/||g') --track $GIT_BRANCH
		fi
		cd $here
		test=1
	else
		# download via wget
		printinfo info "${INFO_DOWNLOAD//%s/$b}";
		echo
		if (echo $1 | grep -q '%writeto%'); then
			wget -O $b -nv `echo $1 | sed 's|%writeto%.*||'`
		else
			wget -nv $1
		fi
		# extract
		printinfo info "${INFO_EXTRACT//%s/$b}";
		echo

		(echo $b | grep -qe tar.bz2 -qe tar.gz -qe zip) && \
		mkdir $b-http && cd $b-http && \
		(if (echo $b | grep -q tar.bz2); then
			tar -xjf $OLDPWD/$b
		elif (echo $b | grep -q tar.gz); then
			tar -xzf $OLDPWD/$b
		elif (echo $b | grep -q zip); then
			unzip $OLDPWD/$b
		fi) && \
		[ -d "$(ls)" ] && export USELESSDIR=$(ls) && mv $USELESSDIR/* ./ && rmdir $USELESSDIR

		cd $here
		test=1
	fi
fi

return $test

printinfo space
}

#### git-compiz now has a build system that handles more types of builds
### Start build functions

## Start prebuild functions

# Apply patches
# $1 == Git object currently being handled
build_patch()
{
LOG_FILE="$LOGDIR/patch-$1.log"
# CPWD is taken from build_wrapper
for mypatch in $PATCHES; do
	# If it exists in a format we can use, apply it
	if [ -f $mypatch -a x`cat $mypatch | grep GIT_OBJECT | sed 's,GIT_OBJECT=,,'` == x"$1" ]; then
		printinfo info "${INFO_APPLY//%s/`basename $mypatch`}";
		echo
		cd $1
		# Use --backup here so they can be reverted later on
		logcmd patch --backup -p1 <$CPWD/$mypatch
		cd $CPWD
	fi
done
}

# (make) Clean
# $1 == Git object currently being handled
build_clean()
{
LOG_FILE="$LOGDIR/clean-$1.log"
# CPWD is taken from build_wrapper
cd $1
spinner $INFO_CLEAN &
SPPID=$!
if [ -d build -a -f CMakeLists.txt ]; then
	root rm -rf build
fi
logcmd make clean
EXST=$?
touch $LOGDIR/stop
sleep 0.4
if [ $EXST -ne 0 ]; then
	printinfo warning $WARNING_CLEAN;
	cd $CPWD
	return 1
fi
cd $CPWD
}
## End prebuild functions

## Start configure functions
# autoconf/automake build function
# $1 == Git object currently being handled
# $2 == autogen arguments
build_autoconf()
{
LOG_FILE="$LOGDIR/conf-$1.log"
# CPWD is taken from build_wrapper
cd $1
spinner $INFO_CONFIGURE &
SPPID=$!
logcmd env PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH ./autogen.sh $2
EXST=$?
touch $LOGDIR/stop
sleep 0.4
if [ $EXST -ne 0 ]; then
	printinfo error $ERROR_AUTOGEN;
	printinfo space
	cd $CPWD
	return 1
fi
cd $CPWD
}

# cmake build function
# $1 == Git object currently being handled
# $2 == cmake arguments
build_cmake()
{
LOG_FILE="$LOGDIR/conf-$1.log"
# CPWD is taken from build_wrapper
cd $1
spinner $INFO_CONFIGURE &
SPPID=$!
test -d build || mkdir build
cd build
if [ $LIBDIR == "lib64" ]; then
	logcmd 	env PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH \
		cmake -D CMAKE_INSTALL_PREFIX=$PREFIX -D LIB_SUFFIX=64 $2 $CPWD/$1
else
	logcmd 	env PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH \
		cmake -D CMAKE_INSTALL_PREFIX=$PREFIX $2 $CPWD/$1
fi
EXST=$?
touch $LOGDIR/stop
sleep 0.4
if [ $EXST -ne 0 ]; then
	printinfo error $ERROR_CMAKE;
	printinfo space
	cd $CPWD
	return 1
fi
cd $CPWD
}
## End configure functions

# make build function
# $1 == Git object currently being handled
# $2 == autoconf/cmake
build_make()
{
LOG_FILE="$LOGDIR/make-$1.log"
# CPWD is taken from build_wrapper
cd $1
if [ x$2 == x"cmake" ]; then
	test -d build || mkdir build
	# If this is cmake, move to and STAY in build/
	cd build 
fi
if [ x$NOBUILD != x"yes" ]; then
	spinner $INFO_COMPILE &
	SPPID=$!
	logcmd env PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH make -j$JOBS
	EXST=$?
	touch $LOGDIR/stop
	sleep 0.4
	if [ $EXST -ne 0 ]; then 
		printinfo error $ERROR_MAKE;
		printinfo space
		cd $CPWD
		return 1
	fi
fi

LOG_FILE="$LOGDIR/install-$1.log"
spinner $INFO_INSTALL &
SPPID=$!
if [ -f autogen.sh ] || [ x$2 == x"cmake" ]; then
	root env BUILD_GLOBAL=true \
	PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH \
	make ${DESTDIR:+ DESTDIR=\"$DESTDIR\"}  install 
else
	#Workaround:
	#If you use the DESTDIR parameter with "make install" to install the extra plugins (like vigo, mousegestures or wizard), 
	#then DESTDIR points to the directory, where the lib*.so files are copied to (usually /usr/lib/compiz, i think). 
	#So if you change DESTDIR to "/mypath" then the extra plugins are copied to "/mypath" and not to "/mypath/usr/lib/compiz". 
	#But all other stuff (like core, plugins-main etc.) is copied correctly.
	root env PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH \
	BUILD_GLOBAL=true make ${DESTDIR:+ \
					PREFIX=\"$DESTDIR$PREFIX\" \
					CLIBDIR=\"$DESTDIR$PREFIX/$LIBDIR\" \
					DESTDIR=\"$DESTDIR$PREFIX/$LIBDIR/compiz\" \
					XMLDIR=\"$DESTDIR$PREFIX/share/compiz\" \
					IMAGEDIR=\"$DESTDIR$PREFIX/share/compiz\" \
					DATADIR=\"$DESTDIR$PREFIX/share/compiz\" \
				} install
fi
EXST=$?
touch $LOGDIR/stop
sleep 0.4
if [ $EXST -ne 0 ]; then
	printinfo error $ERROR_SUDO_MAKE;
	printinfo space
	cd $CPWD
	return 1
fi
cd $CPWD    
printinfo space
}

# Build wrapper function
# $1 == Git object currently being handled
# $2 == autogen/cmake arguments
# $3 == Custom command to build
build_wrapper()
{
CPWD=$PWD
# Check if we are going to skip this...
if [ "$SKIP_INSTALL" == "true" -o $test -ne 1 ] && [ "$FORCE_REBUILT" != "true" \
	-a -z "`(for dir in $FORCE_REBUILT; do [ $dir != $1 ] || echo "yes"; done) | grep yes`" ]; then
		printinfo info "${INFO_SKIP//%s/$1}";
		echo
		printinfo space
		return;
fi
# Check if the directory exists
if [ ! -d $1 ]; then
	printinfo error "$1 $ERROR_DIRECTORY";
	printinfo space
	return 1;
fi
# Apply patches
if [ x$NOBUILD != x"yes" ]; then
	build_patch "$1"
fi
# Export pkgconfig variables
export PKG_CONFIG_PATH=$DESTDIR$PREFIX/$LIBDIR/pkgconfig:$DESTDIR$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH
# Search for build type in the following order
#   python
#   autoconf/automake
#   cmake
#   makefile
#   compiz-manager
#   other
if [ -f $1/setup.py ]; then
	cd $1
	printinfo info $INFO_INSTALL;
	echo
	root python setup.py install ${DESTDIR:+ --root=$DESTDIR} --prefix=$PREFIX
	printinfo space
	cd $CPWD
elif [ -f $1/autogen.sh ] && [ x$1 != x"opencv" ]; then
	if [ x$NOBUILD != x"yes" ]; then
		build_clean "$1"
		build_autoconf "$1" "$2"
	fi
	build_make "$1" 
elif [ -f $1/CMakeLists.txt ] && ! (cat $1/Makefile 2>/dev/null | grep -q 'Compiz plugin Makefile'); then
	if [ x$NOBUILD != x"yes" ]; then
		build_clean "$1"
		build_cmake "$1" "$2"
	fi
	build_make "$1" cmake
elif [ -f $1/Makefile ]; then
	if [ x$NOBUILD != x"yes" ]; then
		build_clean "$1"
	fi
	build_make "$1" 
elif [ -f $1/compiz-manager ]; then
	printinfo info $INFO_INSTALL;
	echo
	sed -e s:COMPIZ_BIN_PATH=\"/usr/local/bin/\":COMPIZ_BIN_PATH=\"$PREFIX/bin/\": -e s:PLUGIN_PATH=\"/usr/local/lib/compiz/\":PLUGIN_PATH=\"$PREFIX/$LIBDIR/compiz/\": -e s:/lib/:/$LIBDIR/:g $1/compiz-manager >$1/compiz-manager.temp
	root install -m 755 $1/compiz-manager.temp $DESTDIR$PREFIX/bin/compiz-manager 
	rm $1/compiz-manager.temp
	printinfo space
elif [ "$3" != "" ]; then
	printinfo info $INFO_INSTALL;
	echo
	cd $1
	$3 $2
	cd $CPWD
	printinfo space
else
	printinfo error $ERROR_BUILD_1;
	printinfo space
	return;
fi
}
### End build functions

unofficial_icons()
{
b="unofficial-compiz-fusion-icons"
CPWD=$PWD
echo ">> $b <<"

if [ ! -d $b ]; then
	spinner "${INFO_CHECK_OUT//%s/$b}" &
	SPPID=$!
        svn co http://compiz-fusion-icons.googlecode.com/svn/trunk $b >/dev/null
	touch $LOGDIR/stop
else
	if [ "$SKIP_UPDATE" != "true" -a -d $b ]; then
		spinner "${INFO_UPDATE//%s/$b}" &
		SPPID=$!
		cd $b
		svn update | grep -q "At revision"
		test=$?
		touch $LOGDIR/stop
		cd $CPWD
	fi
fi
sleep 0.4

build_wrapper $b none "root ./install.sh --prefix=$DESTDIR$PREFIX --$UNOFFICIAL_ICONS_THEME"
}

opencv()
{
b="opencv"
CPWD=$PWD
echo ">> $b <<"

if [ ! -d $b ]; then
	spinner "${INFO_CHECK_OUT//%s/$b}" &
	SPPID=$!
        svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk . >/dev/null
	touch $LOGDIR/stop
else
        if [ "$SKIP_UPDATE" != "true" -a -d $b ]; then
                spinner "${INFO_UPDATE//%s/$b}" &
		SPPID=$!
                cd $b
                svn update | grep -q "At revision"
		test=$?
		touch $LOGDIR/stop
                cd $CPWD
        fi
fi

build_wrapper $b "-D CMAKE_BUILD_TYPE=RELEASE -D BUILD_PYTHON_SUPPORT=ON"
}

echo
echo ">>>           G I T  - C O M P I Z          <<<"
printinfo space

printinfo info "${INFO_LOG_FILE//%s/$LOGDIR}";
echo
printinfo space

## Check dependencies and internet status
check_minimal_dependencies

if ! check_internet_status; then
	bail_ask $ERROR_INTERNET_STATUS
fi

## Auto-Update git-compiz script
if [ "$SKIP_UPDATE" != "true" ]; then
	b=`echo "users/omega/scripts" | sed 's/.*\///g'`
	printinfo info "${INFO_UPDATE//%s/git-compiz}";
	echo
	git pull | grep -q "Already up-to-date."
	test=`echo $?`
  
	if [ $test -ne 1 ]; then
		printinfo error $INFO_AUTOUPDATE_1;
		printinfo space
	else
		printinfo error $INFO_AUTOUPDATE_2;
		printinfo space
		exit 3;
        fi
fi

## Get compiz core
get_repo $CORE $REPO

## Build compiz core first, and no need to continue if it fails.
if ! build_wrapper core "$ARGS --prefix=$PREFIX --libdir=$PREFIX/$LIBDIR"; then
	echo $ERROR_CORE;
	exit 2;
fi

## Install OpenCV (required by headtracking plugin)
if [ x$OPENCV == x"yes" ]; then
        opencv
fi

## Build everything else now.
for a in $BASE $EMERALD $I18N $DE $PLUGINS; do
	if (echo $a | grep -q '%writeto%'); then
		b=`echo $a | sed 's|.*%writeto%||'`
	else
		b=`echo $a | sed 's/.*\///g'`
	fi
	get_repo $a $REPO
	if ! build_wrapper `([ -d $b ] && echo $b) || ([ -d $b-http ] && echo $b-http)` "$ARGS --prefix=$PREFIX --libdir=$PREFIX/$LIBDIR"; then
		bail_ask "${ERROR_BUILD_2//%s/$b} !"
	fi
done

## Install icons
if [ x$UNOFFICIAL_ICONS != x"no" ]; then
	unofficial_icons
fi