#! /bin/sh # # author: miguel & hackbard # # This is the Download script used to fetch all the hdw-linux sources # wheather it is from their original locations or from a mirror site # # To run the script use ./scripts/Download [ options ] mirror="" package="" no_cvs="0" list_op="" remove="0" while [ "$1" ] ; do case "$1" in -mirror) mirror="$2" ; shift 2 ;; -package) package="$2" ; shift 2 ;; -list-missing) list_op="missing" ; shift 1 ;; -list-broken) list_op="broken" ; shift 1 ;; -list-unknown) list_op="unknown" ; shift 1 ;; -remove-unknown) list_op="unknown" remove="1" ; shift 1 ;; -check-new) list_op="check_new" ; shift 1 ;; -no_cvs) no_cvs="1" ; shift 1 ;; *) echo echo "usage:" echo echo " ./scripts/Download" echo " ./scripts/Download -package " echo echo " use -no_cvs option to avoid refetching cvs-packages" echo echo "to fetch sources from a mirror:" echo echo " ./scripts/Download -mirror " echo " ./scripts/Download -package -mirror " echo echo "other options:" echo echo " ./scripts/Download -list-missing" echo " ./scripts/Download -list-broken" echo " ./scripts/Download -list-unknown" echo " ./scripts/Download -check-new" echo " ./scripts/Download -remove-unknown" echo " ./scripts/Download -no_cvs" echo exit 1 ;; esac done # we need to know some of the hdw specific variables. . ./Config # running subroutines . ./scripts/subroutines wget_cmd="wget --tries=3 --passive-ftp " curl="curl --disable-epsv -s" # -list-missing & -list-broken (& -list-unknown) if [ ! -z "$list_op" ] ; then for dir in `ls -A --ignore="CVS" ./download`; do if [ -f ./download/$dir/PKGS ] ; then cat ./download/$dir/PKGS | while read pkg file location; do case "$list_op" in broken) server=`echo $location | awk -F: '{print $1}'` if [ "$server" = "ftp" ] ; then # not very nice! if $wget_cmd -O .ftp-index \ $location 2> /dev/null; then [ -z "`grep $file .ftp-index`" ] && \ echo_r "$dir $file broken ($server - package)" rm -f .ftp-index else echo_r "$dir $file broken ($server - directory)" fi elif [ "$server" = "http" ] ; then $wget_cmd --spider $location$file 2> /dev/null [ "$?" = "1" ] && \ echo_r "$dir $file broken ($server - package)" else echo "$dir $file -> unable to search on $server server" fi ;; check_new) if [ -z "`type -p curl`" ]; then echo "you need curl installed to use -check-new" exit 1 fi prune=".sign|.deb|.rpm|.md5|.diff|.patch" c_v="`grep '^#\ \[V\]' \ \`find packages/*/$pkg/$pkg\` | sed 's/^#\ \[V\]//'`" server=`echo $location | awk -F: '{print $1}'` ending="`detect_file_ending $file`" mkdir -p ./check_tmp if [ "$server" = "http" ] ; then $curl $location | grep $pkg | grep $ending | grep -vE $prune | \ sed -e 's/imgsrc.*"\//IMG\ "/'g -e 's///'g | \ sed -e 's/ahref/A\ /'g -e 's/<\/a/<\/A/'g | \ sed -e 's///'g -e 's/<\/A.*//'g | \ sed 's/\ //g' > ./check_tmp/all-files elif [ "$server" = "ftp" ] ; then $curl $location | tr -s ' ' | cut -f9 -d' ' | \ grep $pkg | grep $ending | grep -vE $prune \ > ./check_tmp/all-files else echo "$pkg: only http/ftp servers supported" exit 1 fi if [ -f ./check_tmp/all-files ]; then echo "$pkg:" echo "current version: $c_v" echo "new versions:" cat ./check_tmp/all-files echo fi ;; missing) if [ "`echo $location | awk -F: '{ print $1 }'`" = "cvs" ]; then if [ "$no_cvs" = "0" ] ; then echo -n "$pkg is cvs-package, " if [ ! -f ./download/$dir/$pkg/$file ] ; then echo_r "missing" else echo_g "available" fi fi else if [ ! -f ./download/$dir/$pkg/$file ] ; then echo -n "$pkg " echo_r "missing" fi fi ;; unknown) if [ -d ./download/$dir/$pkg ] ; then objects="`ls -A ./download/$dir/$pkg`" for i in $objects; do known_f="`grep ^$pkg ./download/$dir/PKGS | \ awk '{ print $2 }'`" if [ -z "`echo $known_f | grep $i`" ] ; then echo "./download/$dir/$pkg/$i unknown" if [ "$remove" = "1" ] ; then echo "removing ..." rm ./download/$dir/$pkg/$i fi fi done fi ;; esac done fi done exit 0 fi # download a package if [ ! -z "$package" ] ; then for dir in `ls -A --ignore="CVS" ./download`; do if [ -f ./download/$dir/PKGS ] ; then cat ./download/$dir/PKGS | while read pkg file location; do if [ "$package" = "$pkg" ] ; then is_cvs="`echo $location | awk -F: '{ print $1 }'`" # cvs if [ "${is_cvs}" = "cvs" -o "${is_cvs}" = "sshcvs" ] ; then if [ "$no_cvs" = "0" ] ; then user=`echo $location | awk -F: '{ print $2 }'` loc=`echo $location | awk -F: '{ print $3 }'` repos=`echo $location | awk -F: '{ print $4 }'` module=`echo $location | awk -F: '{ print $5 }'` #passwd=`echo $location | awk -F: '{ print $6 }'` echo "downloading $pkg using cvs ..." [ ! -f $HOME/.cvspass ] && touch $HOME/.cvspass mkdir -p ./download/$dir/$pkg ; cd ./download/$dir/$pkg rm -rf $file $module dlerror=0 if [ "${is_cvs}" = "cvs" ] ; then cvs -z3 -d:pserver:${user}@${loc}:/${repos} co $module [ "$?" != "0" ] && dlerror=1 else export CVS_RSH=ssh cvs -d ${user}@${loc}:/${repos} co $module [ "$?" != "0" ] && dlerror=1 unset CVS_RSH fi if [ "$dlerror" = "0" ] ; then echo echo "making package ..." tar cf `echo $file | sed 's/.tar.bz2//'`.tar \ $module/ bzip2 `echo $file | sed 's/.tar.bz2//'`.tar fi rm -rf $module cd ../../.. fi # tar.bz2 elif [ "${is_cvs}" != "cvs" ] ; then [ ! -z "$mirror" ] && \ location="${mirror}/hdw-linux-${hdw_version}/$dir/$pkg/" echo "Downloading $dir - package $file ..." echo # possibly the package exists mkdir -p ./download/$dir/$pkg ; cd ./download/$dir/$pkg tolf="`find ../.. -name $file | tail -1`" if [ -n "$tolf" ] ; then [ -d $tolf ] && tolf="" fi if [ -f ./$file ] ; then echo "$file allready downloaded." echo elif [ -n "$tolf" ] ; then ln -svf $tolf . else $wget_cmd -c $location$file \ -O pkg-src.in && mv pkg-src.in $file echo "done." fi cd ../../.. fi fi done fi done fi # download all packages needed for defined target if [ -z "$package" ] ; then d_append="" [ "$no_cvs" = "1" ] && d_append="-no_cvs" for pkg in `./scripts/Download -list-missing | awk '{ print $1 }'`; do if [ ! -z "$mirror" ] ; then cmd_mirror="-mirror $mirror" else cmd_mirror="" fi echo . ./scripts/Download -package $pkg $cmd_mirror $d_append echo done fi # show list_unknown stuff # coming soon :)