#!/bin/bash
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2008 Michael Tremer & Christian Schmidt #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see . #
# #
###############################################################################
case "$1" in
build)
# compile the distro right now
build
;;
shell)
# enter a shell inside LFS chroot
# may be used to change kernel settings
prepareenv
entershell
;;
batch)
# build the distro in background
. $BASEDIR/tools/make-batch
case "$2" in
start)
batch_start
;;
_run)
batch_run
;;
attach|watch)
batch_attach
;;
esac
;;
stats)
# show some stats about the compiler(s)
. $BASEDIR/tools/make-compilers
case "$2" in
ccache)
ccache_stats
;;
distcc)
distcc_mon
;;
esac
;;
clean)
echo -ne "Cleaning ${BOLD}$MACHINE${NORMAL} buildtree"
for i in `mount | grep $BASEDIR | sed 's/^.*loop=\(.*\))/\1/'`
do
$LOSETUP -d $i 2>/dev/null
done
for i in `mount | grep $BASEDIR | cut -d " " -f 1`
do
umount $i
done
stdumount
for i in `seq 0 7`
do
if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
umount /dev/loop${i} 2>/dev/null;
losetup -d /dev/loop${i} 2>/dev/null;
fi;
done
rm -rf $BASEDIR/build_${MACHINE}
rm -rf $BASEDIR/log_${MACHINE}
rm -rf $BASEDIR/packages
if [ -h $TOOLS_DIR ]; then
rm -f $TOOLS_DIR
fi
beautify message DONE
;;
downloadsrc)
LOGFILE=$BASEDIR/log_${MACHINE}/_build.preparation.log
if [ ! -d $BASEDIR/cache ]; then
mkdir $BASEDIR/cache
fi
mkdir -p $BASEDIR/log_${MACHINE}
echo -e "${BOLD}Preload all source files${NORMAL}" | tee -a $LOGFILE
cd $BASEDIR/lfs
for i in *; do
if [ -f "$i" -a "$i" != "Config" ]; then
echo -ne "Loading $i"
make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t" download >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
beautify message FAIL
else
beautify message DONE
fi
fi
done
cd - >/dev/null 2>&1
;;
toolchain)
prepareenv
# Check if host can build the toolchain
. tools/make-check
check_toolchain
toolchain_build
echo "Create toolchain tar.bz for $MACHINE" | tee -a $LOGFILE
# Safer inside the chroot
echo -ne "Stripping lib"
chroot $LFS $TOOLS_DIR/bin/find $TOOLS_DIR/lib \
-type f \( -name '*.so' -o -name '*.so[\.0-9]*' \) \
-exec $TOOLS_DIR/bin/strip --strip-debug {} \; 2>/dev/null
beautify message DONE
echo -ne "Stripping binaries"
chroot $LFS $TOOLS_DIR/bin/find /usr/local /usr/src/binutils-build $TOOLS_DIR/bin $TOOLS_DIR/sbin \
-type f \
-exec $TOOLS_DIR/bin/strip --strip-all {} \; 2> /dev/null
beautify message DONE
stdumount
echo -ne "Tar creation "
[ -d cache/toolchains ] || mkdir cache/toolchains
cd $BASEDIR && tar cj \
--exclude='log_${MACHINE}/_build.*.log' \
--file=cache/toolchains/$TOOLCHAINNAME.tar.bz2 \
build_${MACHINE} \
log_${MACHINE} >> $LOGFILE
beautify message DONE
echo `ls -sh cache/toolchains/$TOOLCHAINNAME.tar.bz2`
md5sum cache/toolchains/$TOOLCHAINNAME.tar.bz2 \
> cache/toolchains/$TOOLCHAINNAME.md5
stdumount
;;
gettoolchain)
if [ ! -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
URL_TOOLCHAIN=`grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }'`
test -d $BASEDIR/cache/toolchains || mkdir $BASEDIR/cache/toolchains
echo "Loading toolchain for $MACHINE"
cd $BASEDIR/cache/toolchains
wget -c -nv $URL_TOOLCHAIN/$TOOLCHAINNAME.tar.bz2 $URL_TOOLCHAIN/$TOOLCHAINNAME.md5
if [ $? -ne 0 ]; then
echo -n "ERROR: Downloading toolchain for $MACHINE machine"
beautify message FAIL
echo "Precompiled toolchain not always available for every machine"
else
if [ "`md5sum $TOOLCHAINNAME.tar.bz2 | awk '{print $1}'`" = "`cat $TOOLCHAINNAME.md5 | awk '{print $1}'`" ]; then
beautify message DONE
echo "Toolchain md5 ok"
else
exiterror "$TOOLCHAINNAME.md5 did not match, check downloaded package"
fi
fi
else
echo -n "Toolchain for $MACHINE is already existing"
beautify message SKIP
fi
;;
othersrc)
prepareenv
echo -ne "`date -u '+%b %e %T'`: Build sources iso for $MACHINE" | tee -a $LOGFILE
chroot $LFS /tools/bin/env -i HOME=/root \
TERM=$TERM PS1='\u:\w\$ ' \
PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
VERSION=$VERSION NAME="$NAME" SNAME="$SNAME" MACHINE=$MACHINE \
/bin/bash -x -c "cd /usr/src/lfs && make -f sources-iso LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
mv $LFS/install/images/ipfire-* $BASEDIR >> $LOGFILE 2>&1
if [ $? -eq "0" ]; then
beautify message DONE
else
beautify message FAIL
fi
stdumount
;;
svn)
. $BASEDIR/tools/make-subversion
case "$2" in
update|up)
svn_up
;;
commit|ci)
clear
svn_commit
svn_up
;;
dist)
svn_dist
;;
diff|di)
svn_diff
;;
log)
svn_log
;;
esac
;;
uploadsrc)
PWD=`pwd`
cd $BASEDIR/cache/
echo -e "Uploading cache to ftp server:"
for i in *; do
echo "${i}" | fgrep -q .md5 && continue
[ -e ${i}.md5 ] && continue
md5sum ${i} | tee ${i}.md5
done
ncftpls -u $FTP_CACHE_USER -p $FTP_CACHE_PASS ftp://$FTP_CACHE_URL/$FTP_CACHE_PATH/ > /tmp/ftplist
for i in *; do
if [ "$(basename $i)" == "toolchains" ]; then continue; fi
grep -q $(basename $i) /tmp/ftplist
if [ "$?" -ne "0" ]; then
echo -ne "$(basename $i)"
ncftpput -u $FTP_CACHE_USER -p $FTP_CACHE_PASS $FTP_CACHE_URL $FTP_CACHE_PATH/ $(basename $i)
if [ "$?" -ne "0" ]; then
beautify message FAIL
fi
fi
done
rm -f /tmp/ftplist
cd $PWD
exit 0
;;
upload)
FTP_ISO_PORT=`echo "$FTP_ISO_URL" | awk -F: '{ print $2 }'`
FTP_ISO_URL=`echo "$FTP_ISO_URL" | awk -F: '{ print $1 }'`
if [ -z $FTP_ISO_PORT ]; then
FTP_ISO_PORT=21
fi
cat < .ftp-commands
mkdir -p $FTP_ISO_PATH$SVN_REVISION
mkdir -p $FTP_ISO_PATH$SVN_REVISION/paks
quit
EOF
ncftp -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL < .ftp-commands
rm -f .ftp-commands
case "$2" in
iso)
echo -e "Uploading the iso to $FTP_ISO_PATH/$SVN_REVISION."
md5sum ipfire-$VERSION.$MACHINE-full.iso > ipfire-$VERSION.$MACHINE-full.iso.md5
for i in svn_status ipfire-source-r$SVN_REVISION.tar.gz ipfire-$VERSION.$MACHINE-full.iso ipfire-$VERSION.$MACHINE-full.iso.md5 ipfire-$VERSION.$MACHINE-devel.iso ipfire-$VERSION.$MACHINE-devel.iso.md5; do
if [ -e "$i" ]; then
ncftpput -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH$SVN_REVISION/ $i
if [ "$?" -eq "0" ]; then
echo "The file with name $i was successfully uploaded to $FTP_ISO_URL$FTP_ISO_PATH$SVN_REVISION/."
else
echo "There was an error while uploading the file $i to the ftp server."
exit 1
fi
fi
done
rm -f ipfire-$VERSION.$MACHINE-full.iso.md5
if [ "$3" = "--with-sources-cd" ]; then
ncftpput -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH/$SVN_REVISION/ ipfire-sources-cd-$VERSION.$MACHINE.iso
fi
;;
paks)
ncftpput -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH$SVN_REVISION/paks packages/*
if [ "$?" -eq "0" ]; then
echo -e "The packages were successfully uploaded to $FTP_ISO_URL$FTP_ISO_PATH$SVN_REVISION/."
else
echo -e "There was an error while uploading the packages to the ftp server."
exit 1
fi
;;
esac
;;
*)
cat doc/make.sh-usage
;;
esac