Actually attaching the file this time...

On Sat, Jun 20, 2009 at 01:54:28AM +0000, Tzafrir Cohen wrote:
> On Fri, Jun 19, 2009 at 06:23:08AM -0500, Joseph Rawson wrote:
> > On Friday 19 June 2009 05:09:31 Tzafrir Cohen wrote:
> > > On Fri, Jun 19, 2009 at 01:52:43AM -0500, Joseph Rawson wrote:
> > > > would be much more interested in making a tool that would make it easier
> > > > to manage local/partial debian mirrors (i.e. one that helped resolve the
> > > > dependencies), rather than have an apt-get wrapper.  I also think that
> > > > once such a tool is made, it would make it easier to build an apt-get
> > > > wrapper that works with it.  I don't think that viewing the problem with
> > > > an "apt-get wrapper" solution is the best way to approach it, but I do
> > > > think that it would be valuable once the underlying problems are solved.
> > >
> > > And reprepro does not fit the bill because?
> > >
> > It fits part of the bill, as it's an excellent tool for maintaining a 
> > repository, but it doesn't resolve dependencies (nor should it).
> 
> Just in case it might help, here's a script we used internally (at the
> Sarge time) to maintain a dummy repository that would help us eventually
> resolve an original list of packages to a complete list of packages we
> ask a reprepro source to update.
> 
> -- 
> Tzafrir Cohen         | tzaf...@jabber.org | VIM is
> http://tzafrir.org.il |                    | a Mutt's
> tzaf...@cohens.org.il |                    |  best
> ICQ# 16849754         |                    | friend
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
> 

-- 
Tzafrir Cohen         | tzaf...@jabber.org | VIM is
http://tzafrir.org.il |                    | a Mutt's
tzaf...@cohens.org.il |                    |  best
ICQ# 16849754         |                    | friend
#!/bin/bash

# using bash-specific PIPESTATUS

CMD=`basename $0`

REPREPRO=reprepro
BASE_DIR=repo
APT_BASE_DIR=${BASE_DIR}/Aptdir
APT_DIR=${APT_DIR:-${APT_BASE_DIR}/unstable}
MAIN_REPO=/home/repo
PACKAGES_LIST_FILE=packages
STATIC_DIR=$MAIN_REPO/static
STATIC_INST=$MAIN_REPO/static_inst
INSTALLER_PATH=$BASE_DIR/dists/sarge/main/installer-i386/current
CD_OVERRIDE=cd-override/cd

set -e

usage() {
        echo >&2 "apter: apt resolver wrapper"
        echo >&2 "       (functionality varies by basename of \$0)"
        echo >&2 "Usage: $0 <setup|generate|refresh>"
}

# $1: file
# $2: condition
get_entry() {
  awk <$BASE_DIR/conf/$1 -v RS='\n\n' "/\<$2\>\n/ {print \$0}" 
  #echo >&2 "printed updates section $2."
}

# $1: file (updates/distributions)
# $2: condition
# $3: field name
get_field() {
        get_entry "$1" "$2" | grep "^$3: " | cut -d: -f2-
}

dists_list() {
        awk '/^Codename: / {print $2}' $BASE_DIR/conf/distributions
}

case "$CMD" in
        apt-get|apt-cache|aptitude)
                exec $CMD \
                        -o Dir=$PWD/$APT_DIR \
                        -o Dir::State::status=$PWD/$APT_DIR/var/lib/dpkg/status 
\
                        "$@"
                ;;
        apter)
                case "$1" in
                setup)
                        for dist in `dists_list`
                        do
                                APT_DIR=$APT_BASE_DIR/$dist
                                export APT_DIR
                        
                                for dir in \
                                        etc/apt var/lib/apt/lists/partial \
                                        var/lib/dpkg 
var/cache/apt/archives/partial
                                do mkdir -p $APT_DIR/$dir
                                done
                                touch $APT_DIR/var/lib/dpkg/status
                                # relevant update sources:
                                update_sources=`get_field distributions 
"Codename: $dist" Update`
                                (
                                        for upd in $update_sources
                                        do 
                                                get_entry updates "Name: $upd"
                                                echo ''
                                        done
                                ) | tools/updates2sources 
>$APT_DIR/etc/apt/sources.list
                                cat <<EOF >$APT_DIR/etc/apt/preferences
# give our packages a higher priority:
Package: *
Pin: release o=Xorcom
Pin-Priority: 600
EOF
                        done
                        ;;
                generate)
                        # setup the apt wrapper:
                        $0 setup
                        $0 refresh
                        ;;
                refresh) 
                        rm -rf $BASE_DIR/{db,dists,lists,pool}
                        $0 refresh-nodel
                        ;;
                upgrade|refresh-nodel) 
                        apt_cmd=`dirname $0`/apt-get
                        for file in `ls $STATIC_DIR`
                        do rsync -a --delete $STATIC_DIR/$file $BASE_DIR
                        done
                        # note: no --delete here
                        rsync -aC $CD_OVERRIDE/* $BASE_DIR/
                        
                        #rm -f $BASE_DIR/conf/*.updates
                        for dist in `dists_list`
                        do
                                if `echo $PACKAGES_LIST_FILE*.$dist | grep -q 
'\*'`
                                then
                                        #echo "(Distro $dist has no packages 
lists. Skipped)"
                                        continue
                                fi
                                echo "refreshing distro $dist."
                                APT_DIR=$APT_BASE_DIR/$dist
                                export APT_DIR
                                # Resolve required packages to packages from 
                                # specific repositories:
                                for pack_list in $PACKAGES_LIST_FILE*.$dist
                                do
                                        packages=`grep -v '^#' $pack_list` 
                                        $apt_cmd update
                                        $apt_cmd install -y --dry-run $packages 
\
                                        | tools/aptdry2lists

                                        # bail out if apt fail. $PIPESTATUS is 
${PIPESTATUS[0]}
                                        if [ $PIPESTATUS -ne 0 ]; then 
                                                echo >&2 "Error demo-installing 
packages from $pack_list"
                                                echo >&2 "Try running 
APT_DIR=$APT_DIR $apt_cmd install --dry-run \`grep -v '^#' $pack_list\`"
                                                exit $PIPESTATUS; 
                                        fi
                                done
                                chmod -R g+w $APT_DIR/var 2>/dev/null || true
                                if [  ! -r 
$BASE_DIR/dists/$dist/main/installer-i386 ]
                                then
                                        mkdir -p $BASE_DIR/dists/$dist/main
                                        ln -s ../../sarge/main/installer-i386 
$BASE_DIR/dists/$dist/main/installer-i386 
                                fi
                        done
                        for file in $BASE_DIR/conf/*.updates.unsorted
                        do
                                new_file=`echo $file | sed -e 's/.unsorted$//'`
                                sort -u $file >$new_file
                                rm $file
                        done
                        
                        # Recreate repository:
                        $REPREPRO --noskipold --ask-passphrase 
--ignore=unknownfield -b $BASE_DIR update
                        $REPREPRO -b $BASE_DIR createsymlinks
                        mkdir -p $INSTALLER_PATH
                        rsync -aq --delete $STATIC_INST/ $INSTALLER_PATH
                        ;;
                *) 
                        echo >&2 "Unknown apter command $1."
                        usage
                        exit 1
                        ;;
                esac
                ;;
        *)
                echo >&2 "Unknown apter functionality $0"
                exit 2
                ;;
esac    

Reply via email to