summaryrefslogblamecommitdiffstats
path: root/tools/installer
blob: 4b10d1022d09ab7e42d218777a845026f61c7d6c (plain) (tree)
1
2
3
4
5
6
7
8

           
                                

                  
                                                               

                       





                                                                            
 
                       







                                                               
                                    
                   
 

 


                   
                            


                                                                                     
                                                                  


                     

 













                                                                                                                                                              
                                                                


        










                                                         
            
 













                                                              
































                                                                                                      
                                                 


      























                                                                                                             
                                                                                                                                     

                       
                                                         
















































                                                                                                 

                                                           







                                                              
                                                                        





                                                      








                                                                      



                                                                                                  

                            

                                                                        
 




                                         
 

                                                          
                        
                               



                                                                                          
                                              

                                            







                                                                           

                                    
                                       


                                                                                           




                                         
                        
                               



                                                                                         
                                                  





                                                                             



















                                                                    
                                                       
                                              

                                                                      
                                         















                                                                                      







                                                                                                                    













                                                                                

                            


                                                                                       

                                                                              



                   
              
 

                                 
                                                 
                                                                                            

                                                                         




                                                              
                                               





















                                                                                 




















                                                                                                      

                                            
        

                                                
        

                                              
                             



                                               



                                                                           




                                                    
                                          
 

                                                                               
                            
                                              
                                                                          
                                                 

                        
                                                       

                           
                                                       
                         



                                         
                                                                        
                        
                                 

 


                   
















                                                                                                  
 


                                                                    







                                                            
 
                                                                                                              
 
                                            







                                                       
                                                   
                                                                     









                                                                                             
                                                                                              

                                                                                                   

        













                                                             
        


                                                     
                                                                                

                             
                       
                                         

 
 




                              



                          










                                        
                       


                      

                         
                  
                    



               
                                      


                         
               

                                   
                          

 
 



                                   

                                 




















                                                   
            
                 
 

               







                                
                    
             













                                




                    
 

                







                           
            
#!/bin/bash

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

[ -f /etc/opt/openslx/settings ] && . /etc/opt/openslx/settings

# determin distribution
if [ ! -z $(which lsb_release) ]; then
  DISTRO=$(lsb_release -i| sed 's/^[^:]*:\t//' | tr '[:upper:]' '[:lower:]')
else
  # Can't determin distro version..
  DISTRO=""
fi

# 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 (libdbd-sqlite3-perl or libdbd-mysql-perl).";
		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

        PKG_VERSION=$(echo $OPENSLX_VERSION | sed -e "s/^v//" -e "s/-[^-]*$//")

	#update control file
	sed -e "s/##version##/$PKG_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