From 69a0b3b50de75a81dc95fe84d73895b753fc3cbe Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 26 Mar 2014 16:26:10 +0100 Subject: filehooker: ftpget can now retrieve dirs, list_downloads is better --- .../root-image/krebs/etc/Reaktor/commands/ftpget | 42 +++++++++++++++++++--- .../krebs/etc/Reaktor/commands/list_downloads | 2 +- 2 files changed, 38 insertions(+), 6 deletions(-) (limited to 'filehooker/root-image/krebs') diff --git a/filehooker/root-image/krebs/etc/Reaktor/commands/ftpget b/filehooker/root-image/krebs/etc/Reaktor/commands/ftpget index 10e73a2f..74e76f8e 100755 --- a/filehooker/root-image/krebs/etc/Reaktor/commands/ftpget +++ b/filehooker/root-image/krebs/etc/Reaktor/commands/ftpget @@ -1,12 +1,37 @@ #!/bin/sh +# usage: $0 [-d] uri sharename[/subdirs] exec 2>&1 set -euf ncdc_user=hooker +usage(){ + cat < 0.8 directory is stored to /media/vag0/firefox_releases + + ftpget -d http://speedtest.qsc.de/10MB.qsc vag0/ + -> 10MB.qsc is stored to /media/vag0/10MB.qsc +EOF +} +if test "${1:--h}" == '-h' -o "${1:-}" == '--help';then + usage + examples + exit 0 +fi +if test ${1:-} == '-d' ;then + is_dir=true + shift +fi target="${1:-}" -if !( echo "$target" | egrep -q '^(ftp://|http://)' );then - echo "target must be ftp:// or http://" +if !( echo "$target" | egrep -q '^(ftps*://|https*://)' );then exit 23 fi @@ -16,11 +41,18 @@ realshare="/media/$share" test ! -e "$sharepath" && echo "$sharepath does not exist!" && exit 23 sudo -u $ncdc_user /usr/bin/mkdir -p "$realshare" -if ! sudo -u $ncdc_user /usr/bin/tmux has-session -t dl >/dev/null 2>&1 ;then - sudo -u $ncdc_user /usr/bin/tmux new-session -s dl -d -c "$realshare" "lftpget \"$target\"" + +if test -z ${is_dir:-};then + cmd="lftpget \"$target\"" else - sudo -u $ncdc_user /usr/bin/tmux new-window -t dl -c "$realshare" "lftpget \"$target\"" + cmd="lftp -e \"mirror;exit\" $target" fi + + if ! sudo -u $ncdc_user /usr/bin/tmux has-session -t dl >/dev/null 2>&1 ;then + sudo -u $ncdc_user /usr/bin/tmux new-session -s dl -d -c "$realshare" "$cmd" + else + sudo -u $ncdc_user /usr/bin/tmux new-window -t dl -c "$realshare" "$cmd" + fi #sudo -u $ncdc_user /usr/bin/tmux new-window -t dl #cd "$realshare" ;sudo -u hooker /usr/bin/lftpget "$target" echo "download started, check with 'list_downloads'" diff --git a/filehooker/root-image/krebs/etc/Reaktor/commands/list_downloads b/filehooker/root-image/krebs/etc/Reaktor/commands/list_downloads index cb1e07be..f53067d8 100755 --- a/filehooker/root-image/krebs/etc/Reaktor/commands/list_downloads +++ b/filehooker/root-image/krebs/etc/Reaktor/commands/list_downloads @@ -4,5 +4,5 @@ count=$(sudo -u $ncdc_user /usr/bin/tmux list-windows -t dl 2>/dev/null| wc -l) test $count -eq 0 && echo "no downloads running" && exit 0 for i in $(seq 0 $(($count-1)));do - sudo -u $ncdc_user /usr/bin/tmux capture-pane -t dl:$i -p |head -1 + sudo -u $ncdc_user /usr/bin/tmux capture-pane -t dl:$i -p | grep -v '^$' | tail -n 1 done -- cgit v1.2.3