#!/bin/sh #(C) July 2001 Thomas Guettler http://www.thomas-guettler.de #Feedback is Welcome! #This script is in the public domain # #Create a debian mirror from a CD set #It only handels binary packages # # Notes: # ------ # + CD must either have "/debian/pool" or "/pool" # + scanpackages: get the files from ftp.debian.org/debian/indices # zcat *.gz | sort | gzip > override.gz # + your /etc/apt/sources.list should look like: # deb file:/debian_mirror ./ # + Warnings abot repeated packages while doing "scanpackages" can # be ignored #TODO: # --> exclude file: file of regex's matching files which should # not be copied to the mirror (see ~/.debian-cd2mirror-exclude) ###Start User Config ###End User Config function usage(){ SCRIPT_NAME=`basename $0` echo "$SCRIPT_NAME: Create a Debian mirror from a CD set" echo "Usage: " echo " $SCRIPT_NAME copy cdrom_dir mirror_dir" echo " $SCRIPT_NAME scanpackages mirror_dir override_file" echo echo " copy: Copies the packages to the mirror" echo " cdrom_dir: where your cdrom gets mounted (/cdrom)" echo " mirror_dir: directory of your mirror (/debian)" echo " scanpackages: Create Packages.gz via dpkg-scanpackages " echo " mirror_dir: directory of your mirror (/debian)" echo " override_file: You get this file from the debian mirror" echo " (/debian/indices/override.VERSION.*.gz)" echo " see note in this script, too" echo echo " Copy all CDs to your mirror with \"copy\". Then you might want" echo " to add your own packages to the mirror. Then use " echo " \"scanpackages\" to create the Packages.gz files" echo exit 1 } function copy(){ mount $CDROM CDROM_DEBIAN=$CDROM/debian if [ ! -d $CDROM/pool ]; then if [ ! -d $CDROM/debian/pool ]; then echo "Error: CD does not have a pool directory. Exiting" umount $CDROM exit 1 else CDROM_DEBIAN=$CDROM/debian fi else CDROM_DEBIAN=$CDROM fi echo "Copying from $CDROM_DEBIAN to $MIRROR." echo "This takes 3-14 minutes depending on disk speed" echo "Start: " `date` if [ -r $CDROM/.disk/info ]; then CD_INFO=`cat $CDROM/.disk/info` else CD_INFO="unkown" fi echo "Coping packages from $CD_INFO onto mirror" rsync -a --exclude Packages \ --exclude Packages.gz \ --exclude Packages.cd \ --exclude Packages.cd.gz \ $CDROM_DEBIAN/dists $CDROM_DEBIAN/pool $MIRROR # old way. Without rsync # (cd $CDROM_DISTS && tar clf - --exclude Packages \ # --exclude Packages.gz \ # --exclude Packages.cd \ # --exclude Packages.cd.gz . ) \ # | (cd $MIRROR/dists && tar xfp - ) echo `date`: added packages from "$CD_INFO" >> $MIRROR/debian-cd2mirror.log echo "End: " `date` umount $CDROM echo "Repeat this for every CD you want to add to the mirror" #now beep a little (echo -ne \\a; sleep 1;echo -ne \\a; sleep 1;echo -ne \\a; sleep 1; echo -ne \\a; sleep 1;echo -ne \\a; sleep 1;echo -ne \\a; sleep 1; echo -ne \\a; sleep 1;echo -ne \\a; sleep 1;echo -ne \\a; sleep 1;)& } function scanpackages(){ echo "Creating Packages.gz with dpkg-scanpackages" echo "This takes about 18-30 minutes on my computer" echo "Start: " `date` #for p_dir in `find . | grep -E 'binary-[^/]*$'`; do # p_file=$p_dir/Packages # dpkg-scanpackages $p_dir $OVERRIDE_FILE > \ # $p_file # gzip -c $p_file > $p_file.gz # echo "$p_file gzipped" #done cd $MIRROR dpkg-scanpackages ./ $OVERRIDE_FILE | gzip > Packages.gz echo "End: " `date` } ### Main type dpkg-scanpackages 1>/dev/null 2>&1 if [ $? != "0" ]; then echo "dpkg-scanpackages is not installed: Install dpkg-dev" exit 1 fi if [ $# -lt 3 ]; then usage fi if [ $1 = "copy" ]; then CDROM=$2 MIRROR=$3 copy elif [ $1 = "scanpackages" ];then MIRROR=$2 OVERRIDE_FILE=$3 scanpackages else usage fi