| 1 | #!/bin/bash |
| 2 | # The script is borrowed from |
| 3 | #============================================================================ |
| 4 | # http://staff.washington.edu/corey/tools.html |
| 5 | # Author: Corey Satten, corey @ cac.washington.edu, 06/26/03, release 1.8 |
| 6 | #============================================================================ |
| 7 | # Modified by Steven Shiau <steven _at_ clonezilla org> 12/12/04 |
| 8 | # 2005/8/22 Steven Shiau modified to add sed -n '/\.rpm$/s/^[-l].* //p' since there are some ftp mirror site can NOT handle symbolic link well (.i.e. dir -L will fail). One of the site is |
| 9 | # ftp://mirrors.mathematik.uni-bielefeld.de/pub/linux/suse/apt/SuSE/9.3-i386/RPMS.base/ |
| 10 | # 2006/6/24 Steven Shiau modified it to use lftp for http instead of lynx, since |
| 11 | # 1. For some apache2, "lynx -dump" will get the html format instead of plain text |
| 12 | # 2. lynx does not support http_proxy and ftp_proxy. |
| 13 | #============================================================================ |
| 14 | # Load DRBL setting and functions |
| 15 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 16 | |
| 17 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 18 | |
| 19 | # |
| 20 | usage () { |
| 21 | echo "Usage: `basename $0` [path]" |
| 22 | echo "Example:" |
| 23 | echo "`basename $0` /mirror/apt/RPMS.drbl-test" |
| 24 | echo "`basename $0` http://free.nchc.org.tw/fedora/apt/fedora/linux/2/i386/RPMS.drbl" |
| 25 | } |
| 26 | |
| 27 | # Try to help people figure out if/when this file has DOS line terminators |
| 28 | # Chances are the initial #!/bin/sh will fail with a cryptic "not found" msg |
| 29 | # If someone tries to debug it by feeding it to sh manually, this should help: |
| 30 | NL= |
| 31 | case "$NL" in '');; *) # |
| 32 | echo "ERROR: $0 was improperly saved with CR-LF newlines." 1>&2 # |
| 33 | echo "Please try again after restoring Unix-style (LF) newlines" 1>&2 # |
| 34 | exit 1 ;; # |
| 35 | esac # |
| 36 | |
| 37 | SRC=$1 |
| 38 | [ -z "$SRC" ] && echo "You must provide the URL or PATH!" && usage && exit 1 |
| 39 | |
| 40 | case "$SRC" in */);; *) SRC=$SRC/;; esac # URL must end in slash |
| 41 | |
| 42 | #------------------------------------------------------------------------------- |
| 43 | # |
| 44 | # Find all redhat patches available |
| 45 | # |
| 46 | |
| 47 | export LC_ALL=C |
| 48 | |
| 49 | if [ -d $SRC ] ;then # local directory |
| 50 | (cd $SRC && ls -l) |
| 51 | else # http/ftp... directory |
| 52 | case "$SRC" in |
| 53 | ftp://*) |
| 54 | ( echo set ftp:passive-mode on |
| 55 | # Steven Shiau modified to use lftp. |
| 56 | #echo dir -L) | ftp -p -n $HST | grep '\.rpm$' > $TMP |
| 57 | echo rels ) | lftp $SRC 2>/dev/null | grep -E '\.rpm\>' |
| 58 | ;; |
| 59 | http://*) |
| 60 | # Steven Shiau modified to use lftp instead of lynx |
| 61 | #lynx -dump $SRC | sed -n 's,^[ 0-9.]*http://.*/,-& ,p';; |
| 62 | echo rels | lftp $SRC 2>/dev/null |
| 63 | ;; |
| 64 | file://*) |
| 65 | DIR="$(echo $SRC | sed -e "s|file://||g")" |
| 66 | (cd $DIR && ls -l) |
| 67 | ;; |
| 68 | esac |
| 69 | # In case dir -L fails, we need to add ^[-l] to strip the junk msg. |
| 70 | # Some repo output DOS (CR/LF), |
| 71 | # convert to Unix format: sed 's/[^[:print:]]$//' |
| 72 | # For OpenSuSE, there are some *.delta.rpm and .rpm.metalink, we have to filter them, too. |
| 73 | fi | sed 's/[^[:print:]]$//' | sed -r -n '/\.rpm($|[[:space:]]])\>/s/^[-l].* //p' | grep -v -E "\.delta\.rpm($|[[:space:]])" | while read x; do basename $x; done | sort |