Project

General

Profile

Revision fc4db4e3

Added by Julien Enselme about 10 years ago

Move usefull functions.

View differences:

other-scripts/d7-sync-config.example.sh
10 10
REMOTE_DIR_TMP_SAS="~/tmp/assos"
11 11
SSH_ID_SAS=jenselme
12 12
SSH_ID_WEBASSOS=assos@webassos.ec-m.fr
13

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

  
21
copy_assos_init() {
22
    ssh $SSH_ID_SAS "mkdir -p $REMOTE_DIR_TMP_SAS"
23
}
24

  
25
get_args() {
26
    if [ "$#" -gt 2 ] ; then
27
	echo ${@:1:$#-2}
28
    fi
29
}
30

  
31
clean() {
32
    ssh $SSH_ID_SAS "rm -r $REMOTE_DIR_TMP_SAS/$1"
33
}
34

  
35
scp_from_assos() {
36
    local input=("$@")
37
    local args=$(get_args $@)
38
    local source=${input[$#-2]}
39
    local dest=${input[$#-1]}
40

  
41
    ssh $SSH_ID_SAS "scp $args $SSH_ID_WEBASSOS:$source $REMOTE_DIR_TMP_SAS/$source" &&
42
    scp $args $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source $dest &&
43
    clean $source
44
}
45

  
46
scp_to_assos() {
47
    local input=("$@")
48
    local args=$(get_args $@)
49
    local source=${input[$#-2]}
50
    local dest=${input[$#-1]}
51

  
52
    scp $args $source $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source &&
53
    ssh $SSH_ID_SAS "scp $args $REMOTE_DIR_TMP_SAS/$source $SSH_ID_WEBASSOS:$dest" &&
54
    clean $source
55
}
56

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

  
63
    ssh $SSH_ID_SAS "rsync $args $SSH_ID_WEBASSOS:$source $REMOTE_DIR_TMP_SAS/$source" &&
64
    rsync $args $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source $dest &&
65
    clean $source
66
}
67

  
68
rsync_to_assos() {
69
    local input=("$@")
70
    local args=$(get_args $@)
71
    local source=${input[$#-2]}
72
    local dest=${input[$#-1]}
73

  
74
    rsync $args $source $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source &&
75
    ssh $SSH_ID_SAS "rsync $args $REMOTE_DIR_TMP_SAS/$source $SSH_ID_WEBASSOS:$dest" &&
76
    clean $source
77
}

Also available in: Unified diff