| 1 | #!/bin/sh |
| 2 | cmd="$1" |
| 3 | shift |
| 4 | |
| 5 | if [ "$cmd" = userspeeda ]; then |
| 6 | while [ $# -gt 0 ]; do |
| 7 | peerfile="$(tr / _ <<<"$1")" |
| 8 | if [ -r "$HOME/dc/users/$peerfile" ]; then |
| 9 | speed="$((read num; read max; read nent; avg=0; for i in $(seq 1 $nent); do read ent; let avg+=$ent; done; let avg/=$nent; echo $avg) < "$HOME/dc/users/$peerfile")" |
| 10 | echo $speed |
| 11 | else |
| 12 | echo -1 |
| 13 | fi |
| 14 | shift |
| 15 | done |
| 16 | fi |
| 17 | |
| 18 | if [ "$cmd" = userspeedm ]; then |
| 19 | while [ $# -gt 0 ]; do |
| 20 | peerfile="$(tr / _ <<<"$1")" |
| 21 | if [ -r "$HOME/dc/users/$peerfile" ]; then |
| 22 | speed="$((read num; read max; echo $max) < "$HOME/dc/users/$peerfile")" |
| 23 | echo $speed |
| 24 | else |
| 25 | echo -1 |
| 26 | fi |
| 27 | shift |
| 28 | done |
| 29 | fi |
| 30 | |
| 31 | if [ "$cmd" = rmtag ]; then |
| 32 | for f in "$HOME"/dc/resume/*.info; do |
| 33 | if [ ! -e "${f%.info}.lock" ]; then |
| 34 | unset dcarg_tag |
| 35 | . "$f" |
| 36 | if [ "$dcarg_tag" = "$1" ]; then |
| 37 | rm "$f" |
| 38 | rm "${f%.info}" |
| 39 | fi |
| 40 | fi |
| 41 | done |
| 42 | fi |
| 43 | |
| 44 | if [ "$cmd" = remain ]; then |
| 45 | for f in "$HOME"/dc/resume/*.info; do |
| 46 | if [ ! -r "$f" ]; then |
| 47 | continue |
| 48 | fi |
| 49 | unset "${!dcarg_@}" |
| 50 | . "$f" |
| 51 | resfile="${f%.info}" |
| 52 | for id in "$@"; do |
| 53 | idt="${id%%:*}" |
| 54 | idd="${id#*:}" |
| 55 | match=n |
| 56 | if [ "$idt" = size ]; then |
| 57 | if [ "$idd" -eq "$filesize" ]; then |
| 58 | match=y |
| 59 | fi |
| 60 | elif [ "$idt" = hash ]; then |
| 61 | if [ "$idd" = "$dcarg_hash" ]; then |
| 62 | match=y |
| 63 | fi |
| 64 | elif [ "$idt" = all ]; then |
| 65 | match=y |
| 66 | fi |
| 67 | if [ "$match" = y ]; then |
| 68 | rfrem="$(wc -c <"$resfile" | sed 's/ //g')" |
| 69 | echo "size:$filesize" |
| 70 | echo "prog:$rfrem" |
| 71 | echo "name:$origname" |
| 72 | if [ -n "$dcarg_hash" ]; then |
| 73 | echo "hash:$dcarg_hash" |
| 74 | fi |
| 75 | fi |
| 76 | done |
| 77 | done |
| 78 | fi |
| 79 | |
| 80 | if [ "$cmd" = lsres ]; then |
| 81 | for f in "$HOME"/dc/resume/*.info; do |
| 82 | if [ ! -r "$f" ]; then |
| 83 | continue |
| 84 | fi |
| 85 | . "$f" |
| 86 | resfile="${f%.info}" |
| 87 | rfrem="$(wc -c <"$resfile" | sed 's/ //g')" |
| 88 | echo "id:${resfile##*/}" |
| 89 | echo "size:$filesize" |
| 90 | echo "prog:$rfrem" |
| 91 | echo "name:$origname" |
| 92 | if [ -e "${resfile}.lock" ]; then |
| 93 | echo "lock:yes" |
| 94 | else |
| 95 | echo "lock:no" |
| 96 | fi |
| 97 | if [ -n "$dcarg_hash" ]; then |
| 98 | echo "hash:$dcarg_hash" |
| 99 | fi |
| 100 | done |
| 101 | fi |
| 102 | |
| 103 | if [ "$cmd" = rmres ]; then |
| 104 | resfile="$HOME/dc/resume/$1" |
| 105 | if [ ! -r "${resfile}.info" ]; then |
| 106 | echo "err:notfound" |
| 107 | exit |
| 108 | fi |
| 109 | if [ -e "${resfile}.lock" ]; then |
| 110 | echo "err:locked" |
| 111 | exit |
| 112 | fi |
| 113 | rm -f "$resfile" "${resfile}.info" |
| 114 | echo "ok" |
| 115 | fi |