#!/bin/sh
VERSION="@VERSION@"
pgmname=$0
colecho () {
local TCOL=
case "$2" in
b)
TCOL="\033[30m";
;;
rd)
TCOL="\033[31m";
;;
gn)
TCOL="\033[32m";
;;
br)
TCOL="\033[33m";
;;
bl)
TCOL="\033[34m";
;;
mg)
TCOL="\033[35m";
;;
cy)
TCOL="\033[36m";
;;
w)
TCOL="\033[37m";
;;
*)
# normal
TCOL="\033[0m";
;;
esac
echo -e "$TCOL$1\033[0m"
}
error () {
colecho "$1" rd
}
end () {
exit
}
read_controlfile () {
local file=$1
local tmp=
local n=0
package_name=
package_short=
package_section=
package_version=
package_date=
package_author_n=0
package_author_0=
package_status=
package_source_n=0
package_source_0=
package_require_n=0
package_require_0=
package_description_n=0
package_description_0=
package_additionalfiles=
package_sourcecode_n=0
package_sourcecode_0_filename=
package_sourcecode_0_directory=
package_sourcecode_0_rulesfile=
while read line
do
case $line in
Package:*)
package_name="`echo $line | sed 's/^Package: //'`"
;;
Short:*)
package_short="`echo $line | sed 's/^Short: //'`"
;;
Section:*)
package_section="`echo $line | sed 's/^Section: //'`"
;;
Version:*)
package_version="`echo $line | sed 's/^Version: //'`"
;;
Date:*)
package_date="`echo $line | sed 's/^Date: //'`"
;;
Author:*)
tmp="`echo $line | sed 's/^Author: //'`"
eval package_author_$package_author_n='"$tmp"'
package_author_n=`expr $package_author_n + 1`
;;
Status:*)
package_status="`echo $line | sed 's/^Status: //'`"
;;
AdditionalFiles:*)
package_additionalfiles="`echo $line | sed 's/^AdditionalFiles: //'`"
;;
Source:*)
tmp="`echo $line | sed 's/^Source: //'`"
eval package_source_$package_source_n='"$tmp"'
package_source_n=`expr $package_source_n + 1`
;;
Require:*)
tmp="`echo $line | sed 's/^Require: //'`"
eval package_require_$package_require_n='"$tmp"'
package_require_n=`expr $package_require_n + 1`
;;
Description:*)
tmp="`echo $line | sed 's/^Description: //'`"
eval package_description_$package_description_n='"$tmp"'
package_description_n=`expr $package_description_n + 1`
;;
Sourcecode_N:*)
package_sourcecode_n="`echo $line | sed 's/^Sourcecode_N: //'`"
;;
Sourcecode_*_Filename:*)
n="`echo $line | sed 's/^Sourcecode_//;s/_Filename:.*//'`"
n=`expr $n - 1`
tmp="`echo $line | sed 's/^Sourcecode_[0-9]*_Filename://'`"
tmp=`echo $tmp`
eval package_sourcecode_${n}_filename='"$tmp"'
;;
Sourcecode_*_Directory:*)
n="`echo $line | sed 's/^Sourcecode_//;s/_Directory:.*//'`"
n=`expr $n - 1`
tmp="`echo $line | sed 's/^Sourcecode_[0-9]*_Directory://'`"
tmp=`echo $tmp`
eval package_sourcecode_${n}_directory='"$tmp"'
;;
Sourcecode_*_Rulesfile:*)
n="`echo $line | sed 's/^Sourcecode_//;s/_Rulesfile:.*//'`"
n=`expr $n - 1`
tmp="`echo $line | sed 's/^Sourcecode_[0-9]*_Rulesfile://'`"
tmp=`echo $tmp`
eval package_sourcecode_${n}_rulesfile='"$tmp"'
;;
esac
done < $file
}
unpack () {
local file=$1
cd `dirname $file` && (
case $file in
*.tar.gz)
tar xvzf $file
;;
*.tar.bz2)
tar xvjf $file
;;
esac
)
}
run_make () {
local makefile=$1
local target=$2
local directory=$3
local options=$4
(cd $directory;make -f $makefile $options $target)
}
write_infofile () {
local file=$1
local i=0
mkdir -p `dirname $file`
(
echo ""
echo ""$package_name""
echo ""$package_short""
echo ""
echo ""$package_version""
echo ""$package_date""
echo ""$package_status""
i=0
while [ $i -lt $package_author_n ]
do
eval author='$package_author_'$i
echo ""$author""
i=`expr $i + 1`
done
i=0
while [ $i -lt $package_source_n ]
do
eval source='$package_source_'$i
echo ""$source""
i=`expr $i + 1`
done
echo ""
echo
i=0
while [ $i -lt $package_description_n ]
do
eval description='$package_description_'$i
echo $description
i=`expr $i + 1`
done
echo ""
echo ""
echo ""$VERSION""
echo ""
echo ""
) > $file
}
copy_additionalfiles () {
local source=$1
local target=$2
local i=
cp -p -R $source/* $target
}
write_filelist () {
local list=$1
cd $outputdir && if [ ! -d `dirname $list` ];then mkdir -p `dirname $list`;fi && (
find -type b
find -type c
find -type p
find -type f
find -type l
find -type s
) | sed 's/^\.//' | grep -v "^/tmp" > $list
}
packit () {
local directory=$1
local file=$2
cd $directory &&
if [ -f $file ];then rm -f $file;fi &&
(
options="--owner=0 --group=0"
if [ "$options_bz2" = "1" ]
then
tar $options -cjf $file *
else
tar $options -czf $file *
fi
)
}
version () {
echo "eisbuild $VERSION"
}
usage () {
version
echo
echo "(c)2002 by Michael Hanselmann. All rights reserved."
echo "This software is released under the terms of the GPL-license."
echo
echo "usage: `basename $pgmname` [options1] [options2]"
echo
echo "Available options for options1:"
echo " --help general help"
echo " --debug enable debugmode"
echo " --controlfile= name of the controlfile"
echo
echo "action is one of: unpack, distclean, clean, build or pack"
echo "use `basename $pgmname` --help for options"
echo
case $1 in
clean|distclean|unpack)
echo "Available options for options2:"
echo " no options"
echo
;;
pack)
echo "Available options for options2:"
echo " --to-bz2 pack to a .tar.bz2-archive instead of a .tar.gz-archive"
echo
;;
build)
echo "Available options for options2:"
echo " --forcebuild do a build even if it's not really needed"
echo
;;
esac
}
unknown_option () {
error "unknown option: $1"
usage
end
}
unknown_action () {
error "unknown action: $1"
end
}
# set defaults
options_debug=0
options_clean=0
options_build=0
options_distclean=0
options_pack=0
options_bz2=0
options_forcebuild=0
options_unpack=0
options_action=
controlfile=control
buildsuccessfullfile=".eisbuild_build_successfull"
rootdir="`pwd`"
while [ $# -gt 0 ]
do
case $1 in
--*)
case $1 in
--help)
usage
end
;;
--debug)
options_debug=1
;;
--controlfile=*)
controlfile=`echo $1 | sed 's/^--controlfile=//'`
;;
*)
unknown_option $1
;;
esac
;;
*)
options_action=$1
break;
;;
esac
shift
done
shift
if [ "$options_action" = "" ]
then
usage
end
fi
case $options_action in
unpack)
options_unpack=1
;;
distclean)
options_distclean=1
options_unpack=0
;;
clean)
options_clean=1
options_unpack=1
;;
build)
options_build=1
options_unpack=1
;;
pack)
options_pack=1
options_unpack=1
options_build=1
;;
*)
unknown_action $options_action
end
;;
esac
while [ $# -gt 0 ]
do
case $1 in
--to-bz2)
if [ "$options_pack" = "1" ]
then
options_bz2=1
fi
;;
--forcebuild)
if [ "$options_build" = "1" ]
then
options_forcebuild=1
fi
;;
--help)
usage $options_action
end
;;
*)
unknown_option $1
;;
esac
shift
done
if [ "$options_debug" = "1" ]
then
set -x
fi
outputdir="$rootdir/output"
if [ ! -f $rootdir/$controlfile ]
then
error "$rootdir/$controlfile not found."
end
fi
if [ "$options_distclean" = "1" -o "$options_pack" = "1" ]
then
rm -rf $outputdir
fi
if [ ! -d $outputdir -a "$options_distclean" != "1" ]
then
mkdir $outputdir
fi
read_controlfile $rootdir/$controlfile || end
infofile="$outputdir/var/install/packages/$package_name"
filelist_short="tmp/filelist"
filelist="$outputdir/$filelist_short"
additionalfiles="$package_additionalfiles"
rm -f $outputdir/$package_name.tar.bz2
rm -f $outputdir/$package_name.tar.gz
if [ "$options_bz2" = "1" ]
then
outputarchive="$outputdir/$package_name.tar.bz2"
else
outputarchive="$outputdir/$package_name.tar.gz"
fi
i=0
while [ $i -lt $package_sourcecode_n ]
do
eval filename='$package_sourcecode_'$i'_filename'
eval directory='$package_sourcecode_'$i'_directory'
eval rulesfile='$package_sourcecode_'$i'_rulesfile'
if [ "$options_distclean" = "1" -a "$directory" != "" ]
then
rm -rf $rootdir/$directory
i=`expr $i + 1`
continue
fi
if [ ! -d $rootdir/$directory -a "$options_unpack" = "1" -a "$options_clean" != "1" ]
then
if [ -f $rootdir/$filename ]
then
echo "unpack $filename"
unpack $rootdir/$filename
run_make "$rootdir/$rulesfile" "patch" "$rootdir/$directory" "INSTALLDIR=\"$outputdir\" SOURCEDIR=\"$rootdir/$directory\""
fi
else
if [ -d $rootdir/$directory ]
then
echo "unpack: nothing todo"
fi
fi
if [ -d $rootdir/$directory -a "$directory" != "" ]
then
if [ "$options_clean" = "1" ]
then
rm -f $rootdir/$directory/$buildsuccessfullfile
run_make "$rootdir/$rulesfile" "clean" "$rootdir/$directory" "INSTALLDIR=\"$outputdir\" SOURCEDIR=\"$rootdir/$directory\""
fi
if [ "$options_build" = "1" ]
then
if [ "$options_forcebuild" = "1" -o ! -f "$rootdir/$directory/$buildsuccessfullfile" ]
then
run_make "$rootdir/$rulesfile" "build" "$rootdir/$directory" "INSTALLDIR=\"$outputdir\" SOURCEDIR=\"$rootdir/$directory\""
if [ $? = 0 ]
then
echo "build-successfull" > $rootdir/$directory/$buildsuccessfullfile
fi
else
echo "no build needed, use --forcebuild if you want to build even if it's not needed"
fi
fi
if [ "$options_pack" = "1" ]
then
run_make "$rootdir/$rulesfile" "install" "$rootdir/$directory" "INSTALLDIR=\"$outputdir\" SOURCEDIR=\"$rootdir/$directory\""
fi
elif [ "$directory" != "" ]
then
options_package=0
fi
i=`expr $i + 1`
done
if [ "$options_pack" = "1" ]
then
copy_additionalfiles $rootdir/$additionalfiles $outputdir
write_infofile $infofile
write_filelist $filelist
echo "Packing into $outputarchive"
packit $outputdir $outputarchive
fi