Project

General

Profile

Paste
Download (1.84 KB) Statistics
| Branch: | Revision:

root / other-scripts / d7-sync-functions.sh @ d0e0fe33

1
# We cannot directly use commands like scp or rsync since we cannot directly access
2
# the server. We use the functions defined below instead. It is advised to put these
3
# functions in your .bashrc or equivalent in order to use them any time you want. These
4
# functions are tested and work with bash. They are incompatible witsh zsh.
5
# They can only take 2 positional parameters.
6

    
7
copy_assos_init() {
8
    ssh $SSH_ID_SAS "mkdir -p $REMOTE_DIR_TMP_SAS"
9
}
10

    
11
get_args() {
12
    if [ "$#" -gt 2 ] ; then
13
	echo ${@:1:$#-2}
14
    fi
15
}
16

    
17
clean() {
18
    ssh $SSH_ID_SAS "rm -r $REMOTE_DIR_TMP_SAS/*"
19
}
20

    
21
scp_from_assos() {
22
    local input=("$@")
23
    local args=$(get_args $@)
24
    local source=${input[$#-2]}
25
    local dest=${input[$#-1]}
26

    
27
    ssh $SSH_ID_SAS "scp $args $SSH_ID_WEBASSOS:$source $REMOTE_DIR_TMP_SAS/$source" &&
28
    scp $args $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source $dest &&
29
    clean $source
30
}
31

    
32
scp_to_assos() {
33
    local input=("$@")
34
    local args=$(get_args $@)
35
    local source=${input[$#-2]}
36
    local dest=${input[$#-1]}
37

    
38
    scp $args $source $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source &&
39
    ssh $SSH_ID_SAS "scp $args $REMOTE_DIR_TMP_SAS/$source $SSH_ID_WEBASSOS:$dest" &&
40
    clean $source
41
}
42

    
43
rsync_from_assos() {
44
    local input=("$@")
45
    local args=$(get_args $@)
46
    local source=${input[$#-2]}
47
    local dest=${input[$#-1]}
48

    
49
    ssh $SSH_ID_SAS "mkdir -p $REMOTE_DIR_TMP_SAS/$source"
50
    ssh $SSH_ID_SAS "rsync $args $SSH_ID_WEBASSOS:$source $REMOTE_DIR_TMP_SAS/$source" &&
51
    rsync $args $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source $dest &&
52
    clean $source
53
}
54

    
55
rsync_to_assos() {
56
    local input=("$@")
57
    local args=$(get_args $@)
58
    local source=${input[$#-2]}
59
    local dest=${input[$#-1]}
60

    
61
    rsync $args $source $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source &&
62
    ssh $SSH_ID_SAS "rsync $args $REMOTE_DIR_TMP_SAS/$source $SSH_ID_WEBASSOS:$dest" &&
63
    clean $source
64
}