| 1 |
#! /bin/sh |
| 2 |
# This fs implements a simple database of your favourite ftp servers. |
| 3 |
# The `archive' is a text file containing a list of ftp URL's one per line |
| 4 |
# like this (followed optionaly by name under which the link will be |
| 5 |
# shown - shouldn't contain spaces inside) |
| 6 |
# |
| 7 |
## ftp://sunsite.unc.edu/pub/Linux sunsite |
| 8 |
## ftp://tsx-11.mit.edu/pub/linux tsx-11 |
| 9 |
## ftp://ftp.cvut.cz/pub/linux cvut |
| 10 |
## ftp://[email protected]:21/ my_machine |
| 11 |
# |
| 12 |
# You should refer only to directories, not to particular files. |
| 13 |
# The file has to use `ftplist' extension (if you don't like it, change |
| 14 |
# it in mc.ext resp. $HOME/.mc/ext). So the file name should match |
| 15 |
# regex ^.*ftplist$ |
| 16 |
# |
| 17 |
# If you add "#define WANT_PARSE" to main.c you will be able to hit return |
| 18 |
# on the filenames in order to connect to the ftp servers. |
| 19 |
# |
| 20 |
|
| 21 |
mcftplistfs_list () |
| 22 |
{ |
| 23 |
{ ls -l $1; cat $1; } | gawk -v uid=$(id -ru) ' |
| 24 |
/^[\ \ ]*(#.*)?$/ { next } |
| 25 |
{ |
| 26 |
if (NF > 8) { |
| 27 |
a[1]=$6 |
| 28 |
a[2]=$7 |
| 29 |
a[3]=$8 |
| 30 |
next |
| 31 |
} |
| 32 |
if ($1 ~ /^(ftp|http|ssh):\/\//) { |
| 33 |
if ($1 ~ /\/$/) { |
| 34 |
a[4]=substr($1, index($1,":")+3, length($1) - index($1,":")-3) |
| 35 |
} else { |
| 36 |
a[4]=substr($1, index($1,":")+3) |
| 37 |
} |
| 38 |
if ($1 ~ /^http:/) { |
| 39 |
i = split($1, b, "/") |
| 40 |
a[5]=b[1] |
| 41 |
for (j=2; j <= i; j++) |
| 42 |
a[5] = sprintf("%s|%s",a[5],b[j]) |
| 43 |
} else |
| 44 |
a[5]=sprintf("%s%s/",substr($1,1,index($1,":")),a[4]); |
| 45 |
if (NF >= 2) |
| 46 |
a[4]=$2 |
| 47 |
else { |
| 48 |
i=split(a[4], b, "/") |
| 49 |
a[4]=b[1] |
| 50 |
for (j = 2; j <= i; j++) |
| 51 |
a[4]=sprintf("%s_%s", a[4], b[j]) |
| 52 |
} |
| 53 |
printf "lrwxrwxrwx 1 %-8d %-8d %8d %s %2d %5s %s -> /#%s\n", uid, 0, length(a[5]), a[1], a[2], a[3], a[4], a[5] |
| 54 |
} |
| 55 |
}' 2>/dev/null |
| 56 |
} |
| 57 |
|
| 58 |
mcftplistfs_run () |
| 59 |
{ |
| 60 |
if [ -n "$MC_CONTROL_FILE" ] |
| 61 |
then |
| 62 |
cat $1 | gawk -v name=$2 ' |
| 63 |
/^[\ \ ]*(#.*)?$/ { next } |
| 64 |
{ |
| 65 |
if ($1 ~ /^ftp:\/\//) { |
| 66 |
if ($1 ~ /\/$/) { |
| 67 |
a[4]=substr($1, 7, length($1) - 7) |
| 68 |
a[5]=$1 |
| 69 |
} else { |
| 70 |
a[4]=substr($1, 7) |
| 71 |
a[5]=sprintf("%s/", $1) |
| 72 |
} |
| 73 |
if (NF >= 2) |
| 74 |
a[4]=$2 |
| 75 |
else { |
| 76 |
i=split(a[4], b, "/") |
| 77 |
a[4]=b[1] |
| 78 |
for (j = 2; j <= i; j++) |
| 79 |
a[4]=sprintf("%s_%s", a[4], b[j]) |
| 80 |
} |
| 81 |
if (a[4] ~ name) |
| 82 |
printf "cd %s\n", a[5] |
| 83 |
} |
| 84 |
}' 2>/dev/null > $MC_CONTROL_FILE |
| 85 |
fi |
| 86 |
} |
| 87 |
|
| 88 |
export LC_ALL=C |
| 89 |
|
| 90 |
case "$1" in |
| 91 |
list) mcftplistfs_list $2; exit 0;; |
| 92 |
run) mcftplistfs_run $2 $3; exit 0;; |
| 93 |
esac |
| 94 |
exit 1 |