blob: 32fdc791ae0e77a1ed5acb0a4203a0c51a9808a6 (
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
59
60
61
62
|
## vim:ft=zsh
## put - make a file available via HTTP
## Written 2008 by Daniel Friesel <derf@derf.homelinux.org>
## supports as many 'failover' hosts as an array can hold
## Usage: put <file>
autoload fdie
typeset hostname
typeset -a ssh_options hosts
typeset target_dir server_prefix
typeset file
typeset -i n_hosts n_ping n_curl
function put_aneurysm_int {
hostname='aneurysm'
ssh_options=(-q)
target_dir='public_html/tmp/'
server_prefix='https://derf.homelinux.org/~derf/tmp/'
}
function put_aneurysm () {
hostname='derf.homelinux.org'
ssh_options=(-q)
target_dir='public_html/tmp/'
server_prefix='https://derf.homelinux.org/~derf/tmp/'
}
function put_sievert () {
hostname='sievert.tabularazor.org'
ssh_options=(-q)
target_dir='www/tmp/'
server_prefix='https://tabularazor.org/~derf/tmp/'
}
hosts=(aneurysm_int aneurysm sievert)
n_hosts=$#hosts
if [[ -f $1 ]] {
file=$1
while (( $#hosts )) {
put_$hosts[1]
ping -c 1 $hostname &> /dev/null
if (( ? == 0 )) {
scp $ssh_options $file $hostname:$target_dir
ssh $ssh_options $hostname "chmod 644 $target_dir${file:t}"
if $(curl -fI $server_prefix${file:t} &> /dev/null); then
echo $server_prefix${file:t}
return 0
else
(( n_curl++ ))
fi
} else {
(( n_ping++ ))
shift hosts
}
}
fdie "Tried uploading to $n_hosts hosts without succes\n" \
" - $n_ping hosts are unreachable\n" \
" - $n_curl errors while uploading"
} else {
fdie "$1: No such file"
}
|