Projet

Général

Profil

Révision f6a5e032

Ajouté par Julien Enselme il y a environ 10 ans

Update d7-sync.sh and d7-sync-config.example.sh so they can work with webassos.ec-m.fr

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
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" &&
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" &&
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
}
other-scripts/d7-sync.sh
1 1
#!/usr/bin/env bash
2 2

  
3 3
help=<<EOF
4
This script is intended to ease the synchronisation of any site hosted by assos. It relies on bash, drush and requires @ssh assos@ to work.
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 6
The drupal installation is synched using git, the website files and database using rsync.
6 7

  
7 8
usage: d7-sync.sh [SITENAME]
......
50 51

  
51 52
mkdir $dir_site
52 53
cd $dir_site
53
rsync -rltp --progress --delete assos:~/drupal7/sites/$dir_site/* .
54
rsync_from_assos -rltp --progress --delete ~/drupal7/sites/$dir_site/* .
54 55
# Change permissions for Apache
55 56
# TODO: do something less permissive than 755
56 57
chmod -R 755 .
......
61 62
now=$(date +%s)
62 63
sql_file="$1.$now.sql"
63 64
remote_sql_file="~/tmp/$sql_file"
64
ssh assos "drush @$1 sql-dump > $remote_sql_file"
65
scp assos:$remote_sql_file .
65
assos "drush @$1 sql-dump > $remote_sql_file"
66
scp_from_assos $remote_sql_file .
66 67
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
67 68
ret=$?
68 69
if [ $ret -ne 0 ] ; then
69 70
    echo "mysql daemon is not started. Exiting."
70
    ssh assos "rm $remote_sql_file"
71
    assos "rm $remote_sql_file"
71 72
    rm $sql_file
72 73
    exit 1
73 74
fi
74 75
mysql -u root $local_db_name < $sql_file
75 76
rm $sql_file
76
ssh assos "rm $remote_sql_file"
77
assos "rm $remote_sql_file"
77 78

  
78 79
### modify settings.php
79 80
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
......
88 89
drush status > /dev/null
89 90
ret=$?
90 91
if [ $ret -ne 0 ] ; then
91
    echo "drush or site has a problem. Exiting"
92
    echo "drush or site has a problem. Exiting."
92 93
    exit 1
93 94
fi
94 95
drush -y dis piwik

Formats disponibles : Unified diff