openmamba-headserver-tools/etc/cron.daily/20-openmamba-autobuild-makedist
2012-03-12 15:18:41 +01:00

266 lines
8.5 KiB
Bash
Executable File

#!/bin/bash
#
# Makedist automatic build script
# Copyright (c) 2007-2009 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
# Usage:
#
# To overwrite already existing images
# FORCE_OVERWRITE=1 ./20-openmamba-makedist
#
# To commit a new release (relies on snapshot images):
# RELEASE=1.0pre3 ./20-openmamba-makedist
#
. /etc/sysconfig/makedist
. /usr/share/makedist/functions.inc.sh
DISTRONAME=openmamba
MAKEDIST_TARGET=openmamba
arch=i586
SOURCEDIR=/var/makedist
[ "$TODAYDATE" ] || TODAYDATE=`date +%Y%m%d`
[ "$WEEKDAY" ] || WEEKDAY=`date +%u`
# DAY: 1=monday ... 7=sunday
if [ "$RELEASE" ]; then
DISTVERSION=milestone1
DESTBASEDIR=/var/ftp/pub/openmamba/$DISTVERSION/media
ALLMEDIAS=(livecd/livecd-root livecd/livestudio-root installdvd/livecd-root bootusb)
ALLMEDIASDAY=(8 8 8 8)
# DOWNLOADSFILEPREFIX=$DESTBASEDIR/downloads
DESTLATESTFILENAME=latest-$RELEASE.inc.js
SOURCEIMGFILEPREFIX="openmamba-$DISTVERSION"
else
DISTVERSION=devel
DESTBASEDIR=/var/ftp/pub/openmamba/$DISTVERSION/media
ALLMEDIAS=(livecd/livecd-root livedvd/livedvd-root livecd/livegames-root livecd/testcd-root flash-1GB bootcd bootusb)
ALLMEDIASDAY=(5 2 6 4 7 7 5)
# DOWNLOADSFILEPREFIX=$DESTBASEDIR/downloads.inc
DESTLATESTFILENAME=latest.inc.js
SOURCEIMGFILEPREFIX="openmamba"
fi
DESTIMGFILEPREFIX="openmamba"
ALLMEDIASLAST=`expr ${#ALLMEDIAS[*]} - 1`
DESTBASEURL=/pub/openmamba/$DISTVERSION/media
# do_makedist()
#
# Parameters;
#
# $1: dist filename
# $2: dest filename
# $3: language
# $4: platform
# $5: subplatform
# $6 product_name
function do_makedist() {
local DIST_CREATED=0
SOURCEIMG=$SOURCEDIR/$1
DESTNAME=$2
DESTDIR=$DESTBASEDIR/$6/$3
DESTIMG=$DESTDIR/$DESTNAME
DESTMD5=$DESTDIR/$DESTNAME.MD5.txt
DESTTORRENT=$DESTDIR/$DESTNAME.torrent
[ "$RELEASE" ] && \
DESTLATEST=$DESTDIR/latest-is-$RELEASETAG.txt || \
DESTLATEST=$DESTDIR/latest-is-$SNAPDATE.txt
if [ ! -f $DESTIMG -o "$FORCE_OVERWRITE" = "1" ]; then
[ ! "$SIMULATE" ] && {
makedist openmamba PLATFORM=$4 SUBPLATFORM=$5 FORCE=1 LANGUAGE=$3 || {
echo "Error building openmamba $6 platform; aborting."
exit 1
}
DIST_CREATED=1
}
if [ "$RELEASE" ]; then
[ -e $DESTDIR ] || mkdir -p $DESTDIR
cp $SOURCEIMG $DESTIMG
cp $SOURCEDIR/.$1.inc.html $DESTDIR/buildinfo-$RELEASE.inc.html
[ "$RELEASE/pre" != "$RELEASE" ] && ln -sf buildinfo-$RELEASE.inc.html $DESTDIR/buildinfo-pre.inc.html
cd $DESTDIR
md5sum $DESTNAME > $DESTMD5
maketorrent-console --title "openmamba $RELEASE $6 $3" --tracker_name "mambaSoft BitTorrent tracker" \
http://www.mambasoft.it:8080/announce $DESTNAME --target $DESTTORRENT
rm -f $DESTDIR/latest-is-*.txt
> $DESTLATEST
else
[ -e $DESTDIR ] || mkdir -p $DESTDIR
cp $SOURCEIMG $DESTIMG
cp $SOURCEDIR/.$1.inc.html $DESTDIR/buildinfo.inc.html
cd $DESTDIR
md5sum $DESTNAME > $DESTMD5
maketorrent-console \
--comment "openmamba snapshot $SNAPDATE $6 $3 from http://www.openmamba.org" \
--tracker_name "mambaSoft BitTorrent tracker" \
--language $3 \
http://www.mambasoft.it:8080/announce \
$DESTNAME --target $DESTTORRENT
rm -f $DESTDIR/latest-is-*.txt
> $DESTLATEST
fi
fi
DESTSIZE=`du $DESTIMG -h | gawk '{ print $1 }'`
DESTMD5=`cat $DESTMD5 | gawk '{ print $1 }'`
cat > $DESTDIR/$DESTLATESTFILENAME << _EOF
nameArray['$6-$RELEASETAG-$3']='$DESTNAME';
pathArray['$6-$RELEASETAG-$3']='/download.html?file=$DESTBASEURL/$6/$3/';
sizeArray['$6-$RELEASETAG-$3']='$DESTSIZE';
md5Array['$6-$RELEASETAG-$3']='$DESTMD5';
_EOF
return $DIST_CREATED
}
# do_all_langs_makedist()
#
# Parameters;
#
# $1: dist filename
# $2: dest filename
# $3: platform
# $4: subplatform
# $5: html output language
# $6: product name
function do_makedist_and_html() {
local DIST_LINE DIST_CREATED DIST_DWD
local tempfile2=`tempfile 2>/dev/null` || tempfile=/tmp/makedist_tmpfile2
PRODNAME=$6
[ $PRODNAME ] || PRODNAME=$PLATFORM
cat > $tempfile2 << _EOF
<div class="downloadbox"><table width="760"><tr><td width=400>
<form name="$PRODNAME-form-$RELEASETAG" id="$PRODNAME-form-$RELEASETAG">
_EOF
case $5 in
it) echo -n "Lingua: " >> $tempfile2 ;;
*) echo -n "Language: " >> $tempfile2 ;;
esac
for l in $LANGS; do
[ "$l" = "$5" ] && {
checked="checked"
} || checked=""
case $l in
it) langname="italiano" ;;
es) langname="espa&ntilde;ol" ;;
en) langname="english" ;;
*) langname="unknown" ;;
esac
echo "<input type=radio name=\"language\" value=\"$l\" onclick=\"javascript:selectlang('$PRODNAME-${RELEASETAG}','$l');\" $checked>$langname" >> $tempfile2
done
cat >> $tempfile2 << _EOF
<br><span name="$PRODNAME-${RELEASETAG}-spanl" id="$PRODNAME-${RELEASETAG}-spanl"></span><script>
_EOF
echo "<tr><td>" >> $tempfile.$5
#>> $tempfile.$5
unset DIST_DWD
for l in $LANGS; do
DESTNAME=$DESTIMGFILEPREFIX-$PRODNAME-$l-$2
do_makedist $SOURCEIMGFILEPREFIX-$PRODNAME-$l.$1 $DESTNAME $l $3 $4 $PRODNAME
DIST_CREATED=$?
cat $DESTBASEDIR/$PRODNAME/$l/$DESTLATESTFILENAME >> $tempfile2
DIST_DWD="$DIST_DWD <a href=\"/download.html?file=$DESTBASEURL/$PRODNAME/$l/$DESTNAME\">$l-$arch</a>"
done
DIST_LINE="<a href=\"/distribution/media/$PRODNAME.html?lang=$5\">$PRODNAME</a>"
[ $DIST_CREATED ] && DIST_LINE="<b>$DIST_LINE</b>"
echo "${DIST_LINE}</td><td>$SNAPDATE</td><td nowrap>[ ${DIST_DWD}]</td></tr>" >>$tempfile.$5
cat >> $tempfile2 << _EOF
</script></form></td><td><span name="${6}-${RELEASETAG}-spanr" id="${6}-${RELEASETAG}-spanr"></span></td></tr></table></div>
<script>javascript:selectlang('$PRODNAME-${RELEASETAG}','$5');</script>
_EOF
if [ "$RELEASE" ]; then
DESTHTML=$DESTBASEDIR/$PRODNAME/index.inc.$5.$RELEASE.html
ln -sf index.inc.$5.$RELEASE.html $DESTBASEDIR/$PRODNAME/index.inc.$5.pre.html
else
DESTHTML=$DESTBASEDIR/$PRODNAME/index.inc.$5.html
fi
mv $tempfile2 $DESTHTML
chmod +r $DESTHTML
}
LANGUAGE=_SPLIT_
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/makedist_tmpfile
for l in $LANGS; do
echo "<table>" > $tempfile.$l
done
for i in `seq 0 $ALLMEDIASLAST`; do
PLATFORM=${ALLMEDIAS[i]/\/*/}
SUBPLATFORM=${ALLMEDIAS[i]/*\//}
unset PRODUCT_NAME
unset PRODUCT_NAME_OVERRIDE
[ $SUBPLATFORM ] && . /var/makedist/targets/$MAKEDIST_TARGET/platforms/$SUBPLATFORM/settings.inc
. /var/makedist/targets/$MAKEDIST_TARGET/platforms/$PLATFORM/settings.inc
[ "$SUBPLATFORM" ] && \
media_name=`PLATFORM=$SUBPLATFORM media_name` ||
media_name=`media_name`
media_suffix=${media_name/*_SPLIT_\./}
[ $PRODUCT_NAME ] || PRODUCT_NAME=$PLATFORM
[ "$PRODUCT_NAME_OVERRIDE" ] && PRODUCT_NAME=$PRODUCT_NAME_OVERRIDE
#echo "PLATFORM=$PLATFORM SUBPLATFORM=$SUBPLATFORM MEDIA_SUFFIX=$media_suffix"
if [ "$RELEASE" ]; then
echo "Releasing $PRODUCT_NAME media (${PLATFORM}/${SUBPLATFORM})"
SIMULATE=1
elif [ "$WEEKDAY" = "${ALLMEDIASDAY[i]}" -o \
"$FORCEBUILD" = "$PRODUCT_NAME" ]; then
echo "Building $PRODUCT_NAME media"
unset SIMULATE
else
SIMULATE=1
fi
if [ -e $DESTBASEDIR/$PRODUCT_NAME/en ]; then
unset latest
latest=`ls $DESTBASEDIR/$PRODUCT_NAME/en/latest-is-*.txt 2>/dev/null| sed "s/.*latest-is-\(.*\)\.txt/\1/"`
[ "$latest" -a "$SIMULATE" ] && SNAPDATE=$latest || SNAPDATE=$TODAYDATE
[ "$RELEASE" ] && RELEASETAG=milestone1-$RELEASE || RELEASETAG=snapshot-$SNAPDATE
for l in $LANGS; do
# build specific language version
[ "$latest" -o ! "$SIMULATE" -o "$RELEASE" ] &&
do_makedist_and_html \
$media_suffix $RELEASETAG.$media_suffix \
$PLATFORM "$SUBPLATFORM" $l $PRODUCT_NAME
done
# # build english version
# [ "$latest" -o ! "$SIMULATE" -o "$RELEASE" ] &&
# do_makedist_and_html \
# $media_suffix $RELEASETAG.$media_suffix \
# $PLATFORM "$SUBPLATFORM" en $PRODUCT_NAME
else
echo "Warning: missing directory $DESTBASEDIR/$PRODUCT_NAME/en; skipping"
fi
done
for l in $LANGS; do
echo "</table>" >> $tempfile.$l
if [ "$RELEASE" ]; then
cat $tempfile.$l > $DESTBASEDIR/downloads-$RELEASE.inc.$l
[ "${RELEASE/pre}" != "$RELEASE" ] && ln -sf downloads-$RELEASE.inc.$l $DESTBASEDIR/downloads-pre.inc.$l
else
cat $tempfile.$l > $DESTBASEDIR/downloads.inc.$l
fi
rm -f $tempfile.$l
done
exit 0