| 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> Sep/03/07 |
| 8 | #============================================================================ |
| 9 | # Load DRBL setting and functions |
| 10 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 11 | |
| 12 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 13 | |
| 14 | # Settings |
| 15 | default_comp="xz" |
| 16 | |
| 17 | # |
| 18 | USAGE() { |
| 19 | echo "$ocs - To list the available tarball files" |
| 20 | echo "Usage:" |
| 21 | echo "To run $ocs:" |
| 22 | echo "$ocs [OPTION] PATH" |
| 23 | echo "Options:" |
| 24 | echo "-f, --comp-format FORMAT Specify the tarball compression format, i.e. gz, bz2, xz. If not assigned, xz will be used." |
| 25 | echo "Ex:" |
| 26 | echo "$ocs /mirror/apt/RPMS.drbl-test" |
| 27 | echo "$ocs http://free.nchc.org.tw/syslinux/" |
| 28 | } |
| 29 | |
| 30 | #################### |
| 31 | ### Main program ### |
| 32 | #################### |
| 33 | |
| 34 | ocs_file="$0" |
| 35 | ocs=`basename $ocs_file` |
| 36 | # |
| 37 | while [ $# -gt 0 ]; do |
| 38 | case "$1" in |
| 39 | -f|--comp-format) |
| 40 | shift; |
| 41 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 42 | # skip the -xx option, in case |
| 43 | suf="$1" |
| 44 | shift; |
| 45 | fi |
| 46 | [ -z "$ocsroot" ] && USAGE && exit 1 |
| 47 | ;; |
| 48 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 49 | USAGE >& 2 |
| 50 | exit 2 ;; |
| 51 | *) break ;; |
| 52 | esac |
| 53 | done |
| 54 | |
| 55 | SRC="$1" |
| 56 | |
| 57 | # Try to help people figure out if/when this file has DOS line terminators |
| 58 | # Chances are the initial #!/bin/sh will fail with a cryptic "not found" msg |
| 59 | # If someone tries to debug it by feeding it to sh manually, this should help: |
| 60 | NL= |
| 61 | case "$NL" in '');; *) # |
| 62 | echo "ERROR: $0 was improperly saved with CR-LF newlines." 1>&2 # |
| 63 | echo "Please try again after restoring Unix-style (LF) newlines" 1>&2 # |
| 64 | exit 1 ;; # |
| 65 | esac # |
| 66 | |
| 67 | if [ -z "$suf" ]; then |
| 68 | suf="$default_comp" |
| 69 | fi |
| 70 | if [ -z "$SRC" ]; then |
| 71 | echo "You must assign the URL or PATH!" |
| 72 | USAGE |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | case "$SRC" in */);; *) SRC=$SRC/;; esac # URL must end in slash |
| 77 | |
| 78 | # |
| 79 | if [ -d $SRC ] ;then # local directory |
| 80 | (cd $SRC && ls -l) |
| 81 | else # ftp directory |
| 82 | case "$SRC" in |
| 83 | ftp://*) |
| 84 | ( echo set ftp:passive-mode on |
| 85 | # Steven Shiau modified to use lftp. |
| 86 | echo rels ) | lftp $SRC 2>/dev/null | grep -Ew "\.tar\.${suf}" |
| 87 | ;; |
| 88 | http://*) |
| 89 | # Steven Shiau modified to use lftp instead of lynx |
| 90 | #lynx -dump $SRC | sed -n 's,^[ 0-9.]*http://.*/,-& ,p';; |
| 91 | echo rels | lftp $SRC 2>/dev/null |
| 92 | ;; |
| 93 | file://*) |
| 94 | DIR="$(echo $SRC | sed -e "s|file://||g")" |
| 95 | (cd $DIR && ls -l) |
| 96 | ;; |
| 97 | esac |
| 98 | # In case dir -L fails, we need to add ^[-l] to strip the junk msg. |
| 99 | # Some repo output DOS (CR/LF), |
| 100 | # convert to Unix format: sed 's/[^[:print:]]$//' |
| 101 | fi | sed 's/[^[:print:]]$//' | sed -r -n "/tar.${suf}$/s/^[-l].* //p" | while read x; do basename $x; done | sort |