plan9fox/rc/bin/hget

71 lines
1,017 B
Text
Raw Normal View History

2012-01-11 15:17:54 +00:00
#!/bin/rc
2012-05-26 19:18:41 +00:00
rfork e
2012-01-11 15:17:54 +00:00
argv0=$0
fn usage {
2012-01-22 22:28:45 +00:00
echo usage: $argv0 [ -o file ] [ -p body ] [ -r header ] [ -m method ] [ -b baseurl ] url >[1=2]
2012-01-11 15:17:54 +00:00
exit usage
}
s=0
o=()
p=()
r=()
m=()
b=()
while(~ $1 -*){
switch($1){
case -o
o=$2
shift
case -p
p=$2
shift
case -r
r=($r $2)
shift
case -m
m=$2
shift
case -b
b=$2
shift
case *
usage
}
shift
}
if(! ~ $#* 1)
usage
if(! ~ $#o 0){
if(! ~ $#o 1)
usage
if(test -s $o)
s=`{ls -l $o | awk '{print $6}'}
}
if(! ~ $s 0)
r=($r 'Range: bytes='^$s^'-')
<>/mnt/web/clone {
d=/mnt/web/^`{sed 1q}
if(~ $#b 1)
echo -n baseurl $b >[1=0]
echo -n url $1 >[1=0]
for(i in $r)
echo -n headers $i >[1=0]
if(~ $#m 1)
echo -n request $m >[1=0]
if(! ~ $#p 0)
echo -n $"p >$d/postbody
2012-01-11 15:17:54 +00:00
<$d/body {
if(~ $#o 1){
l=`{cat $d/contentlength >[2]/dev/null}
x=`{awk 'BEGIN{FS=" |-"}/^bytes ([0-9]+)\-/{print $2}' \
$d/contentrange >[2]/dev/null}
if(~ $s $l && ~ $#x 0)
exit
if(~ $s $x)
exec cat >>$o
exec cat >$o
}
exec cat
}
}