summaryrefslogtreecommitdiffstats
path: root/elchos/root-image/krebs/etc/Reaktor/commands/ftpget
blob: 74e76f8e5222003d95c84e257ae00a78d9e86829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# usage: $0 [-d] uri sharename[/subdirs]
exec 2>&1
set -euf
ncdc_user=hooker
usage(){
  cat <<EOF
usage: $0 [-d] uri share[/subdirs]
  -d      --   uri is a directory to be mirrored
  share   --   vag[0-n]

EOF
}
examples(){
  cat <<EOF
examples: ftpget -d http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/0.8 vag0/firefox_releases
              -> 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 '^(ftps*://|https*://)' );then
  exit 23
fi

share=$( printf "%s" "${2?provide share name}" |head -1 | sed 's#\.\./##')
sharepath=/media/${share%%/*}
realshare="/media/$share"
test ! -e "$sharepath" && echo "$sharepath does not exist!" && exit 23

sudo -u $ncdc_user /usr/bin/mkdir -p "$realshare"

if test -z ${is_dir:-};then
  cmd="lftpget \"$target\""
else
  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'"