#!/bin/sh

# This script is for test mirroring and home usage
# I (danchev) use the mirrored files like:
# cd debian-cd-unofficial/sarge/jigdo/
# jigdo-lite sarge-alpha-1.jigdo
# ... Not downloading .template file 'sarge-alpha-1.template' already present ... 
# (NOTE: the corresponding .template file is found in the current directory;-)

# It is NOT suitable for mirrors to mirror these (not theirs) files *directly*, 
# because the downloading user will fetch the .jigdo file from you and the relevant 
# .template file from the original location (e.g. fsn.hu) ...
# In fact these Absolute Paths could be changed manually within the 
# .jigdo file Section [Image] Template= 
# However, note that jigdo-lite also supports relative URLs, so the 
# .jigdo file could contain just "Template=suite-arch-Number.template" 
# and the file would be fetched from the same directory as the .jigdo file 
# which contains that line.
# Unfortunately, the Debian .jigdos don't use relative URLs. :-/ This is
# because all template files on non-us.cdimage.d.o are supposed to be
# downloaded from us.cdimage.d.o. Obviously, this is not ideal for people who
# mirror the .jigdo/.template files. 
# The jigdo & debian-cd people are informed about that and This could be changed !

#
# Or you need to generate .jigdo and .template files with jigdo-file already having the ISO files
# 
# Or better use the debian-cd (/usr/share/doc/debian-cd/README.gz) with DOJIGDO=2 in CONF.sh 
# which will pipe the mkisofs output directly to jigdo-file and no ISO will be created, except 
# for the bootable images of alpha and powerpc, which will be deleted after .jigdo and .template 
# files are done.

##################################################################################################       
# 
#       Unofficial файловете се мирорват от ftp.fsn.hu, но могат и да бъдат получени локално на някой 
#	Debian mirror, чрез debian-cd и jigdo-file. Бъдещите версии на debian-cd ще могат да
#	генерират images и jigdo files от remote Debian mirror.
#       
#	Файловете .jigdo и .template са комплементарна двойка. Файла .jigdo се изтегля първи и показва пътя 
#	до съответния му .template. Това е зададено в секция [Image] Template=... в .jigdo. Файла .jigdo може 
#	да бъде в plain text или в gzip формат (file(1)), при което може да бъде разглеждан с zless, zcat, 
#	zgrep и т.н.
#	
#	URL-а към съответния .template във файла .jigdo може да бъде зададен като 
#       относителен или абсолютен път: 
#	
#	 * Относителния път е за предпочитане понеже когато мирорваме чужди .jigdo/.template файлове то после 
#	 и двата файла users ще изтеглят от нас.
#	
#	 * Ако е с абсолютен път то .jigdo ще бъде изтеглен от нас, а ще пренасочи user-а да изтегли 
#	 съответния .template от там откъдето ние сме ги мирорнали. Ако има чужди абсолютни пътища във 
#	 файловете .jigdo на сървъра, (т.е. на нашия сървър е мирорнато нещо което е генерирано на 
#	 друг сървър и са забити абсолютни пътища в .jigdo) то users ако за да теглят от нас и изпълнят:
#	
#	 # jigdo-lite our.server.tld/path/to/file.jigdo
#	
#	 или какво е в нашия случай за CD1 на Sid за i386:
#	
#        # jigdo-lite http://jigdo.debian-nikola.homelinux.net/debian-cd-unofficial/sid/jigdo/sid-i386-1.jigdo
#	
#	 .jigdo ще се изтегли от our.server.tld, а ще последва абсолютния път към .template зададен в така 
#	 изтегления .jigdo. Понеже тези файлове са мирорнати от foreign.server.tld и в.jigdo са зададени 
#	 абсолютни пътища към .template които сочат към foreign.server.tld, файла .template ще бъде изтеглен 
#	 от там.
#	
#	 За да предотрватят теглене от 2 сървъра (в което няма лошо разбира се) за users решението е:
#	
#	 # cd somedir/
#	 # wget our.server.tld/path/to/file.jigdo
#	 # wget our.server.tld/path/to/file.template
#	 # jigdo-lite file.jigdo
#	
#	 Така при подаването на файла .jigdo на jigdo-lite, съответния му .template ще бъде намерен локално и 
#	 няма да бъде теглен от абсолютния или относителен път зададен във файла .jigdo.
#	
#	 Ако имате стари CDROM-дискове или images ги монтирате за сканиране на .deb пакети във версии описани 
#	 във файла .template, за да не се теглят пак от FTP/HTTP debian/ и debian-non-US/ мирърите, което е и 
#	 една от целите на занятието. За FTP/HTTP debian/ и debian-non-US/ въвеждате български миръри.
#
#	 Още:  "Примери за сглобяване на ISO files с jigdo"
#	 http://debian-nikola.homelinux.net/debian-book/src/htmlsplit/node17.html

 
 NAME=debian-cd
 MSGFILE=$NAME.WORK_IN_PROGRESS_PLEASE_BE_PATIENT
 
 CMD="rsync -avz --delete-after --progress --stats --exclude \"*.iso\" --exclude \"*.raw\"  \
                 --recursive --links --perms --times --devices --timeout=600" 
 
 OFFICIAL=debian-cd-official
 UNOFFICIAL=debian-cd-unofficial

 # OFFICIAL Woody jigdo templates & images
 WOODYjigdo=us.cdimage.debian.org::jigdo-area/3.0_r2/jigdo/
 #WOODYjigdo=non-us.cdimage.debian.org::debian-jigdo/3.0_r2/jigdo/
 #WOODYjigdo=mirrors.kernel.org::debian-cd/jigdo-area/3.0_r2/jigdo/
 #WOODYiso=mirrors.kernel.org::debian-cd/jigdo/
 #TESTINGdi=gluck.debian.org::cdimage/testing/
 
 # UNOFFICIAL Woody, Sarge, Sid jigdo templates & images
  FSN=ftp.fsn.hu::cdimages/debian-unofficial/

 # Unofficial Woody Extra
 # iso files
  WOODYisoextra=$FSN/woody/

 # Unofficial Sarge
 # jigdo templates files & iso files
  SARGEjigdo=$FSN/sarge/jigdo/
 
 # Unofficial Sid
 # jigdo templates & iso files
  SIDjigdo=$FSN/sid/jigdo/

 # Check if directories exist
 
 for dir in $OFFICIAL                 \
            $UNOFFICIAL               \
  	    $OFFICIAL/woody/jigdo/    \
	    $OFFICIAL/testing/        \
	    $UNOFFICIAL/woody/        \
            $UNOFFICIAL/sarge/jigdo/  \
            $UNOFFICIAL/sid/jigdo/    \
 ; do 
 if [ -d "$dir" ] ; then
    echo "$dir exists" ;
 else
    echo "$dir created";
    mkdir -p "$dir" ;
 fi ;
 done
 
 # Execute
 
 touch $MSGFILE
 
 # Official
 ##########
 # $CMD $WOODYiso	  $OFFICIAL/woody/
 # $CMD $WOODYjigdo       $OFFICIAL/woody/jigdo/   > $NAME.OFFICIAL.woody.jigdo.LOG
 # $CMD $TESTINGdi        $OFFICIAL/testing/       > $NAME.OFFICIAL.testing.LOG

 # Unofficial
 ############
 # $CMD $WOODYisoextra    $UNOFFICIAL/woody/
 # $CMD $SARGEjigdo       $UNOFFICIAL/sarge/jigdo/ > $NAME.UNOFFICIAL.sarge.jigdo.LOG
   $CMD $SIDjigdo         $UNOFFICIAL/sid/jigdo/   > $NAME.UNOFFICIAL.sid.jigdo.LOG

 rm -rf $MSGFILE
