#!/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)
# check for prerequisites
. $BASEDIR/tools/make-check && check_build
# compile the distro right now
build
# beeps when finished
echo -ne '\a'
;;
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.00-preparation.log
if [ ! -d $BASEDIR/cache ]; then
mkdir -p $BASEDIR/cache/{tarballs,patches}
fi
mkdir -p $BASEDIR/log_${MACHINE}
echo -e "${BOLD}Preload all source files${NORMAL}"
cd $BASEDIR/lfs
for i in *; do
if [ -f "$i" -a "$i" != "Config" ]; then
make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t" download 2>> $LOGFILE
if [ $? -ne 0 ]; then
echo -ne "Couldn't download all files for ${BOLD}${i}${NORMAL}"
beautify message FAIL
fi
fi
done
cd - >/dev/null 2>&1
;;
toolchain)
prepareenv
# Check if host can build the toolchain
. tools/make-check
check_toolchain
build_spy compiling
toolchain_build
stdumount
echo -ne "\ntarball creation "
[ -d $BASEDIR/cache/toolchains ] || mkdir $BASEDIR/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.tar.bz2.md5
stdumount
build_spy idle
;;
gettoolchain)
if [ ! -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
URL_TOOLCHAIN=$(grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }')
DIR_TOOLCHAIN="$BASEDIR/cache/toolchains"
echo "Loading toolchain for $MACHINE"
BASEDIR=$BASEDIR DIR_TMP=/tmp DIR_DL=$DIR_TOOLCHAIN \
sh $BASEDIR/tools/downloader $URL_TOOLCHAIN $TOOLCHAINNAME.tar.bz2
if [ $? -eq 0 ]; then
echo -n "Toolchain was successfully downloaded"
beautify message DONE
else
echo -n "ERROR: Downloading toolchain \"$TOOLCHAINNAME\""
beautify message FAIL
echo "Precompiled toolchain not always available for every machine"
fi
else
echo -n "Toolchain \"$TOOLCHAINNAME\" is already existing"
beautify message SKIP
fi
;;
check)
. tools/make-check
check_sanity $2
;;
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
;;
g[iu]t)
. $BASEDIR/tools/make-git
COMMAND=$2
shift 2
case "$COMMAND" in
update|pull)
git_pull $*
;;
commit|ci)
clear
git_commit $*
;;
dist|export|archive)
git_export $*
;;
push)
git_push $*
;;
diff|di)
git_diff $*
;;
log)
git_log $*
;;
put-key)
ssh_cert $*
;;
*) # If no command matches run git directly
git $*
;;
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