#!/bin/sh

source conf_vars.sh

# Update system
${ROOTCMD} apt-get -f -y --force-yes install
${ROOTCMD} apt-get -f -y --force-yes update
${ROOTCMD} apt-get -f -y --force-yes upgrade
${ROOTCMD} apt-get -f -y --force-yes dist-upgrade
${ROOTCMD} apt-get -f -y --force-yes autoremove

#----------------------------------------------------------------------
# check build-deps
checkinstalled () {
        while [ -n "$1" ]; do
                dpkg -l "$1" |grep -q "^ii" || {
                        echo "$1 is not installed."
                        apt-get -y --force-yes install $1
                        apt-get clean
                }
                shift
        done
}

sanitycheck () {
        # sanity check build environment
        echo "Sanity check..."
        checkinstalled dpkg-cross
#       checkinstalled wget
        #checkinstalled dctrl-tools 
        checkinstalled grep-dctrl
        checkinstalled sudo
        checkinstalled fakeroot
        checkinstalled dpatch
        checkinstalled patchutils
        checkinstalled tar
        checkinstalled bzip2
        checkinstalled lsb-release
        checkinstalled autoconf
        checkinstalled autoconf2.13
        checkinstalled automake1.9
        checkinstalled libtool
        checkinstalled autogen
        checkinstalled gawk
        checkinstalled bison
        checkinstalled flex
        checkinstalled realpath
        checkinstalled texinfo
        checkinstalled devscripts
        checkinstalled reprepro
        checkinstalled less
        checkinstalled coreutils
        checkinstalled automake1.4
        checkinstalled automake1.7
        checkinstalled dh-make
        checkinstalled debhelper
        checkinstalled apt-cross
        checkinstalled emdebian-tools
        
        # Following lines are gdb dependencies
        checkinstalled tetex-bin
        checkinstalled libncurses5-dev
        checkinstalled libreadline5-dev
        #checkinstalled gcj 
        checkinstalled gobjc
        checkinstalled cdbs
        checkinstalled quilt
        checkinstalled type-handling
        checkinstalled build-essential
        checkinstalled gcc-multilib
        checkinstalled libc6-dev-i386
        checkinstalled lib32gcc1
        checkinstalled dejagnu
        checkinstalled gperf
        checkinstalled libmpfr-dev
        checkinstalled sharutils
        checkinstalled pbuilder
        checkinstalled chrpath
        echo "Sanity check passed."
}

sanitycheck

cat << 'EOF' > $LOGHTMLPATH/$LOGHTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Buildcross results: Emdebian vs Debian (unstable)</title>  <link rev="made" href="mailto:webmaster\@emdebian.org">
  <link rel="shortcut icon" href="http://www.emdebian.org/favicon.ico">
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#800080" alink="#FF0000">
<table width="100%" align="center" border="0" cellpadding="3" cellspacing="0" summary="">
<tr>
  <td align="left" valign="middle">
  <a href="http://www.emdebian.org/"><img src="http://www.emdebian.org/Pics.bak/emdebian_swirl.jpg" border="0" hspace="0" 
  vspace="0" alt="emdebian logo" width="310" height="61"></a>
  </td>
</tr>
</table>
<table bgcolor="#DF0451" border="0" cellpadding="0" cellspacing="0" width="100%" summary="">
<tr>
<td valign="top">
<img src="http://www.emdebian.org/Pics.bak/red-upperleft.png" align="left" border="0" hspace="0" vspace="0" 
alt="" width="15" height="16">
</td>
<td rowspan="2" align="center">
<a href="http://www.emdebian.org/News/index.html"><img src="http://www.emdebian.org/Pics.bak/news.en.png" align="middle" 
border="0" hspace="4" vspace="7" alt="news" width="48" height="18"></a>
<a href="http://www.emdebian.org/projects.html"><img src="http://www.emdebian.org/Pics.bak/projects.en.png" align="middle" 
border="0" hspace="4" vspace="7" alt="emdebian projects" width="62" height="18"></a>
<a href="http://www.emdebian.org/support.html"><img src="http://www.emdebian.org/Pics.bak/support.en.png" align="middle" 
border="0" hspace="4" vspace="7" alt="support" width="62" height="18"></a>
<a href="http://www.emdebian.org/develinfo.html"><img src="http://www.emdebian.org/Pics.bak/devel.en.png" align="middle" 
border="0" hspace="4" vspace="7" alt="development" width="89" height="18"></a>
<td valign="top">
<img src="http://www.emdebian.org/Pics.bak/red-upperright.png" align="right" border="0" hspace="0" vspace="0" 
alt="" width="16" height="16">
</td>

</tr>
<tr>
<td valign="bottom">
<img src="http://www.emdebian.org/Pics.bak/red-lowerleft.png" align="left" border="0" hspace="0" vspace="0" 
alt="" width="16" height="16">
</td>
<td valign="bottom">
<img src="http://www.emdebian.org/Pics.bak/red-lowerright.png" align="right" border="0" hspace="0" vspace="0" 
alt="" width="15" height="16">
</td>
</tr>
</table>
<div><h1>
Emdebian buildcross toolchain updates: unstable</h1>
<p>This page is generated automatically by buildcross infrastructure to check latest status in
Emdebian toolchain <b>unstable</b> repository against upstream Debian unstable.</p>
<table border="1"><colgroup><col width="30%"><col width="10%">
<col width="30%"></colgroup>
<br>
<p>You can check <a href="./logs/build.log">buildcross complete log</a></p>
<b>BUILD-HOST : ARCH : SUITE : PKG : LOGFILE : STATUS</b> <br>
EOF

for ARCH in $ARCHLIST; do
	# Do PKGLIST
	for PKG in $PKGLIST; do
		# Check if it is already latest version built

		# Builds certain PKG for certain ARCH
		nice -n +15 ./em_build.sh $PKG $ARCH

		# Anything else to do?
	done
		
	# Anything else to do?
done

cat << 'EOF' >> $LOGHTMLPATH/$LOGHTML
</table>
</body></html>
EOF

