[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

apt-update: caching package lists for different debian releases



Dear Apt-Development team,

I run sarge with lots of user software (like gnome, firefox, and
thunderbird) from etch or sid. I often want to apt-get update for either
sarge, etch or sid, and see just packages from that release. I don't
want to always have to edit /etc/apt/sources.list and I also don't want
the package lists to get re-downloaded every time I switch back and
forth between releases.

I run this script instead of executing apt-get update and use it all the
time for switching back and forth between debian releases
(sarge/etch/sid/experimental/cdrom) and caching the package lists, so
they don't have to get re-downloaded. There probably is a much more
elegant method of doing this using /etc/apt/apt.conf, but I don't know
it and this works for me.

The basic idea is that the script is run with one parameter specifying
the release, e.g.:

# apt-update etch

The script caches any downloaded package lists not in the desired
release, looks for any previously cached package lists for the desired
release and copies them to the appropriate directory, parses
/etc/apt/sources.list.base and creates a corresponding
/etc/apt/sources.list, and then executes apt-get update.

The script is nothing special, so I'm really just trying to
contribute the idea. I've gpl'd the script. Feel free to use any part or
idea from it as you see fit.

I've also included my /etc/apt/sources.list.base as an example, so you
can see what the script is working with.


cheers,

josh buhl


##########################snip#####################################

#!/bin/bash
#
# $Id: apt-update,v 1.1.1.1 2006/01/01 18:03:08 root Exp $
#
# /root/bin/apt-update
#
# run apt-get update for various dists and cache downloaded Package files
#
# Copyright (C) 2005 Josh Buhl
#
#  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.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330,
#  Boston, MA 02111-1307, USA.

mnt=mnt

stable=sarge
testing=etch
unstable=sid
experimental=experimental
marillat=marillat
cdrom=cdrecorder
image=file:/$mnt

sourcelist=/etc/apt/sources.list
sourcebase=/etc/apt/sources.list.base

archive=/var/tmp/Package_lists

declare -a dists

dists=(
$stable
$testing
$unstable
$experimental
$marillat
cdrom
image
)

declare -a pseudonyms

pseudonyms=(
stable
testing
unstable
$experimental
$marillat
$cdrom
_$mnt
)


usage() {
    echo "usage: update-apt
{cdrom|image|$stable|$testing|$unstable|$marillat|$experimental}"
}


##parameter checking
dist=$1
valid=0

for (( i=0; i< ${#dists[*]}; i++  )); do
    if [[ ${dists[$i]} = $dist ]]; then
	valid=1
	pseudonym=${pseudonyms[$i]}
	#echo caught $dist, pseudonym is $pseudonym
    fi
done


if [[ $# != 1 || $valid != 1 ]] ; then
    usage
    exit 1
fi


#cache package lists
cd /var/lib/apt/lists

for (( i=0; i< ${#dists[*]}; i++  )); do
    foo=${dists[$i]}
    bar=${pseudonyms[$i]}
    if [ ! -d $archive/$foo ] ; then
	mkdir -p $archive/$foo
    fi	
    if [[ $foo != $dist ]]; then
	mv *$foo* $archive/$foo/ 2> /dev/null
	mv *$bar* $archive/$foo/ 2> /dev/null
    else
	mv $archive/$foo/* . 2> /dev/null
    fi
done


##create new sourcelist
case $dist in
    cdrom)
 	cat $sourcebase | grep -v "#" | grep $cdrom > $sourcelist
 	;;

    image)
 	cat $sourcebase | grep -v "#" | grep $image > $sourcelist
 	;;

    *)
	cat $sourcebase | grep -v "#" | grep $dist | grep -v $image | grep -v
$cdrom  > $sourcelist
        #any deb sources that don't use release names
	cat $sourcebase | grep -v "#" | grep $pseudonym | grep -v $image | grep
-v $cdrom >> $sourcelist

        #we always want the marillat line, but not twice (marillat line
contains unstable and marillat)
	grep $marillat $sourcelist > /dev/null || cat $sourcebase | grep -v "#"
| grep $marillat >> $sourcelist
	cp -a $archive/$marillat/* /var/lib/apt/lists 2> /dev/null
	;;
esac



##update package lists
apt-get update
#dpkg --update-avail

synaptic &
wait
exit

## building blocks
# case $dist in
#     ${dists[0]}|${dists[1]}|${dists[2]}|${dists[3]})
# 	for i in "${dists[@]}" ; do
# 	    echo "i is $i dist is $dist"
# 	    if [[ $i = $dist ]]; then
# 		echo caught $i
# 	    fi
# 	done
# 	;;
#     *)
# 	echo caught nothing
# 	exit 1
# 	;;
# esac

# for (( i=0; i< ${#dists[*]}; i++  )); do
#     if [[ $i != $dist ]]; then
#     fi
#done
# ############
# exit
# ############


##########################snip#####################################

###/etc/apt/sources.list.base

## cdrom or image
deb file:/media/cdrecorder testing main contrib
deb file:/mnt testing main contrib

# Sarge
deb ftp://ftp.de.debian.org/debian-non-US sarge/non-US main contrib non-free
deb ftp://ftp.de.debian.org/debian sarge main contrib non-free
#deb ftp://ftp.fr.debian.org/debian-non-US sarge/non-US main contrib
non-free
#deb ftp://ftp.fr.debian.org/debian sarge main contrib non-free
#deb-src ftp://ftp.de.debian.org/debian sarge main contrib non-free


# Etch
deb ftp://ftp.de.debian.org/debian etch main contrib non-free
#deb ftp://ftp.fr.debian.org/debian etch main contrib non-free
#deb-src ftp://ftp.de.debian.org/debian etch main contrib non-free


# Sid
#deb ftp://ftp.fr.debian.org/debian sid main contrib non-free
deb ftp://ftp.de.debian.org/debian sid main contrib non-free
#deb-src ftp://ftp.de.debian.org/debian sid main contrib non-free

#dvd::rip, transcode, etc.
deb ftp://ftp.nerim.net/debian-marillat/ sid main

# Debian experimental
#deb ftp://ftp.debian.org/debian ../project/experimental main
# GNOME 2.10 pending packages
#deb http://pkg-gnome.alioth.debian.org/debian experim



Reply to: