summaryrefslogtreecommitdiffstats
path: root/tools/installer
blob: 9345c31b7e9db22f5b7cadf96080193128d57bb5 (plain) (blame)
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
#!/bin/bash

# include fancy bash color stuff
. tools/inc/colors


# determin distribution
DISTRO=$(lsb_release -i| sed 's/^[^:]*:\t//' | tr '[:upper:]' '[:lower:]')

# get/set default paths
[ -z $USR_BIN_PATH ]       && USR_BIN_PATH=/usr/bin
[ -z $SLX_CONFIG_PATH ]    && SLX_CONFIG_PATH=/etc/opt/openslx
[ -z $SLX_BASE_PATH ]      && SLX_BASE_PATH=/opt/openslx
[ -z $SLX_PRIVATE_PATH ]   && SLX_PRIVATE_PATH=/var/opt/openslx
[ -z $SLX_PUBLIC_PATH ]    && SLX_PUBLIC_PATH=/srv/openslx
[ -z $SLX_TEMP_PATH ]      && SLX_TEMP_PATH=/tmp
[ -z $SLX_INSTALL_LOG ]    && SLX_INSTALL_LOG=install.log

PREPARE_INSTALL_TARGET="./_install/"
INSTALL_HOME=$(pwd)



# helper functions:
git_version()
{
	if [ -d .git ]; then
      GITVERSION=`git describe`
      GITMODIFIED=`(git status | grep "modified:\|added:\|deleted:" -q) && echo "-M"`
      echo $GITVERSION$GITMODIFIED
      [ -w VERSION -o ! -e VERSION ] && echo $GITVERSION > VERSION
	else
	  cat VERSION
	fi
}

versions_update()
{
	VERSION_STRING=$(git_version)
	VERSION_MAJOR=$(echo $VERSION_STRING| sed -e 's/^v//'| awk -F "." '{print $1}')
	VERSION_MINOR=$(echo $VERSION_STRING| sed -e 's/^v//'| awk -F "." '{print $2}')
	VERSION_RELEASE=$(echo $VERSION_STRING| sed -e 's/^v//'| awk -F "." '{print $3}' | sed -e 's/-.*$//')
	VERSION_BUILD=$(echo $VERSION_STRING| sed -e 's/^[^-]*-//')
	
	echo "OPENSLX_VERSION_MAJOR=\"$VERSION_MAJOR\"" > VERSIONS
	echo "OPENSLX_VERSION_MINOR=\"$VERSION_MINOR\"" >> VERSIONS
	echo "OPENSLX_VERSION_RELEASE=\"$VERSION_RELEASE\"" >> VERSIONS
	echo "OPENSLX_VERSION_STRING=\"\${OPENSLX_VERSION_MAJOR}.\${OPENSLX_VERSION_MINOR}.\${OPENSLX_VERSION_RELEASE}\${OPENSLX_VERSION_BUILD}\"" >> VERSIONS
	echo "" >> VERSIONS
	
	echo "OPENSLX_VERSION_BUILD=\"-$VERSION_BUILD\"" > BUILD
	
}

print_banner()
{
	
	echo "   ____               ______   _  __ "
	echo "  / __ \___ ___ ___  / __/ /  | |/_/ "
	echo " / /_/ / _ | -_) _ \_\ \/ /___>  <  "
	echo " \____/ .__|__/_//_/___/____/_/|_|  "
	echo "     /_/            http://www.openslx.org"
	echo -e "\nVersion: $(git_version)\n"
}

check_perl()
{
	echo -n " * checking perl"
    if ! perl -e '$x=42' 2>>${SLX_INSTALL_LOG} ; then
    	echo -e " [${LightRed}failed${NC}]"
		echo "  Perl is required, please install it.";
		exit 1;
	else
		echo -e " [${LightGreen}ok${NC}]"
	fi;
}
	

check_perl_dep()
{
	echo -n " * checking perl module dependencies"
    PERL_MODULES=$(cat tools/inc/perl.modules.base)
    [ -e .perl_modules_missing ] && rm .perl_modules_missing
    [ -e .perl_deps_guess ] && rm .perl_deps_guess
    for pm in $PERL_MODULES; do
    	perl -e "use $pm" 2>>/dev/null || echo $pm >> .perl_modules_missing;
    done
    if [ -e .perl_modules_missing ]; then
    	echo -e " [${LightRed}failed${NC}]"
    	echo "   Following perl modules are required and could not be found on your system:"
    	for pm in $(cat .perl_modules_missing); do
    		echo -n "     $pm"
    		if [ -e tools/inc/perl.modules.$DISTRO ]; then
    			GUESS_INSTALL=$(cat tools/inc/perl.modules.$DISTRO|grep $pm| awk '{print $2}')
    			if [ ! -z $GUESS_INSTALL ]; then 
    				echo " ($GUESS_INSTALL)"
    				echo "$GUESS_INSTALL" >> .perl_deps_guess
    			else
    			    echo ""
    			fi
    		else 
    			echo ""
    		fi
    	done
    	if [ -e .perl_deps_guess ]; then
	    	echo "   To install the missing dependencies run:"
    		echo -n "     apt-get install"
    		for d in $(cat .perl_deps_guess | sort -u); do
    			echo -n " $d"
    		done
    		echo ""
    		exit 1
    	fi
	else
		echo -e " [${LightGreen}ok${NC}]"
    fi
}

check_perl_db()
{
	echo -n " * checking perl db abstraction"
	DEFAULT_DB_TYPE="";
	if test -e ${SLX_CONFIG_PATH}/settings; then
    	sed ${SLX_CONFIG_PATH}/settings -e "s,=,=\"," -e "s,$,\"," > /tmp/slxsettings;
		. /tmp/slxsettings;
        rm /tmp/slxsettings;
	fi;
	
	for m in ${SLX_DB_TYPE} SQLite mysql; do
		if ! perl -Isrc/lib -Isrc/config-db -e "use OpenSLX::MetaDB::$m" 2>>${SLX_INSTALL_LOG} ; then
			echo -e "  'DBD::$m' not found (or too old), so $m-databases will not be supported.";
		else
			if test "${DEFAULT_DB_TYPE}X" = "X"; then
				DEFAULT_DB_TYPE=$m;
				echo -e " [${LightGreen}ok${NC}]"
				echo " * selected db backend: $m";
				break;
			fi;
		fi;
	done;
	if test "${DEFAULT_DB_TYPE}X" = "X"; then
		echo -e " [${LightRed}failed${NC}]"
		echo "  None of the DB-modules is available! Please install one of them.";
		exit 1;
	else
		echo ${DEFAULT_DB_TYPE} >DEFAULT-DB-TYPE;
	fi;
}	

check_helper_apps()
{
	echo -n " * checking for required linux tools"
	if ! which rsync >/dev/null 2>&1; then
		echo -e " [${LightRed}failed${NC}]"
		echo "  rsync is required, please install it.";
		exit 1;
	fi;
    echo -e " [${LightGreen}ok${NC}]"
}

_install(){
    FILE=$1
    BASE_TARGET=$2
    ADDOPTS=$3
    [ "$BASE_TARGET" = "config" ] && BASE_TARGET_PATH=${PREPARE_INSTALL_TARGET}${SLX_CONFIG_PATH}
    [ "$BASE_TARGET" = "base" ] && BASE_TARGET_PATH=${INSTALL_BASE}
	while read TYPE SOURCE TARGET; do
		if [ "$TYPE" = "f" ]; then
			cp src/${SOURCE} ${BASE_TARGET_PATH}/${TARGET}
		elif [ "$TYPE" = "d" ]; then
		    SOURCE_DIRNAME=$(echo $SOURCE | sed -e 's,^.*/,,' )
		    SOURCE_BASE=$(echo $SOURCE | sed -e 's,\(^.*/\).*,\1,')
		    [ "$SOURCE_DIRNAME" = "$SOURCE" ] && SOURCE_BASE=""
     		tar -cp $ADDOPTS -C src/${SOURCE_BASE} ${SOURCE_DIRNAME} \
     		| tar -xp -C ${BASE_TARGET_PATH}/$TARGET
		fi
	done < $FILE
	
}

prepare_install()
{
	echo -n " * prepare OpenSLX installation"
	[ "${TRACE_INSTALLATION}" = "1" ] && set -x
	INSTALL_BASE=${PREPARE_INSTALL_TARGET}${SLX_BASE_PATH}
	[ -e $PREPARE_INSTALL_TARGET ] && rm -rf $PREPARE_INSTALL_TARGET
	mkdir -p ${PREPARE_INSTALL_TARGET}
	mkdir -p ${PREPARE_INSTALL_TARGET}${SLX_CONFIG_PATH}/boot-env/syslinux/themes \
	      -p ${INSTALL_BASE}/lib \
	      -p ${INSTALL_BASE}/bin \
	      -p ${INSTALL_BASE}/share/boot-env \
	      -p ${INSTALL_BASE}/share/initramfs \
	      -p ${INSTALL_BASE}/share/squashfs \
	      -p ${INSTALL_BASE}/share/templates \
	      -p ${INSTALL_BASE}/share/ramfstools \
	      -p ${PREPARE_INSTALL_TARGET}${USR_BIN_PATH} \
	      -p ${PREPARE_INSTALL_TARGET}/lib;
	      
	# copy license
	cp COPYING ${INSTALL_BASE}/
	
	#### copy OpenSLX perl scripts & required modules ####
   	_install ./tools/inc/files.core base
   	
   	#### copy OpenSLX shared data ####
    opts="--exclude=OpenSLX --exclude=*.example" # --strip-components 1"
   	_install ./tools/inc/files.share base $opts

   	#### copy OpenSLX config data ####
    opts="--exclude=OpenSLX"
   	_install ./tools/inc/files.config config $opts

    # copy distro-info
	tar --exclude=*.example -cp -C src/lib distro-info \
	  | tar -xp -C ${PREPARE_INSTALL_TARGET}${SLX_BASE_PATH}/share
	tar --exclude=prereqfiles --exclude=trusted-package-keys/* \
	    --exclude=*.default --exclude=mirrors \
	    -cp -C src/lib distro-info \
	  | tar -xp -C ${PREPARE_INSTALL_TARGET}${SLX_CONFIG_PATH}

    ### link slx binarires ###
	for f in $(ls -1 $PREPARE_INSTALL_TARGET/$SLX_BASE_PATH/bin )
	do
		ln -sf $SLX_BASE_PATH/bin/$(basename $f) ${PREPARE_INSTALL_TARGET}${USR_BIN_PATH}/
	done
	
	### deprecated.. ###
	ln -sf ${SLX_BASE_PATH}/share/uclib-rootfs/lib/ld-uClibc.so.0 \
		${PREPARE_INSTALL_TARGET}/lib/ld-uClibc.so.0

	echo -e " [${LightGreen}ok${NC}]"

}

make_install_tarball()
{
	cd $INSTALL_HOME
	[ -d  $PREPARE_INSTALL_TARGET ] || prepare_install
    local COMPRESSION=$1
    local ALTERNATIVE_PREFIX=$2
	[ "x$COMPRESSION" = "x" ] && \
		echo -n " * create OpenSLX install tarball"
	[ "x$COMPRESSION" = "x" ] || \
		echo -n " * create OpenSLX install tarball (compressed with $COMPRESSION)"
	VERSIONSTRING="openslx-$(git_version)"
	if [ ! -f $VERSIONSTRING.tar ]; then
		cd $PREPARE_INSTALL_TARGET 
		if [ "x$ALTERNATIVE_PREFIX" = "x" ]; then
			OPT=""
		else
			OPT=" --transform \"s,^,/$ALTERNATIVE_PREFIX/,S\" "
		fi
		#HACK .. otherwise tar doesn't like parameters..
		CMD="tar $OPT -c -f ../$VERSIONSTRING.tar *"
		sh -c "$CMD"
		cd - 2>&1 >/dev/null
	fi
	rm -rf  $PREPARE_INSTALL_TARGET
	COMPRESSION_KEEP_ORIG="-k"
	[ "x$COMPRESSION" = "xgzip" ] && COMPRESSION_KEEP_ORIG=""
    [ "x$COMPRESSION" = "x" ] || $COMPRESSION -f $COMPRESSION_KEEP_ORIG $VERSIONSTRING.tar 
	echo -e " [${LightGreen}ok${NC}]"
}	

make_source_tarball()
{
    local COMPRESSION=$1
    local ALTERNATIVE_PREFIX=$2
	[ "x$COMPRESSION" = "x" ] && \
		echo -n " * create OpenSLX source tarball"
	[ "x$COMPRESSION" = "x" ] || \
		echo -n " * create OpenSLX source tarball (compressed with $COMPRESSION)"
	VERSIONSTRING="openslx-$(git_version)-src"
	if [ "x$ALTERNATIVE_PREFIX" = "x" ]; then
		PREFIX="openslx-$(git_version)-src"
	else
		PREFIX=$ALTERNATIVE_PREFIX
	fi
	git archive --format=tar --prefix=$PREFIX/ -o $VERSIONSTRING.tar HEAD
    [ "x$COMPRESSION" = "x" ] || $COMPRESSION -f $VERSIONSTRING.tar
	echo -e " [${LightGreen}ok${NC}]"
}

prepare_upgrade()
{
	echo -n " * cleanup old OpenSLX installation before upgrade"
	rm -rf ${SLX_BASE_PATH}
	rm -f ${USR_BIN_PATH}/slx*
	echo -e " [${LightGreen}ok${NC}]"
}

do_install()
{
	echo -n " * installing OpenSLX"
	if [ ! "$(whoami)" = "root" ]; then
		echo -e " [${LightRed}failed${NC}]"
		echo "   you need to be root"
		exit 1
	fi
	make_install_tarball  >>${SLX_INSTALL_LOG} 2>&1
	VERSIONSTRING="openslx-$(git_version)"
	cd ${SLX_BUILD_PATH}/; tar xf $INSTALL_HOME/$VERSIONSTRING.tar
	cd $INSTALL_HOME
	echo -e " [${LightGreen}ok${NC}]"
}

uninstall()
{
	echo -n " * Uninstalling OpenSLX project files but keeping configs and stage1"
	rm -rf ${SLX_BASE_PATH}
	rm -rf ${SLX_PUBLIC_PATH}
	rm -f ${USR_BIN_PATH}/slx*
	rm -f /lib/ld-uClibc.so.0
	echo -e " [${LightGreen}ok${NC}]"
	echo "    left config files in ${SLX_CONFIG_PATH} untouched"
	echo "    left config files in ${SLX_PRIVATE_PATH} untouched"
}

mrproper()
{
	echo -e "${LightRed}*warning*${NC} This will remove all cloned/exported OpenSLX systems from your machine!" 
	echo -n "Press <Ctrl>-C to abort.. "
	for i in 4 3 2 1
	do 
	   echo -n "$i.."
	   sleep 1
	done
	echo "0"
	echo -n " * Wiping all!"
	rm -rf ${SLX_BASE_PATH}
	rm -rf ${SLX_CONFIG_PATH}
	rm -rf ${SLX_PRIVATE_PATH}
	rm -rf ${SLX_PUBLIC_PATH}
	rm -f ${USR_BIN_PATH}/slx*
	echo -e " [${LightGreen}ok${NC}]"
}

check_upgrade()
{
	# find out if there is an older version installed and, if so, clean that
	INSTALLED_VERSION=$(slxversion 2>/dev/null)
	if ! test -z "${INSTALLED_VERSION}"; then
		. ./BUILD
		. ./VERSIONS
		if test ${INSTALLED_VERSION} != ${OPENSLX_VERSION_STRING}; then
			echo " * preparing upgrade from version (${INSTALLED_VERSION})"
			prepare_upgrade;
		else
		    echo " * reinstall current version (${INSTALLED_VERSION})"
		fi;
	fi
}

post_install()
{
	echo " * run postinstall"
	
	# create default config folder hierarchy:
	perl -Isrc/lib -e 'use OpenSLX::ConfigFolder; createConfigFolderForDefaultSystem();'

	# create complete default settings and empty local settings file:
	sed -e "s,###SLX_BASE_PATH###,$SLX_BASE_PATH," \
	    -e "s,###SLX_CONFIG_PATH###,$SLX_CONFIG_PATH," \
	    -e "s,###SLX_PRIVATE_PATH###,$SLX_PRIVATE_PATH," \
	    -e "s,###SLX_PUBLIC_PATH###,$SLX_PUBLIC_PATH," \
	    -e "s,###SLX_TEMP_PATH###,$SLX_TEMP_PATH," \
	    ./tools/inc/openslx.settings.dist \
	> $SLX_BUILD_PATH/$SLX_BASE_PATH/share/settings.default

	if [ ! -e $SLX_BUILD_PATH/$SLX_CONFIG_PATH/settings ]; then
		# create complete default settings and empty local settings file:
		sed -e "s,###SLX_BASE_PATH###,$SLX_BASE_PATH," \
		    ./tools/inc/openslx.settings \
		> $SLX_BUILD_PATH/$SLX_CONFIG_PATH/settings
	fi

	. ./BUILD
	. ./VERSIONS

	echo -e "#! /bin/sh\n\necho ${OPENSLX_VERSION_STRING}" \
	    > $SLX_BUILD_PATH/$SLX_BASE_PATH/bin/slxversion
	chmod a+x $SLX_BUILD_PATH/$SLX_BASE_PATH/bin/slxversion
	ln -sf $SLX_BASE_PATH/bin/slxversion $SLX_BUILD_PATH/$USR_BIN_PATH

	# set default db-type:
	DEFAULT_DB_TYPE=$(cat DEFAULT-DB-TYPE)
	rm DEFAULT-DB-TYPE
	echo -n "    o "
	slxsettings set db-type="${DEFAULT_DB_TYPE}";
}

build_dpkg_package()
{
	make_install_tarball
	
	dpkg_deb=`which dpkg-deb`
	if [ -z "$dpkg_deb" ];then 
	    echo "You need the program dpkg-deb (contained in package dpkg) to build a debian package"
	    exit
	fi
	
	# import default paths for debian installation
	. ./packaging/dpkg/debianpaths
	
	# change into folder where we expect the Makefile:
	if [ ! -e ./Makefile ]; then
	    echo "There is no makefile in this programs directory (`pwd`)."
	    echo "Please run this script only embedded in the context of an openslx checkout."
	    exit
	fi

	echo -n " * Building DEB Package(s)"
	
	export SLX_DEPBUILD_PATH=/tmp/slx-dep-$$
	mkdir -p $SLX_DEPBUILD_PATH
	
	VERSIONSTRING="openslx-$(git_version)"
	
	cd $SLX_DEPBUILD_PATH
	tar xf $INSTALL_HOME/$VERSIONSTRING.tar
	cd $INSTALL_HOME
	
	#Create Temporary working directory
	mkdir -p $SLX_DEPBUILD_PATH/DEBIAN
	cp packaging/dpkg/default_files/control  $SLX_DEPBUILD_PATH/DEBIAN/
	cp packaging/dpkg/default_files/pre*     $SLX_DEPBUILD_PATH/DEBIAN/
	cp packaging/dpkg/default_files/post*    $SLX_DEPBUILD_PATH/DEBIAN/

    OPENSLX_VERSION=$(git describe)


	sed -i -e "4r./packaging/dpkg/debianpaths" \
    	$SLX_DEPBUILD_PATH/DEBIAN/postinst

	#update control file
	sed -e "s/##version##/$OPENSLX_VERSION/" \
	    -e "s/##size##/$(du -s $SLX_BUILD_PATH | awk '{print $1}')/" \
	    -i  $SLX_DEPBUILD_PATH/DEBIAN/control
	
	#Set permissions
	find $SLX_DEPBUILD_PATH -type d|xargs chmod 755
	
	#Create the package
	dpkg-deb --build $SLX_DEPBUILD_PATH > /dev/null
	cd packaging/dpkg
	
	echo -e " [${LightGreen}ok${NC}]"

	mkdir -p $INSTALL_HOME/pkgs/
	cp  $SLX_DEPBUILD_PATH.deb $INSTALL_HOME/pkgs/$VERSIONSTRING.deb
	cd $INSTALL_HOME
	rm -rf $SLX_DEPBUILD_PATH
}

build_rpm_package()
{
	
	VERSIONSTRING="openslx-$(git_version)"

    OPENSLX_VERSION=$(git describe | sed -e 's/-.*$//' -e 's/^v//')
    OPENSLX_REVISION=$(git_version | sed -e 's/[^-]*-//' -e 's/-/_/g')

	rpm_builder=`which rpmbuild`
	if [ -z "$rpm_builder" ];then 
	    echo "You need the program rpmbuild (contained in package ?!?) to build a rpm package"
	    exit
	fi

	# change into folder where we expect the Makefile:
	if [ ! -e ./Makefile ]; then
	    echo "There is no makefile in this programs directory (`pwd`)."
	    echo "Please run this script only embedded in the context of an openslx checkout."
	    exit
	fi

	export SLX_RPMBUILD_PATH=/tmp/slx-rpm-$$
	mkdir -p $SLX_RPMBUILD_PATH
	mkdir -p $SLX_RPMBUILD_PATH/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
	
	#make_source_tarball gzip "openslx-$OPENSLX_VERSION"
    #make_install_tarball
    #tar -tf $VERSIONSTRING.tar > $SLX_RPMBUILD_PATH/FILES
    #sed -i $SLX_RPMBUILD_PATH/FILES -e 's,^,/,'
    
    [ -f $VERSIONSTRING.tar ] && rm  $VERSIONSTRING.tar
	make_install_tarball gzip "openslx-$OPENSLX_VERSION"

	mv $VERSIONSTRING.tar.gz $SLX_RPMBUILD_PATH/SOURCES/openslx-v$OPENSLX_VERSION-$OPENSLX_REVISION.tar.gz

	echo -n " * Building RPM Package(s)"

	#update control file
	sed   -e "s/###version###/$OPENSLX_VERSION/" \
	      -e "s/###release###/$OPENSLX_REVISION/" \
	      -e "/###authors###/r AUTHORS" \
	      -e "/###authors###/d" \
	      packaging/rpm/openslx.spec \
	      > $SLX_RPMBUILD_PATH/SPECS/openslx.spec
	[ "x$ARCH" = "x" ] || ARCH="--target=$ARCH"
	rpmbuild --nodeps -ba --define "_topdir $SLX_RPMBUILD_PATH" \
	      $SLX_RPMBUILD_PATH/SPECS/openslx.spec >>${SLX_INSTALL_LOG} 2>&1
	      
	if [ "$(ls -1 $SLX_RPMBUILD_PATH/RPMS)" = "x86_64" ]; then
		rpmbuild --target="i386" --nodeps -ba --define "_topdir $SLX_RPMBUILD_PATH" \
	      $SLX_RPMBUILD_PATH/SPECS/openslx.spec >>${SLX_INSTALL_LOG} 2>&1
	fi
	
	echo -e " [${LightGreen}ok${NC}]"
	
	mkdir -p $INSTALL_HOME/pkgs/
	#echo "find  $SLX_RPMBUILD_PATH/RPMS/ -iname *.rpm -exec cp {} $INSTALL_HOME/pkgs/ \;"
	sh -c "find  $SLX_RPMBUILD_PATH/RPMS/ -iname  \"*.rpm\" -exec cp {} $INSTALL_HOME/pkgs/ \;"
	rm -rf $SLX_RPMBUILD_PATH
	
}

cleanup_tmpfiles()
{
	rm -f openslx-*.tar
	rm -rf _install
}

check_permissions()
{
	if [ ! "x$(whoami)" = "xroot" ]; then
		echo "You need to be root to run installer.."
		exit 1
	fi
}
	
clean()
{
	echo -n " * Cleanup OpenSLX source directory"
	for file in ${SLX_INSTALL_LOG} VERSION openslx-*.tar openslx-*.tar.*; do
		rm -f ${file}
	done
	rm -rf _install
	echo -e " [${LightGreen}ok${NC}]"
}


cmd_usage()
{
	echo "Usage: ..."
	echo "  plain-install"
	echo "  install"
	echo "  build-rpm"
	echo "  build-deb"
	echo "  clean"
	echo "  mrproper"
}

cmd_plain_install()
{
	echo "running plain install:"	
	do_install
}

cmd_install()
{
	echo "running full install"
	versions_update
	check_perl
	check_perl_dep
	check_perl_db
	check_helper_apps
	check_upgrade
	do_install
	post_install
}

cmd_build_rpm()
{
	echo "creating rpm package(s)"
	build_rpm_package
}

cmd_build_deb()
{
	echo "creating deb package"
	build_dpkg_package
}


cmd_build_tarball()
{
	echo "creating deb package"
	make_install_tarball bzip2
	mkdir -p pkgs/
	cp openslx*.tar.bz2 pkgs/
}

cmd_clean()
{
	echo "Cleanup source directory"
	clean
}

cmd_uninstall()
{
	echo "normal uninstall"
	uninstall
}

cmd_mrproper()
{
    echo "Remove all OpenSLX files from the system"
	mrproper
}


print_banner
check_permissions

versions_update

case "$1" in
	"plain-install")
       cmd_plain_install	
	   ;;
	"install")
       cmd_install	
	   ;;
	"build-rpm")
       cmd_build_rpm
	   ;;
	"build-deb")
       cmd_build_deb	
	   ;;
	"build-tarball")
       cmd_build_tarball	
	   ;;
	"uninstall")
       cmd_uninstall
	   ;;
	"clean")
       cmd_clean
	   ;;
	"mrproper")
       cmd_mrproper	
	   ;;
	 *)
	   cmd_usage
	   ;;
esac

cleanup_tmpfiles

#make_install_tarball
#make_install_tarball gzip
#make_install_tarball bzip2
#make_install_tarball lzma
#make_source_tarball
#make_source_tarball gzip
#make_source_tarball bzip2
#make_source_tarball lzma
#git_version