#!/bin/sh # (you might have to change this to /bin/bash or /usr/bin/bash, etc.) # # NTeX-ftp V1.2 # Download NTeX packages # # This script was derived from Volker B"orcher's get_ntex script. # # Copyright (C) 1996 Frank Langbein (langbein@mathematik.uni-stuttgart.de) # All rights reserved. This file is part of the NTeX system. # # 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., # 675 Mass Ave, Cambridge, MA 02139, USA. # # Usage: type `NTeX-ftp --help' for a description # script="`basename $0`" version=1.1 ############################################################################### # # make dir chain # mk_dirchain() { P="" for E in `echo $1 | sed -e 's,/, ,g'` do P="$P/$E" if [ ! -d "$P" ]; then if [ -r "$P" ]; then rm -f $P fi error="`mkdir $P 2>&1`" if [ "$?" != 0 -o -n "$error" ]; then echo "$script: failed to create $P" 1>&2 echo "$script: $error" 1>&2 exit 1 fi chmod 0755 "$P" fi done } ######## rtn_dir ############################################################## # Returns the name of the directory where the file is # expected to be in, e.g. `rtn_dir nb-cm' returns `base' rtn_dir () { case $1 in nb-*) echo "base" ;; nx-*) echo "extras" ;; nf-*) echo "fonts" ;; nj-*) echo "japanese" ;; nl-*) echo "languages" ;; ns-*) echo "sources" ;; *) echo "unknown" ;; esac } PKGS="" SETS="" ROOT="" FILES="" setu=f update=f ntexversion=2.0.0 sets=f systems=- export systems setd=f distdir="" export distdir setsite=f site="" export site sitedir="" export sitedir next="" short_help="$script: type \`$script --help' for help" for arg in $* do case $arg in --update=*) if [ "$setu" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setu=t update=t ntexversion="`echo $arg | cut -d= -f2-`" ;; --update|-u) if [ "$setu" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setu=t update=t next=$next"update:" ;; --file=*) FILES="$FILES `echo $arg | cut -d= -f2-`" ;; --file|-f) next=$next"file:" ;; --systems|-s) if [ "$sets" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi sets=t next=$next"systems:" ;; --systems=*) if [ "$sets" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi sets=t systems="`echo $arg | cut -d= -f2-`" ;; --directory|-d) if [ "$setd" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setd=t next=$next"distdir:" ;; --directory=*) if [ "$setd" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setd=t distdir="`echo $arg | cut -d= -f2-`" ;; --site) if [ "$setsite" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setsite=t next=$next"site:" ;; --site=*) if [ "$setsite" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setsite=t h="`echo $arg | cut -d= -f2-`" site="`echo $h | cut -d: -f1`" sitedir="`echo $h | cut -d: -f2-`" ;; --master) if [ "$setsite" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setsite=t site=web.mathematik.uni-stuttgart.de sitedir=/pub/ntex/ntex ;; --ctan-germany) if [ "$setsite" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setsite=t site=ftp.dante.de sitedir=/tex-archive/systems/unix/linux/ntex ;; --ctan-uk) if [ "$setsite" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setsite=t site=ftp.tex.ac.uk sitedir=/tex-archive/systems/unix/linux/ntex ;; --sunsite) if [ "$setsite" = t ]; then echo "$script: $arg already specified, option mismatch" 1>&2 echo $short_help 1>&2 exit 1 fi setsite=t site=sunsite.unc.edu sitedir=/pub/Linux/apps/tex/ntex ;; --version|-v) echo "NTeX NTeX-ftp ($script) V$version" exit 0 ;; --copyright|--copyleft) cat <] {} package name set: base, extras, languages, japanese, fonts, sources ntex for all base installation files all for all sets and all base installation files info for INDEX and help files The binary packages will be downloaded for the systems given by the --systems option and the involved sets. Options: --update=| -u get updates for given sets and all base installation files where is the currently installed NTeX version --file=| -f read packages or sets from --systems=| -s get binaries for system , default is i486-linux more systems can be given as a list separated by : if is empty, no binaries are downloaded if is \`all', get all binary sets --directory==| -d directory where the downloaded files are stored (default is \`.') --site=: download NTeX from directory on --master download NTeX from NTeX´s master archive --ctan-germany download NTeX from ftp.dante.de --ctan-uk download NTeX from ftp.tex.ac.uk --sunsite download NTeX from sunsite.unc.edu --copyright| --copyleft print copyright information --help|-h give this help --version|-v display version number For the automatic ftp login procedure you will need a file \`~/.netrc' with an entry for the site of your choice. (Alternatively a \`default' entry - but not all ftp daemons support it). \`$script' will figure it out for itself if your \`~/.netrc' file exists and is OK or not, and will tell you what to do, if not. EOD exit 0 ;; -*) echo "$script: illegal option $arg" 1>&2 echo $short_help 1>&2 exit 1 ;; *) if [ -n "$next" ]; then c="`echo $next | cut -d: -f1`" next="`echo $next | cut -d: -f2-`" if [ "$c" = file ]; then FILES="$FILES $arg" elif [ "$c" = systems ]; then systems="$arg" elif [ "$c" = distdir ]; then distdir="$arg" elif [ "$c" = update ]; then ntexversion="$arg" elif [ "$c" = site ]; then site="`echo $arg | cut -d: -f1`" sitedir="`echo $arg | cut -d: -f2-`" fi else case "$arg" in base|extras|languages|japanese|fonts|sources) test -z "`echo $SETS | grep $arg`" && SETS="$SETS $arg" ;; ntex) ROOT="BUGS CHANGES INDEX INSTALL InstallNTeX NTeX.announce NTeX.lsm README.NTeX RELEASE ntex.pkg ntex-guide.ascii ntex-guide.ps.gz" ;; all) ROOT="BUGS CHANGES INDEX INSTALL InstallNTeX NTeX.announce NTeX.lsm README.NTeX RELEASE ntex.pkg ntex-guide.ascii ntex-guide.ps.gz ntex-guide.twoside.ps.gz" SETS="base extras languages japanese fonts sources" ;; info) test -z "$ROOT" && ROOT="BUGS CHANGES INDEX INSTALL NTeX.announce NTeX.lsm README.NTeX RELEASE" ;; *) PKGS="$PKGS $arg" ;; esac setP=t fi ;; esac done if [ -z "$ROOT$PKGS$SETS$FILES" ]; then echo "$script: no package, sets, etc. given" 1>&2 echo "$short_help" 1>&2 exit 1 fi if [ "$setsite" = f ]; then echo "$script: no site for downloading given" 1>&2 echo "$short_help" 1>&2 exit 1 fi # check .netrc if [ -z "`grep $site $HOME/.netrc 2>/dev/null`" -a \ -z "`grep default $HOME/.netrc 2>/dev/null`" ]; then echo "$script: ~/.netrc not configured." 1>&2 echo "Add one of the following two lines to it:" 1>&2 echo " machine $site login anonymous password " 1>&2 echo "or: default login anonymous password " 1>&2 echo "and shut it for all others by \"chmod 600 ~/.netrc\"" 1>&2 exit 1 fi if [ "$systems" = - ]; then systems=i486-linux else systems="`echo $systems | sed -e 's,:, ,g'`" fi test -z "$distdir" && distdir=. if [ ! -d "$distdir" ]; then echo "$script: $distdir is no directory" 1>&2 echo $short_help 1>&2 exit 1 fi if [ -z "$NTEX_TMPDIR" ]; then NTEX_TMPDIR="/tmp/NTeX-ftp.$$" export NTEX_TMPDIR fi mk_dirchain $NTEX_TMPDIR trap "cd /; rm -rf $NTEX_TMPDIR; exit 0" 0 1 2 15 # Read FILES for f in $FILES do if [ -r "$f" ]; then for f in `cat $f | grep -v \#` do case $f in base|extras|languages|japanese|fonts|sources) test -z "`echo $SETS | grep $arg`" && SETS="$SETS $arg" ;; ntex) ROOT="BUGS CHANGES INDEX INSTALL InstallNTeX NTeX.announce NTeX.lsm README.NTeX RELEASE ntex.pkg ntex-guide.ascii ntex-guide.ps.gz" ;; all) ROOT="BUGS CHANGES INDEX INSTALL InstallNTeX NTeX.announce NTeX.lsm README.NTeX RELEASE ntex.pkg ntex-guide.ascii ntex-guide.ps.gz ntex-guide.twoside.ps.gz" SETS="base extras languages japanese fonts sources" ;; info) test -z "$ROOT" && ROOT="BUGS CHANGES INDEX INSTALL NTeX.announce NTeX.lsm README.NTeX RELEASE" ;; *) PKGS="$PKGS $arg" ;; esac done else echo "$script: can't read $f" 1>&2 echo $short_help 1>&2 exit 1 fi done cd $distdir # Update if [ "$update" = t -a -n "$SETS$PKGS" ]; then # get all base files when updating ROOT="BUGS CHANGES INDEX INSTALL InstallNTeX NTeX.announce NTeX.lsm README.NTeX RELEASE ntex.pkg ntex-guide.ascii ntex-guide.ps.gz" # download CHANGES echo "Downloading CHANGES from $site..." ftp $site <&2 echo "$script: please download the packages without the update option" 1>&2 echo $short_help 1>&2 exit 1 elif [ "$s3" -gt "$n3" ]; then newer=t fi fi fi if [ "$newer" = t ]; then echo "Updating from $ntexversion to $siteversion" egrep '^N(.-|TeX V[1-9])' CHANGES | cut -d, -f1 \ | sed -e "s,NTeX V,#release," -e "s, V.*\$,," -e 's,^.*Changes$,,' \ | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' \ | awk -v current=$ntexversion 'BEGIN { doprint=1 } { if(doprint==1) { print $1; if($0 ~ current) {doprint=0} }}' > $NTEX_TMPDIR/list ## to cope with wildcards in changes (e.g. ns-*) - ## we then have to get the whole directory NEWSETS="" for this in `grep "\*" $NTEX_TMPDIR/list` do s="`rtn_dir $this`" test -n "`echo $SETS | grep $s`" -a \ -z "`echo $NEWSETS | grep $s`" && NEWSETS="$NEWSETS $s" done NEWPKGS="" for p in $PKGS do test -n "`grep ^$p\$ $NTEX_TMPDIR/list`" -a \ -z "`echo $NEWPKGS | grep $p`" && NEWPKGS="$NEWPKGS $p" done for f in `grep -v "\*" $NTEX_TMPDIR/list` do if [ "`echo $f- | cut -d- -f2`" = bin ]; then sys="`echo $f-- | cut -d- -f3-`" test -z "`echo $systems | grep $sys`" && f=unknown fi s="`rtn_dir $f`" test -n "`echo $SETS | grep $s`" -a \ -z "`echo $NEWSETS | grep $s`" -a \ -z "`echo $NEWPKGS | grep $f`" && NEWPKGS="$NEWPKGS $f" done PKGS="$NEWPKGS" SETS="$NEWSETS" else echo "$script: You already have the latest NTeX version ($ntexversion)" 1>&2 exit 0 fi else echo "$script: unable to get the file CHANGES" 1>&2 echo "$script: ceck site, local and remote directory settings" 1>&2 echo $short_help 1>&2 exit 1 fi fi # figure out which binary packages have to be installed BINPKGS="" BPKGS="" XPKGS="" LPKGS="" FPKGS="" JPKGS="" SPKGS="" for p in $PKGS do if [ "`echo $p- | cut -d- -f2`" = bin ]; then BINPKGS="$BINPKGS $p" else case "$p" in nb-*) BPKGS="$BPKGS $p" ;; nx-*) XPKGS="$XPKGS $p" ;; nl-*) LPKGS="$LPKGS $p" ;; nj-*) JPKGS="$JPKGS $p" ;; nf-*) FPKGS="$FPKGS $p" ;; ns-*) SPKGS="$SPKGS $p" ;; esac fi done # create ftp script rm -f $NTEX_TMPDIR/ftp echo "bin" >$NTEX_TMPDIR/ftp echo "prompt off" >>$NTEX_TMPDIR/ftp if [ -n "$ROOT" ]; then echo "cd $sitedir" >>$NTEX_TMPDIR/ftp for f in $ROOT do echo "get $f" >>$NTEX_TMPDIR/ftp done fi for s in $SETS do echo "cd $sitedir/$s" >>$NTEX_TMPDIR/ftp echo "lcd $s" >>$NTEX_TMPDIR/ftp mk_dirchain `pwd`/$s echo "mget *" >>$NTEX_TMPDIR/ftp echo "lcd .." >>$NTEX_TMPDIR/ftp done for i in base:BPKGS extras:XPKGS languages:LPKGS fonts:FPKGS \ japanese:JPKGS sources:SPKGS do v="`echo $i: | cut -d: -f2`" pk=`eval echo '$'$v` if [ -n "$pk" ]; then d="`echo $i | cut -d: -f1`" echo "cd $sitedir/$d" >>$NTEX_TMPDIR/ftp echo "lcd $d" >>$NTEX_TMPDIR/ftp mk_dirchain `pwd`/$d for p in $pk do echo "get $p.pkg" >>$NTEX_TMPDIR/ftp done echo "lcd .." >>$NTEX_TMPDIR/ftp fi done for sys in $systems do echo "cd $sitedir/systems/$sys" >>$NTEX_TMPDIR/ftp echo "lcd systems/$sys" >>$NTEX_TMPDIR/ftp mk_dirchain `pwd`/systems/$sys for s in $SETS do case $s in base) i=b ;; extras) i=x ;; languages) i=l ;; japanese) i=j ;; fonts) i=f ;; *) i="" ;; esac test -n "$i" && echo "get n$i-bin-$sys.pkg" >>$NTEX_TMPDIR/ftp done echo "lcd ../.." >>$NTEX_TMPDIR/ftp done for p in $BINPKGS do sys="`echo $p | cut -d- -f3-`" echo "cd $sitedir/systems/$sys" >>$NTEX_TMPDIR/ftp echo "lcd systems/$sys" >>$NTEX_TMPDIR/ftp mk_dirchain `pwd`/systems/$sys echo "get $p.pkg" >>$NTEX_TMPDIR/ftp echo "lcd ../.." >>$NTEX_TMPDIR/ftp done echo "bye" >>$NTEX_TMPDIR/ftp # download if grep get $NTEX_TMPDIR/ftp 1>/dev/null 2>&1; then echo "Connecting to $site ..." ftp $site <$NTEX_TMPDIR/ftp fi