summaryrefslogblamecommitdiffstats
path: root/tools/installer
blob: 184011104d16765205da1dd7e162873f9c1c71c5 (plain) (tree)
1
2
3
4
5
6





                                                                          







                                                               
                                    








                                                                                   
            
 













                                                              
































                                                                                                      
                                                 


      

































































































                                                                                                             
 
                                                   

                                                      










                                                      

                                                                                    
                                         

 








                                        
          
#!/bin/bash

. tools/inc/colors

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

[ -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/"

# helper functions:
git_version()
{
    GITVERSION=`git describe`
    GITMODIFIED=`(git status | grep "modified:\|added:\|deleted:" -q) && echo "-M"`
    echo $GITVERSION$GITMODIFIED
}

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};
	      
	# 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

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

}

make_install_tarball()
{
	echo -n " * create OpenSLX install tarball"
	VERSIONSTRING="openslx-$(git_version)"
	rm -rf $VERSIONSTRING.tar $VERSIONSTRING.tar.*
	cd $PREPARE_INSTALL_TARGET 
	tar cfj ../$VERSIONSTRING.tbz2 *
	cd - 2>&1 >/dev/null
	echo -e " [${LightGreen}ok${NC}]"
}	

make_source_tarball()
{
	echo -n " * create OpenSLX source tarball"
	VERSIONSTRING="openslx-$(git_version)-src"
	rm -rf $VERSIONSTRING.tar $VERSIONSTRING.tar.*
	git archive --format=tar --prefix=$VERSIONSTRING/ -o $VERSIONSTRING.tar HEAD
	bzip2 $VERSIONSTRING.tar
	echo -e " [${LightGreen}ok${NC}]"
}



check_perl
check_perl_dep
check_perl_db
check_helper_apps
prepare_install
make_install_tarball
#make_source_tarballmake_install_tarball
git_version