3 # author: miguel & hackbard
5 # This is the Download script used to fetch all the hdw-linux sources
6 # wheather it is from their original locations or from a mirror site
8 # To run the script use ./scripts/Download [ options ]
18 -mirror) mirror="$2" ; shift 2 ;;
19 -package) package="$2" ; shift 2 ;;
20 -list-missing) list_op="missing" ; shift 1 ;;
21 -list-broken) list_op="broken" ; shift 1 ;;
22 -list-unknown) list_op="unknown" ; shift 1 ;;
25 remove="1" ; shift 1 ;;
26 -check-new) list_op="check_new" ; shift 1 ;;
27 -no_cvs) no_cvs="1" ; shift 1 ;;
31 echo " ./scripts/Download"
32 echo " ./scripts/Download -package <name>"
34 echo " use -no_cvs option to avoid refetching cvs-packages"
36 echo "to fetch sources from a mirror:"
38 echo " ./scripts/Download -mirror <mirror>"
39 echo " ./scripts/Download -package <name> -mirror <mirror>"
43 echo " ./scripts/Download -list-missing"
44 echo " ./scripts/Download -list-broken"
45 echo " ./scripts/Download -list-unknown"
46 echo " ./scripts/Download -check-new"
47 echo " ./scripts/Download -remove-unknown"
48 echo " ./scripts/Download -no_cvs"
54 # we need to know some of the hdw specific variables.
58 . ./scripts/subroutines
60 wget_cmd="wget --tries=3 --passive-ftp "
61 curl="curl --disable-epsv -s"
63 # -list-missing & -list-broken (& -list-unknown)
64 if [ ! -z "$list_op" ] ; then
66 for dir in `ls -A --ignore="CVS" ./download`; do
67 if [ -f ./download/$dir/PKGS ] ; then
68 cat ./download/$dir/PKGS | while read pkg file location; do
72 server=`echo $location | awk -F: '{print $1}'`
73 if [ "$server" = "ftp" ] ; then
75 if $wget_cmd -O .ftp-index \
76 $location 2> /dev/null; then
77 [ -z "`grep $file .ftp-index`" ] && \
78 echo_r "$dir $file broken ($server - package)"
81 echo_r "$dir $file broken ($server - directory)"
83 elif [ "$server" = "http" ] ; then
84 $wget_cmd --spider $location$file 2> /dev/null
86 echo_r "$dir $file broken ($server - package)"
88 echo "$dir $file -> unable to search on $server server"
92 if [ -z "`type -p curl`" ]; then
93 echo "you need curl installed to use -check-new"
96 prune=".sign|.deb|.rpm|.md5|.diff|.patch"
97 c_v="`grep '^#\ \[V\]' \
98 \`find packages/*/$pkg/$pkg\` |
100 server=`echo $location | awk -F: '{print $1}'`
101 ending="`detect_file_ending $file`"
103 if [ "$server" = "http" ] ; then
104 $curl $location | grep $pkg | grep $ending | grep -vE $prune | \
105 sed -e 's/imgsrc.*"\//IMG\ "/'g -e 's/<IMG .*">//'g | \
106 sed -e 's/ahref/A\ /'g -e 's/<\/a/<\/A/'g | \
107 sed -e 's/<A .*">//'g -e 's/<\/A.*//'g | \
108 sed 's/\ //g' > ./check_tmp/all-files
109 elif [ "$server" = "ftp" ] ; then
110 $curl $location | tr -s ' ' | cut -f9 -d' ' | \
111 grep $pkg | grep $ending | grep -vE $prune \
112 > ./check_tmp/all-files
114 echo "$pkg: only http/ftp servers supported"
117 if [ -f ./check_tmp/all-files ]; then
119 echo "current version: $c_v"
121 cat ./check_tmp/all-files
126 if [ "`echo $location | awk -F: '{ print $1 }'`" = "cvs" ]; then
127 if [ "$no_cvs" = "0" ] ; then
128 echo -n "$pkg is cvs-package, "
129 if [ ! -f ./download/$dir/$pkg/$file ] ; then
136 if [ ! -f ./download/$dir/$pkg/$file ] ; then
143 if [ -d ./download/$dir/$pkg ] ; then
144 objects="`ls -A ./download/$dir/$pkg`"
145 for i in $objects; do
146 known_f="`grep ^$pkg ./download/$dir/PKGS | \
148 if [ -z "`echo $known_f | grep $i`" ] ; then
149 echo "./download/$dir/$pkg/$i unknown"
150 if [ "$remove" = "1" ] ; then
152 rm ./download/$dir/$pkg/$i
167 if [ ! -z "$package" ] ; then
169 for dir in `ls -A --ignore="CVS" ./download`; do
170 if [ -f ./download/$dir/PKGS ] ; then
171 cat ./download/$dir/PKGS | while read pkg file location; do
173 if [ "$package" = "$pkg" ] ; then
175 is_cvs="`echo $location | awk -F: '{ print $1 }'`"
178 if [ "${is_cvs}" = "cvs" -o "${is_cvs}" = "sshcvs" ] ; then
179 if [ "$no_cvs" = "0" ] ; then
181 user=`echo $location | awk -F: '{ print $2 }'`
182 loc=`echo $location | awk -F: '{ print $3 }'`
183 repos=`echo $location | awk -F: '{ print $4 }'`
184 module=`echo $location | awk -F: '{ print $5 }'`
185 #passwd=`echo $location | awk -F: '{ print $6 }'`
187 echo "downloading $pkg using cvs ..."
188 [ ! -f $HOME/.cvspass ] && touch $HOME/.cvspass
189 mkdir -p ./download/$dir/$pkg ; cd ./download/$dir/$pkg
192 if [ "${is_cvs}" = "cvs" ] ; then
193 cvs -z 9 -d:pserver:${user}@${loc}:/${repos} co $module
194 [ "$?" != "0" ] && dlerror=1
197 cvs -d ${user}@${loc}:/${repos} co $module
198 [ "$?" != "0" ] && dlerror=1
201 if [ "$dlerror" = "0" ] ; then
203 echo "making package ..."
204 tar cf `echo $file | sed 's/.tar.bz2//'`.tar \
206 bzip2 `echo $file | sed 's/.tar.bz2//'`.tar
213 elif [ "${is_cvs}" != "cvs" ] ; then
214 [ ! -z "$mirror" ] && \
215 location="${mirror}/hdw-linux-${hdw_version}/$dir/$pkg/"
216 echo "Downloading $dir - package $file ..."
218 # possibly the package exists
219 mkdir -p ./download/$dir/$pkg ; cd ./download/$dir/$pkg
220 tolf="`find ../.. -name $file | tail -1`"
221 if [ -n "$tolf" ] ; then
222 [ -d $tolf ] && tolf=""
224 if [ -f ./$file ] ; then
225 echo "$file allready downloaded."
227 elif [ -n "$tolf" ] ; then
231 $wget_cmd -c $location$file \
245 # download all packages needed for defined target
246 if [ -z "$package" ] ; then
249 [ "$no_cvs" = "1" ] && d_append="-no_cvs"
251 for pkg in `./scripts/Download -list-missing | awk '{ print $1 }'`; do
252 if [ ! -z "$mirror" ] ; then
253 cmd_mirror="-mirror $mirror"
258 . ./scripts/Download -package $pkg $cmd_mirror $d_append
264 # show list_unknown stuff