Projet

Général

Profil

Révision e71cae50

Ajouté par Julien Enselme il y a environ 10 ans

Change script so that the wrapper around functions are not needed any more. Use ProxyCommand in ~/.ssh/config

Voir les différences:

other-scripts/d7-sync-config.example.sh
6 6
SITES_PHP=$DIR_DRUPAL7_SITES/sites.php
7 7
LOCAL_BRANCH_NAME=local
8 8
DOMAIN=assos.local
9
# Connexion variable
10
REMOTE_DIR_TMP_SAS="~/tmp/assos"
11
SSH_ID_SAS=jenselme
12
SSH_ID_WEBASSOS=assos@webassos.ec-m.fr
9
WEBASSOS_ID=webassos
other-scripts/d7-sync-functions.sh
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
}
other-scripts/d7-sync.sh
2 2

  
3 3
help=<<EOF
4 4
This script is intended to ease the synchronisation of any site hosted by assos.
5
It relies on bash, drush and requires a valid d7-sync-config.sh.
5
It relies on bash, drush and requires a valid d7-sync-config.sh. You must have
6
configured SSH so that ssh webassos connects you to the webserver.
6 7
The drupal installation is synched using git, the website files and database using rsync.
7 8

  
8 9
usage: d7-sync.sh [SITENAME]
......
15 16
### Init
16 17
# Config
17 18
source d7-sync-config.sh || source d7-sync-config.example.sh
18
source d7-sync-functions.sh
19
source ~/.bashrc
20
shopt -s expand_aliases
21 19
cd $DIR_MULTIASSOS
22 20
ret=$?
23 21
if [ $ret -ne 0 ] ; then
......
54 52

  
55 53
mkdir $dir_site
56 54
cd $dir_site
57
rsync_from_assos -rltp --progress --delete drupal7/sites/$dir_site/ .
55
rsync -rltp --progress --delete $WEBASSOS_ID:drupal7/sites/$dir_site/ .
58 56
# Change permissions for Apache
59 57
# TODO: do something less permissive than 755
60 58
chmod -R 755 .
......
65 63
now=$(date +%s)
66 64
sql_file="$1.$now.sql"
67 65
remote_sql_file="$REMOTE_DIR_TMP_SAS/$sql_file"
68
assos "drush @$1 sql-dump > $remote_sql_file"
69
scp $SSH_ID_SAS:$remote_sql_file .
66
ssh $WEBASSOS_ID "drush @$1 sql-dump > $remote_sql_file"
67
scp $WEBASSOS_ID:$remote_sql_file .
70 68
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
71 69
ret=$?
72 70
if [ $ret -ne 0 ] ; then
......
77 75
fi
78 76
mysql -u root $local_db_name < $sql_file
79 77
rm $sql_file
80
assos "rm $remote_sql_file"
78
ssh $WEBASSOS_ID "rm $remote_sql_file"
81 79

  
82 80
### modify settings.php
83 81
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name

Formats disponibles : Unified diff