openmamba-headserver-tools/etc/cron.daily/20-openmamba-autobuild-makedist

343 lines
12 KiB
Plaintext
Raw Normal View History

2012-03-12 15:18:41 +01:00
#!/bin/bash
#
# Makedist automatic build script
# Copyright (c) 2007-2012 by Silvan Calarco <silvan.calarco@mambasoft.it>
2012-03-12 15:18:41 +01:00
#
# 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
ME=`basename $0`
[ "$$" == "`pidof -x $ME`" ] || {
echo "Warning: script already running; exiting."
exit 0
}
TORRENTURL=http://torrent.mambasoft.it:8080/announce
2012-03-12 15:18:41 +01:00
DISTRONAME=openmamba
MAKEDIST_TARGET=openmamba
arch=i586
SOURCEDIR=/var/makedist
[ "$TODAYDATE" ] || TODAYDATE=`date +%Y%m%d`
[ "$WEEKDAY" ] || WEEKDAY=`date +%u`
[ "$DISTVERSION" ] || {
echo "Error: DISTVERSION is not set, check configuration file; aborting."
exit 1
}
2012-03-12 15:18:41 +01:00
if [ "$RELEASE" ]; then
DESTLATESTFILENAME=latest-$RELEASE.inc.js
SOURCEIMGFILEPREFIX="openmamba-$DISTVERSION"
else
DESTLATESTFILENAME=latest.inc.js
SOURCEIMGFILEPREFIX="openmamba"
fi
DESTBASEDIR=/var/ftp/pub/openmamba/$DISTVERSION/media
2012-03-12 15:18:41 +01:00
DESTIMGFILEPREFIX="openmamba"
ALLMEDIASLAST=`expr ${#MEDIA_NAME[*]} - 1`
2012-03-12 15:18:41 +01:00
DESTBASEURL=/pub/openmamba/$DISTVERSION/media
# do_makedist()
#
# Parameters;
#
# $1: dist filename
# $2: dest filename
# $3: language
# $4: platform
# $5: subplatform
# $6: product_name
# $7: architecture
2012-03-12 15:18:41 +01:00
function do_makedist() {
local DIST_CREATED=0 SOURCEIMG DESTFILENAME DESTNAME DESTLANGUAGE DESTPLATFORM DESTSUBPLATFORM DESTARCH \
DESTPRODUCTNAME DESTDIR DESTIMG DESTMD5 DESTTORRENT
DESTFILENAME=$1
2012-03-12 15:18:41 +01:00
DESTNAME=$2
DESTLANGUAGE=$3
DESTPLATFORM=$4
DESTSUBPLATFORM=$5
DESTPRODUCTNAME=$6
DESTARCH=$7
SOURCEIMG=$SOURCEDIR/${DESTFILENAME}
DESTDIR=$DESTBASEDIR/${DESTPRODUCTNAME}/${DESTLANGUAGE}
2012-03-12 15:18:41 +01:00
DESTIMG=$DESTDIR/$DESTNAME
DESTMD5=$DESTDIR/$DESTNAME.MD5.txt
DESTTORRENT=$DESTDIR/$DESTNAME.torrent
[ "$DESTARCH" ] || {
echo "Error: do_makedist: invalid number of parameters; aborting."
exit 1
}
2012-03-12 15:18:41 +01:00
[ "$RELEASE" ] && \
DESTLATEST=$DESTDIR/latest-is-$RELEASETAG.txt || \
DESTLATEST=$DESTDIR/latest-is-$SNAPDATE.txt
if [ ! -f $DESTIMG -o "$FORCE_OVERWRITE" = "1" ]; then
if [ ! "$SIMULATE" ]; then
[ "$CRON_DEBUG" = "1" ] && \
echo "-> makedist openmamba PLATFORM=${DESTPLATFORM} SUBPLATFORM=${DESTSUBPLATFORM} \
LANGUAGE=${DESTLANGUAGE} ARCH=${DESTARCH} FORCE=1"
makedist openmamba PLATFORM=${DESTPLATFORM} SUBPLATFORM=${DESTSUBPLATFORM} \
LANGUAGE=${DESTLANGUAGE} ARCH=${DESTARCH} FORCE=1 || {
echo "Error building openmamba ${DESTPRODUCTNAME} medium; aborting."
2012-03-12 15:18:41 +01:00
exit 1
}
DIST_CREATED=1
fi
2012-03-12 15:18:41 +01:00
if [ "$RELEASE" ]; then
[ -e $DESTDIR ] || mkdir -p $DESTDIR
cp $SOURCEIMG $DESTIMG
cp $SOURCEDIR/.${DESTFILENAME}.inc.html $DESTDIR/buildinfo-$RELEASE.inc.html
2012-03-12 15:18:41 +01:00
[ "$RELEASE/pre" != "$RELEASE" ] && ln -sf buildinfo-$RELEASE.inc.html $DESTDIR/buildinfo-pre.inc.html
cd $DESTDIR
md5sum $DESTNAME > $DESTMD5
if [ "${DESTIMG/.iso}" != "$DESTIMG" ]; then
# ISO image, create video preview
[ ! -e $DESTDIR/preview/$DESTNAME.ogv -o $SOURCEIMG -nt $DESTDIR/preview/$DESTNAME.ogv ] && openmamba-recordvm $DESTIMG
fi
rm -f $DESTDIR/latest-is-*.txt
2012-03-12 15:18:41 +01:00
> $DESTLATEST
else
[ -e $DESTDIR ] || mkdir -p $DESTDIR
cp $SOURCEIMG $DESTIMG
cp $SOURCEDIR/.${DESTFILENAME}.inc.html $DESTDIR/buildinfo.inc.html
cd $DESTDIR
2012-03-12 15:18:41 +01:00
md5sum $DESTNAME > $DESTMD5
if [ "${DESTIMG/.iso}" != "$DESTIMG" ]; then
# ISO image, create video preview
[ ! -e $DESTDIR/preview/$DESTNAME.ogv -o $SOURCEIMG -nt $DESTDIR/preview/$DESTNAME.ogv ] && openmamba-recordvm $DESTIMG
fi
2012-03-12 15:18:41 +01:00
rm -f $DESTDIR/latest-is-*.txt
> $DESTLATEST
fi
fi
if [ "$DIST_CREATED" = "1" -o $DESTIMG -nt $DESTTORRENT -o \
"$FORCE_OVERWRITE" = "1" -o "$FORCE_OVERWRITE_TORRENT" = "1" ]; then
# Generate TORRENT
if [ "$RELEASE" ]; then
cd $DESTDIR
maketorrent-console \
--comment "openmamba $RELEASE ${DESTPRODUCTNAME} ${DESTLANGUAGE}-${DESTARCH} from http://www.openmamba.org" \
--tracker_name "mambaSoft BitTorrent tracker" \
--language ${DESTLANGUAGE} \
$TORRENTURL \
$DESTNAME --target $DESTTORRENT >/dev/null
else
cd $DESTDIR
maketorrent-console \
--comment "openmamba snapshot $SNAPDATE ${DESTPRODUCTNAME} ${DESTLANGUAGE}-${DESTARCH} from http://www.openmamba.org" \
--tracker_name "mambaSoft BitTorrent tracker" \
--language ${DESTLANGUAGE} \
$TORRENTURL \
$DESTNAME --target $DESTTORRENT >/dev/null
fi
fi
2012-03-12 15:18:41 +01:00
DESTSIZE=`du $DESTIMG -h | gawk '{ print $1 }'`
DESTMD5=`cat $DESTMD5 | gawk '{ print $1 }'`
DESTBUILDDATE=`stat -c %y $SOURCEIMG`
2012-03-12 15:18:41 +01:00
cat > $DESTDIR/$DESTLATESTFILENAME << _EOF
nameArray['$DESTPRODUCTNAME-$RELEASETAG-$DESTLANGUAGE-$DESTARCH']='$DESTNAME';
pathArray['$DESTPRODUCTNAME-$RELEASETAG-$DESTLANGUAGE-$DESTARCH']='/download.html?file=$DESTBASEURL/$DESTPRODUCTNAME/$DESTLANGUAGE/';
sizeArray['$DESTPRODUCTNAME-$RELEASETAG-$DESTLANGUAGE-$DESTARCH']='$DESTSIZE';
md5Array['$DESTPRODUCTNAME-$RELEASETAG-$DESTLANGUAGE-$DESTARCH']='$DESTMD5';
builddateArray['$DESTPRODUCTNAME-$RELEASETAG-$DESTLANGUAGE-$DESTARCH']='$DESTBUILDDATE';
2012-03-12 15:18:41 +01:00
_EOF
return $DIST_CREATED
}
# do_all_langs_makedist()
#
# Parameters;
#
# $1: medium suffix
# $2: medium release tag
2012-03-12 15:18:41 +01:00
# $3: platform
# $4: subplatform
# $5: html language
2012-03-12 15:18:41 +01:00
# $6: product name
# $7: medium idx
2012-03-12 15:18:41 +01:00
function do_makedist_and_html() {
local DIST_LINE DIST_CREATED DIST_DWD HTMLLANG MEDIA_ARCH PRODNAME \
MEDIUMFILENAME MEDIUMNAME MEDIUMPLATFORM MEDIUMSUBPLATFORM m l
2012-03-12 15:18:41 +01:00
local tempfile2=`tempfile 2>/dev/null` || tempfile=/tmp/makedist_tmpfile2
MEDIUMSUFFIX=$1
MEDIUMTAG=$2
MEDIUMPLATFORM=$3
MEDIUMSUBPLATFORM=$4
HTMLLANG=$5
2012-03-12 15:18:41 +01:00
PRODNAME=$6
m=$7
[ "${m}" ] || {
echo "Error: do_makedist_and_html: invalid number of parameters; aborting."
exit 1
}
2012-03-12 15:18:41 +01:00
cat > $tempfile2 << _EOF
<div class="downloadbox"><table width="760"><tr><td width=400>
<form name="$PRODNAME-$RELEASETAG-form" id="$PRODNAME-$RELEASETAG-form">
2012-03-12 15:18:41 +01:00
_EOF
case ${HTMLLANG} in
it) echo -n "Lingua: " >> $tempfile2; selecttext="Scarica..."; fortext="per" ;;
*) echo -n "Language: " >> $tempfile2; selecttext="Download..."; fortext="for" ;;
2012-03-12 15:18:41 +01:00
esac
for l in ${MEDIA_LANGUAGES[$m]}; do
[ "$l" = "${HTMLLANG}" ] && {
checked="checked"
2012-03-12 15:18:41 +01:00
} || checked=""
case $l in
it) langname="italiano" ;;
es) langname="espa&ntilde;ol" ;;
en) langname="english" ;;
*) langname="unknown" ;;
esac
echo "<input type=radio id=\"language\" name=\"language\" value=\"$l\" onclick=\"javascript:selectlang('$PRODNAME-${RELEASETAG}');\" $checked />$langname" >> $tempfile2
done
case ${HTMLLANG} in
it) echo -n "<br>Architettura: " >> $tempfile2;;
*) echo -n "<br>Architecture: " >> $tempfile2;;
esac
checked="checked"
for a in ${MEDIA_ARCHS[$m]}; do
echo "<input type=radio id=\"arch\" name=\"arch\" value=\"$a\" onclick=\"javascript:selectlang('$PRODNAME-${RELEASETAG}');\" $checked />$a" >> $tempfile2
checked=""
2012-03-12 15:18:41 +01:00
done
cat >> $tempfile2 << _EOF
<br><span name="$PRODNAME-${RELEASETAG}-spanl" id="$PRODNAME-${RELEASETAG}-spanl"></span><script>
_EOF
echo "<tr><td width=25%>" >> $tempfile.${HTMLLANG}
2012-03-12 15:18:41 +01:00
#>> $tempfile.$5
DIST_DWD="<select style=\"float:right;width:150px;align:right;\" onchange=\"window.location=this.value;\"><option value="/">$selecttext</option>"
for l in ${MEDIA_LANGUAGES[$m]}; do
case $l in
it) mediumlang="italiano" ;;
es) mediumlang="espa&ntilde;ol" ;;
en) mediumlang="english" ;;
*) mediumlang="unknown" ;;
esac
for a in ${MEDIA_ARCHS[$m]}; do
case $a in
i586) archtext="x86 (PC)" ;;
arm) archtext="arm" ;;
*) archtext="unknown" ;;
esac
DESTNAME=$DESTIMGFILEPREFIX-$PRODNAME-$l-${MEDIUMTAG}.${a}.${MEDIUMSUFFIX}
[ "$CRON_DEBUG" = "1" ] && \
echo "do_makedist_and_html: calling do_makedist \"$SOURCEIMGFILEPREFIX-$PRODNAME-$l.${a}.${MEDIUMSUFFIX}\" \"$DESTNAME\" \"${l}\" \"${MEDIUMPLATFORM}\" \"${MEDIUMSUBPLATFORM}\" \"$PRODNAME\" \"${a}\""
do_makedist "$SOURCEIMGFILEPREFIX-$PRODNAME-$l.${a}.${MEDIUMSUFFIX}" "$DESTNAME" "${l}" "${MEDIUMPLATFORM}" "${MEDIUMSUBPLATFORM}" "$PRODNAME" "${a}"
DIST_CREATED=$?
cat $DESTBASEDIR/$PRODNAME/$l/$DESTLATESTFILENAME >> $tempfile2
DIST_DWD="$DIST_DWD<option value=\"/download.html?file=$DESTBASEURL/$PRODNAME/$l/$DESTNAME\">${mediumlang} $fortext $archtext</option>"
# DIST_DWD="$DIST_DWD <a href=\"/download.html?file=$DESTBASEURL/$PRODNAME/$l/$DESTNAME\">${l}-${a}</a>"
done
2012-03-12 15:18:41 +01:00
done
DIST_DWD="$DIST_DWD</select>"
DIST_LINE="<a href=\"/distribution/media/${MEDIA_NAME[$m]}.html?lang=${HTMLLANG}\">${MEDIA_NAME[$m]}</a>"
2012-03-12 15:18:41 +01:00
[ $DIST_CREATED ] && DIST_LINE="<b>$DIST_LINE</b>"
echo "${DIST_LINE}</td><td width=30%>$SNAPDATE</td><td width=40%>${DIST_DWD}</td></tr>" >>$tempfile.${HTMLLANG}
2012-03-12 15:18:41 +01:00
cat >> $tempfile2 << _EOF
</script></form></td><td><span name="${6}-${RELEASETAG}-spanr" id="${PRODNAME}-${RELEASETAG}-spanr"></span></td></tr>
<tr><td colspan=2><span id="details-data-$PRODNAME-${RELEASETAG/./_}"></span></td></tr></table></div>
<script>javascript:selectlang('$PRODNAME-${RELEASETAG}');</script>
2012-03-12 15:18:41 +01:00
_EOF
if [ "$RELEASE" ]; then
DESTHTML=$DESTBASEDIR/$PRODNAME/index.inc.${HTMLLANG}.$RELEASE.html
ln -sf index.inc.${HTMLLANG}.$RELEASE.html $DESTBASEDIR/$PRODNAME/index.inc.${HTMLLANG}.pre.html
2012-03-12 15:18:41 +01:00
else
DESTHTML=$DESTBASEDIR/$PRODNAME/index.inc.${HTMLLANG}.html
2012-03-12 15:18:41 +01:00
fi
mv $tempfile2 $DESTHTML
chmod +r $DESTHTML
}
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/makedist_tmpfile
for l in ${HTML_LANGS}; do
echo "<table width=100% cellpadding=0 cellspacing=0>" > $tempfile.$l
2012-03-12 15:18:41 +01:00
done
for i in `seq 0 $ALLMEDIASLAST`; do
PLATFORM=${MEDIA_PLATFORM[i]}
SUBPLATFORM=${MEDIA_SUBPLATFORM[i]}
2012-03-12 15:18:41 +01:00
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" ] && \
medium_name=`arch=_SPLIT_ PLATFORM=$SUBPLATFORM media_name` ||
medium_name=`arch=_SPLIT_ media_name`
medium_suffix=${medium_name/*_SPLIT_\./}
2012-03-12 15:18:41 +01:00
[ $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" = "${MEDIA_BUILDDAY[i]}" -o \
2012-03-12 15:18:41 +01:00
"$FORCEBUILD" = "$PRODUCT_NAME" ]; then
echo "Building $PRODUCT_NAME media"
unset SIMULATE
else
SIMULATE=1
fi
for l in ${HTML_LANGS}; do
for ml in ${MEDIA_LANGUAGES[i]}; do
if [ ! -e $DESTBASEDIR/$PRODUCT_NAME/$ml ]; then
mkdir -p $DESTBASEDIR/$PRODUCT_NAME/$ml || {
echo "Error: cannot create directory $DESTBASEDIR/$PRODUCT_NAME/$ml; aborting"
exit 1
}
fi
done
2012-03-12 15:18:41 +01:00
unset latest
latest=`ls $DESTBASEDIR/$PRODUCT_NAME/$ml/latest-is-*.txt 2>/dev/null| sed "s/.*latest-is-\(.*\)\.txt/\1/"`
2012-03-12 15:18:41 +01:00
[ "$latest" -a "$SIMULATE" ] && SNAPDATE=$latest || SNAPDATE=$TODAYDATE
[ "$RELEASE" ] && RELEASETAG=$DISTVERSION-$RELEASE || RELEASETAG=snapshot-$SNAPDATE
2012-03-12 15:18:41 +01:00
# build all media and create html page of language ${l}
[ "$latest" -o ! "$SIMULATE" -o "$RELEASE" ] &&
do_makedist_and_html \
$medium_suffix $RELEASETAG \
$PLATFORM "$SUBPLATFORM" ${l} $PRODUCT_NAME ${i}
done
2012-03-12 15:18:41 +01:00
done
for l in ${HTML_LANGS}; do
2012-03-12 15:18:41 +01:00
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