i have troubles with the function ver () from a script of which the goal is to produce a structured/ ordered build list dependencies from cvsdb (a modules database)
i show you all needed scripts (exept the builds scripts which are not needed to run test via 'build --mad' )
i would be happy to understand what's wrong because i'm a little lost in this raw produced script
#!/bin/bash
#/usr/sbin/build
#this is the core of BUILD CVS
#
bliscat.sirtakys@tele2.fr GPL
#need functions cvs_db cvsdb cvs wget gawk patch make (build scripts are made for LFS-CVS-20040601 (gcc-3.4.1))
export RD=/var/cvs
SCRIPT=/etc/scripts
source $SCRIPT/fonctions
case "$1" in
--mad)
mad
;;
esac
now the fuction referencies for build script
#this is the function definition for BUILD CVS
#
bliscat.sirtakys@tele2.fr GPL
# there are bugs in function ver (), ver2 () and probably mkd ()
#be aware of the fact we use an binary result in test so anything else from YES/NO generaly produce an error
dat () # return the date + hour
{
date '+%y%m%d%H'
}
ccr () # check for required dirs / make it / cd to
{
if [ ! -d "$RD/$1" ] ; then rm -f "$RD/$1" ; install -d "$RD/$1" ; fi
cd "$RD/$1"
}
csd () # change directory to source directory + ccr ()
{
ccr "$1"
cd "$RD/$1/$1"
}
run () # return the name of the build script
{
cvs_db --script "$1"
}
typ () # return the type of the requested module CVS or Tarball
{
cvs_db --type "$1"
}
dep () # return a list containing the DIRECT dependancies of the requested module
{
cvs_db --deps "$1"
}
url () # return the needed parameter to get the source from CVS or the URL for the Tarball
{
cvs_db --server "$1"
}
moe () # check if module exist
{
if [ -z "$(cvs_db --type "$1")" ] ; then echo "NO" ; else echo "YES" ; fi
}
mfp () # check if module was successfully updated by us
{
ccr $1
if [ -f "$1.sync" ] ; then echo "YES"; else echo "NO" ; fi
}
mkc () # just mark module source directory to said that we have get module successfully
{
csd "$1" ; dat > ../"$1".sync
}
# fonctions de niveau 2
mup () # check if anything look good to build the requested module now
{
ccr "$1"
if [ $"(mfp "$1")" = "YES" ] && [ "`cat "$1.sync"`" = "dat" ]
then echo "YES"
else echo "NO"
fi
}
mau () # check if anything look good to build the requested module after "having" updated it
{
ccr "$1"
if [ "$(mfp "$1")" = "YES" ] && [ "`cat "$1.sync"`" != "dat" ]
then echo "YES"
else echo "NO"
fi
}
get () # just get or download
{
ccr "$1"
if [ "$(typ "$1")" = "CVS" ]
then cvs -q -z3 -d"$(url "$1")" get "$1" 2>&1 > /dev/null ; mkc "$1" ; fi
if [ "$(typ "$1")" = "SRC" ]
then csd $RD "$1" ; wget "$(url "$1")" 2>&1 > /dev/null ; mkc "$1" ; fi
}
gmf ()
{
if [ "$(moe "$1")" = "YES" ] ; then get "$1" 2>&1 > /dev/null ; fi
}
upm () # just update or download
{
csd "$1"
if [ "$(typ "$1")" = "CVS" ]
then cvs -q -z3 -d"$(url "$1")" update 2>&1 > /dev/null ; mkc "$1" ; fi
if [ "$(typ "$1")" = "SRC" ]
then get "$1" 2>&1 > /dev/null ; fi
}
mku () # this little function decides how to make modules able to build
{
ccr "$1"
if [ "$(run "$1")" = "NO" ] ; then echo "YES" ; return 0 ; fi
if [ "$(moe "$1")" = "YES" ] ; then
if [ "$(mup "$1")" = "YES" ] ; then echo "YES" ; fi
if [ "$(mau "$1")" = "YES" ] ; then upm "$1" 2>&1 > /dev/null && echo "YES"
else gmf "$1" 2>&1 > /dev/null && echo "YES"
fi
else
echo "NO"
fi
}
ext ()
{
gawk -v MOD="$1" '{FS=" "}
$1 == MOD { print "DUPLICATED" }' "$2.dep.raw"
}
mcl () # kindly one of the most important things : reorder the build list
{
ccr "$1"
cat "$1.dep.raw" | tac > "$1.dep"
}
ddb ()
{
gawk -v MOD="$1" '{FS=" "}
$1 == MOD { print "DUPLICATING" }' "$RD/MODULES.LOCK"
}
# Argh now one checks the order of the dependences for each dependence of the preceding list of not ordered dependence
# if "$(moe "$DEPS")" is null/empty so it need nothing
# HERE COMES THE BUG
isgood () # an other sipmle use of gawk witch aims to accelerate the process
{
gawk -v MOD="$1" '{FS="#"}
$1 == MOD { print "YES" }' "$2.dep.good"
}
ver2 () # whooo matters with '#' ? not in off but sed made some on name like gimp and gimp-print it's why i use those protection symbols
{
for MODP in `cat "$1.dep.nogood"`
do
teu () # i guess but i prefer KOF
{
for DEPS in `cat "$(echo "$RD/$1/$1.dep" | sed 's/\#//g' )"`
do
if [ -z "$(isgood "$DEPS" "$2")" ]
then echo "NO"
break
fi
done
}
if [ "$(teu "$MODP" "$1")" != "NO" ]
then echo "$MODP" | sed 's/\#//g' >> "$1.dep.good"
sed -i '/\#\'"$MODP"'\#/d' "$1.dep.nogood"
echo -n "."
fi
done
while [ -n "$(cat "$1.dep.nogood")" ]
do
echo -n "#"
ver2 "$1"
done
}
ver ()
{
echo -n "Checking dependency order ..."
ccr "$1"
rm -f "$1.dep."*
if [ "$(cat "$1.dep")" != "$1" ]
then
for MOD in `cat "$1.dep"`
do
if [ -z "$(dep "$MOD")" ] ; then echo "$MOD" >> "$1.dep.good"
echo -n "."
else echo "#$MOD#" >> "$1.dep.nogood" ; fi
done
ver2 "$1"
echo " done"
sed 's/\#//g' "$1.dep.good" > "$1.dep"
rm -f "$1.dep."*
else
echo " done"
fi
}
# argh ! my nightmare : the dependencies... ( just have a look to the db) (this is why i have made thoses scripts)
# so, first put the name of our mod to the build list
# second, put recursively each dependencies... and check before they exist and more that they weren't build before
# this will really increase the speed of the process ( you should before test your db by --test-db option in cvs_db)
mkd ()
{
echo -n "Making dependencies for $1"
if [ ! -f "$RD/MODULES.LOCK" ] ; then echo "" > "$RD/MODULES.LOCK" ; fi # prevent from output error from ddb
ccr "$1" # go to dir
echo "$1" > "$1.dep.raw" # put the name in bl (build list)
BM="$1" # save the final module
dal () # define the recursive function
{
for DEPS in $(dep "$1")
do
if [ "$(moe "$DEPS")" = "YES" ] ; then
if [ ! -z "$DEPS" ] && [ "$(ext "$DEPS" "$BM")" != "DUPLICATED" ] # same as upper
then echo "$DEPS" >> "$BM.dep.raw"
echo -n "." # artistic output
fi
for MOD in $(dep "$DEPS")
do
if [ ! -z "$MOD" ] && [ "$(ext "$MOD" "$BM")" != "DUPLICATED" ]
then echo "$MOD" >> "$BM.dep.raw"
echo -n "." # artistic output
dal "$MOD"
fi
done
fi
done
}
dal "$1"
mcl "$1" # reorder bl
rm -f "$1.dep.raw" # clean unnecessary file
echo " done"
ver "$1"
}
ece () # fonction d'arret sur erreur
{
echo " ERROR"
less "$RD/$1/build.log"
exit 1
}
# izi zest kaboul
mkb_2 ()
{
if [ "$(moe "$1")" = "YES" ] #0
then
ccr "$1"
for MOD in `cat "$1.dep"`
do
if [ $MOD != $1 ] #1
then mkb_2 $MOD
else
if [ "$(ddb "$MOD")" != "DUPLICATING" ] #2
then
echo -n "Updating $MOD ..."
if [ "$(mku "$MOD")" = "YES" ] #3
then
echo " YES"
echo -n "Building $MOD ..."
if [ "$(run "$1")" = "NO" ] #4
then
echo "FORBIDEN"
else csd $MOD
cp $SCRIPT/libtool ./
cp $SCRIPT/mkinstalldirs ./
sh "$SCRIPT/$(run "$MOD")" 2>&1 > "../build.log" &&
echo " YES" &&
echo "$MOD" >> "$RD/MODULES.LOCK" || ece $MOD
fi #4
else
echo "UPDATE FAILS ##CVS/WGET## DATABASE URL ERROR OR CHECK CVS LOGIN CODE"
exit
fi #3
fi #2
fi #1
done
else echo "Module $1 not found in database"
fi #0
}
mkb ()
{
mkd "$1"
mkb_2 "$1"
}
mad ()
{
echo "Updating build list dependencies for each module "
for all in $(cvs_db --all-mods)
do
mkd $all
done
echo "Updating build list dependencies for each module : done"
}
now the cvs_db script for testind build script
#!/bin/bash
#/usr/sbin/cvs_db
#un truc bien marrant voire utile...
#this is the core of CVS_DB an cvs module database reader (STABLE / no bug)
#
bliscat.sirtakys@tele2.fr GPL
#need gawk cvsdb (build scripts are made for LFS-CVS-20040601 (gcc-3.4.1))
export DBNAME=cvsdb
export DBDIR=/etc
case "$1" in
--all-mods)
echo -e $(echo $(gawk '{FS=" "};{ print $1 }' $DBDIR/$DBNAME) | sed 's/ / \\n/g')
;;
--test-db)
#supressed for space... here only
;;
--deps)
#aie aie aie...
#bon, posons un principe: separation des dependances par un :
# et,
#on utilise sed pour virer les : par des <<\n >> glib\ atk\ pango
# l'info DEPS est en 5eme col
echo -e $(echo $(gawk -v MOD=$2 '{FS=" "};$1 == MOD { print $5 }' $DBDIR/$DBNAME) | sed 's/:/ \\n/g')
;;
--server)
# l'info SERVER est en 4eme col
gawk -v MOD=$2 '{FS=" "}
$1 == MOD { print $4 }' $DBDIR/$DBNAME
;;
--type)
# l'info TYPE est en 3eme col
gawk -v MOD=$2 '{FS=" "}
$1 == MOD { print $3 }' $DBDIR/$DBNAME
;;
--script)
# l'info SCRIPT est en 2nd col
gawk -v MOD=$2 '{FS=" "}
$1 == MOD { print $2 }' $DBDIR/$DBNAME
;;
esac
#fin de cvs_db
and a little part the database cvsdb but nice to show error
atk cvsgnome CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome glib
gtk-doc cvsgnome CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome gnome-common:libxslt
gtk+ cvsgnome CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome pango:atk:glib
libxml2 NO CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome
libxslt NO CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome
pango cvsgnome CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome glib
pkgconfig NO CVS :pserver:anoncvs@pdx.freedesktop.org:/cvs/pkgconfig
glib cvsgnome CVS :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome pkgconfig:gtk-doc