makedist/obsoleted/make_cd_lists.sh
2011-05-04 02:30:35 +02:00

248 lines
7.0 KiB
Bash
Executable File

#
# make_cd_lists.sh - QiLinux CD lists creator
#
# Copyright (c) 2005-2007 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
# 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 2 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.
. ./VERSION
. ./functions.inc.sh
. ./defs.inc.sh
EMPTYCD_SPACE=734000000
tmpfile=`mktemp -q -t ${0##*/}.XXXXXXXX` ||
{ echo "${0##*/}: error: cannot create temporary files." >&2
{ (exit 1); exit 1; }; }
trap "rm -f $tmpfile" 0 1 2 5 15
copyleft="\
Makedist distribute cd tool (version $makedist_version)
Copyright (c) 2003-2007 by Silvan Calarco <silvan.calarco@mambasoft.it>
Copyright (c) 2003-2006 by Davide Madrisan <davide.madrisan@qilinux.it>
"
unset branch # can be 'stable', 'unstable', or 'devel'
mkcd_me="${0##*/}"
function usage() {
echo "\
usage: $mkcd_me [-y] [-u[=<opts>]] [-t target] branch media platform
-u : download setup scripts and files and QiLinux packages
<opts> can be:
setup download the setup scripts and db files
rpms download only the RPM packages
srpms download only the SRPM packages
lists create packages lists for each media
all download setup scripts, db files, RPM, SRPM
-t : build CD for specified target
netcd : build an ISO image for installation from network only
livecd: create the ISO image for QiLinux live CD
i.e. $mkcd_me -u stable
$mkcd_me -u=setup,rpms stable cd2 desktop
$mkcd_me -u=setup devel cd1 free
" >&2
}
function add_packages_tocd() {
calculate_rpms_occupation "$1"
if [ $rpmsfilesum -lt $CDFREESPACE ]; then
INST="$INST $1"
let CDFREESPACE-=$rpmsfilesum
let CDOCCUPIEDSPACE+=$rpmsfilesum
CDPACKAGES="$CDPACKAGES $1"
return 0
else
return 1
fi
}
#
# function generate_cd_list:
#
# input args:
#
# $1: make target(s) to be added
# $2: CD number
# $3: match regexp
#
function generate_cd_list() {
local t pkgs_filtered
CDFREESPACE=${CDSPACE[$2]}
CDOCCUPIEDSPACE=0
CDPACKAGES=
INST=$INSTALLED
for target in $1; do
echo -n "Adding target $target to CD$2"
[ "$3" ] && echo "(filter: $3)" || echo
CDADDPACKAGES=`make -s -C $UTILSDIR INSTALLED="$INST" LISTALLPACKAGES=1 PLATFORM="$PLATFORM" $target 2>$tmpfile`
if [ $? -ne 0 ]; then
echo "FATAL ERROR: error while executing make:"
cat $tmpfile
echo "Command was: make -s -C $UTILSDIR INSTALLED=\"$INST\" LISTALLPACKAGES=1 PLATFORM=\"$PLATFORM\" $target"
exit 1
fi
unset pckgs_filtered
if [ "$3" ]; then
for t in $CDADDPACKAGES; do
[[ "$(echo $t | sed -n "/$3/p")" ]] &&
pkgs_filtered="$pkgs_filtered $t"
done
CDADDPACKAGES="$pkgs_filtered"
fi
add_packages_tocd "$CDADDPACKAGES"
if [ $? -ge 1 ]; then
# cannot add all packages, so add packages one by one unil free space is over
for currpackage in $CDADDPACKAGES; do
CDADDSUBPACKAGES=`make -s -C $UTILSDIR INSTALLED="$INST" LISTALLPACKAGES=1 PLATFORM="$PLATFORM" $currpackage 2>/dev/null`
if [ "$CDADDSUBPACKAGES" ]; then
echo -n " adding $CDADDSUBPACKAGES "
add_packages_tocd "$CDADDSUBPACKAGES"
if [ $? -ge 1 ]; then
echo "failed"
break
fi
echo "ok (free space: $CDFREESPACE)"
fi
done
break
fi
done
INSTALLED=$INST
CDPACKAGES[$2]="${CDPACKAGES[$2]} $CDPACKAGES"
CDSPACE[$2]=$CDFREESPACE
echo "$CDPACKAGES" >> $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-cd$2
echo "CD$2: `wc -w $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-cd$2 | gawk '{ print $1 }'` packages, $CDOCCUPIEDSPACE bytes (free space:$CDFREESPACE)"
}
function generate_cd_lists() {
rm -f $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-*
# Assigning packages to CDs
#
INSTALLED=""
CDSPACE[1]=$CD1_SPACE
for i in `seq 2 7`; do
CDSPACE[$i]=$EMPTYCD_SPACE
done
# First step: distribute desired targets among CDs
generate_cd_list "$CD1_PACKAGES" 1
generate_cd_list "$CD2_PACKAGES" 2
generate_cd_list "$CD3_PACKAGES $CD2_PACKAGES" 3
generate_cd_list "$CD4_PACKAGES $CD3_PACKAGES $CD2_PACKAGES" 4
generate_cd_list "$CD7_PACKAGES" 7
# Second step: create devel + internationalizations CD(s)
generate_cd_list "all_packages" 5 "-devel$"
generate_cd_list "all_packages" 6 "\(-i18n-[a-zA-Z0-9@_\-]*$\)"
generate_cd_list "all_packages" 6 "\(^OpenOffice-\)"
# Third step: discard exceeding packages to cd6
generate_cd_list "all_packages" 7 "\(^OpenOffice-\)"
# Fourth step: put all other packages into remaining space on first CDs
for i in `seq 2 7`; do
generate_cd_list all_packages $i
done
# create a DVD packages list with all the CD's contents
unset DVD1PACKAGES
for cd in `seq 1 7`; do
DVD1PACKAGES="$DVD1PACKAGES `cat $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-cd$cd`"
done
echo "$DVD1PACKAGES" > $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-dvd1
}
function generate_cds_content() {
for currmedia in $MEDIA_LIST; do
generate_cd_content $MAKEDIST_TARGET-$PLATFORM-$currmedia $currmedia
done
}
#
# Main
#
TARGETDIR=$TOPDIR/targets
while test -n "$1" ; do
case $1 in
-u) UPDATE=$2
shift ;;
-t) shift
MAKEDIST_TARGET=$1
[ -d $TARGETDIR/$1 ] || {
echo "$mkcd_me: unknown target '$1'"; exit 1
}
;;
-h) usage; exit ;;
-f) force_update=1 ;;
-F) force_noupdate=1 ;;
-v) echo "$copyleft"; exit ;;
*) if test -z "$branch" ; then branch=$1
elif test -z "$MEDIA" ; then MEDIA=$1
elif test -z "$PLATFORM" ; then PLATFORM=$1
fi ;;
esac
shift
done
[ "$MAKEDIST_TARGET" ] || {
usage
exit 1
}
TARGETDIR=$TOPDIR/targets/$MAKEDIST_TARGET
. $TARGETDIR/settings.inc
# is list generation needed ?
echo "$UPDATE" | grep lists >/dev/null && update_lists=true
[ "$force_update" ] && update_lists="true"
[ -s $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-$MEDIA ] || update_lists="true"
#if [ ! "$update_lists" ]; then
# for DIR in $RPMDIR ; do
# if [ $DIR -nt $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-$MEDIA ]; then
# update_content=true
# if [ $UTILSDIR/Makefile.qilinux -nt $SOURCEDIR/packages.$MAKEDIST_TARGET-$PLATFORM-$MEDIA ]; then
# update_lists=true
# break
# fi
# fi
# done
#fi
[ "$update_lists" = "true" ] && {
echo "Generating media lists..."
generate_cd_lists
}
#[ "$update_content" = "true" ] &&
generate_cd_content $MAKEDIST_TARGET-$PLATFORM-$MEDIA $MEDIA
echo
exit 0