commit f6a5e032a93160a31483c6ba4e35c78e5d700862
Author: Julien Enselme <julien.enselme@centrale-marseille.fr>
Date:   Sat Mar 22 19:07:17 2014 +0100

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

diff --git a/other-scripts/d7-sync-config.example.sh b/other-scripts/d7-sync-config.example.sh
index adb789fc..8b0829be 100644
--- a/other-scripts/d7-sync-config.example.sh
+++ b/other-scripts/d7-sync-config.example.sh
@@ -6,3 +6,72 @@ DIR_DRUPAL7_SITES=$DIR_DRUPAL7/sites
 SITES_PHP=$DIR_DRUPAL7_SITES/sites.php
 LOCAL_BRANCH_NAME=local
 DOMAIN=assos.local
+# Connexion variable
+REMOTE_DIR_TMP_SAS="~/tmp/assos"
+SSH_ID_SAS=jenselme
+SSH_ID_WEBASSOS=assos@webassos.ec-m.fr
+
+## Functions
+# We cannot directly use commands like scp or rsync since we cannot directly access
+# the server. We use the functions defined below instead. It is advised to put these
+# functions in your .bashrc or equivalent in order to use them any time you want. These
+# functions are tested and work with bash. They are incompatible witsh zsh.
+# They can only take 2 positional parameters.
+
+copy_assos_init() {
+    ssh $SSH_ID_SAS "mkdir -p $REMOTE_DIR_TMP_SAS"
+}
+
+get_args() {
+    if [ "$#" -gt 2 ] ; then
+	echo ${@:1:$#-2}
+    fi
+}
+
+clean() {
+    ssh $SSH_ID_SAS "rm -r $REMOTE_DIR_TMP_SAS/$1"
+}
+
+scp_from_assos() {
+    local input=("$@")
+    local args=$(get_args $@)
+    local source=${input[$#-2]}
+    local dest=${input[$#-1]}
+
+    ssh $SSH_ID_SAS "scp $args $SSH_ID_WEBASSOS:$source $REMOTE_DIR_TMP_SAS" &&
+    scp $args $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source $dest &&
+    clean $source
+}
+
+scp_to_assos() {
+    local input=("$@")
+    local args=$(get_args $@)
+    local source=${input[$#-2]}
+    local dest=${input[$#-1]}
+
+    scp $args $source $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source &&
+    ssh $SSH_ID_SAS "scp $args $REMOTE_DIR_TMP_SAS/$source $SSH_ID_WEBASSOS:$dest" &&
+    clean $source
+}
+
+rsync_from_assos() {
+    local input=("$@")
+    local args=$(get_args $@)
+    local source=${input[$#-2]}
+    local dest=${input[$#-1]}
+
+    ssh $SSH_ID_SAS "rsync $args $SSH_ID_WEBASSOS:$source $REMOTE_DIR_TMP_SAS" &&
+    rsync $args $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source $dest &&
+    clean $source
+}
+
+rsync_to_assos() {
+    local input=("$@")
+    local args=$(get_args $@)
+    local source=${input[$#-2]}
+    local dest=${input[$#-1]}
+
+    rsync $args $source $SSH_ID_SAS:$REMOTE_DIR_TMP_SAS/$source &&
+    ssh $SSH_ID_SAS "rsync $args $REMOTE_DIR_TMP_SAS/$source $SSH_ID_WEBASSOS:$dest" &&
+    clean $source
+}
diff --git a/other-scripts/d7-sync.sh b/other-scripts/d7-sync.sh
index befa0efd..6f5e96ff 100755
--- a/other-scripts/d7-sync.sh
+++ b/other-scripts/d7-sync.sh
@@ -1,7 +1,8 @@
 #!/usr/bin/env bash
 
 help=<<EOF
-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.
+This script is intended to ease the synchronisation of any site hosted by assos.
+It relies on bash, drush and requires a valid d7-sync-config.sh.
 The drupal installation is synched using git, the website files and database using rsync.
 
 usage: d7-sync.sh [SITENAME]
@@ -50,7 +51,7 @@ fi
 
 mkdir $dir_site
 cd $dir_site
-rsync -rltp --progress --delete assos:~/drupal7/sites/$dir_site/* .
+rsync_from_assos -rltp --progress --delete ~/drupal7/sites/$dir_site/* .
 # Change permissions for Apache
 # TODO: do something less permissive than 755
 chmod -R 755 .
@@ -61,19 +62,19 @@ chmod -R 777 files
 now=$(date +%s)
 sql_file="$1.$now.sql"
 remote_sql_file="~/tmp/$sql_file"
-ssh assos "drush @$1 sql-dump > $remote_sql_file"
-scp assos:$remote_sql_file .
+assos "drush @$1 sql-dump > $remote_sql_file"
+scp_from_assos $remote_sql_file .
 mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
 ret=$?
 if [ $ret -ne 0 ] ; then
     echo "mysql daemon is not started. Exiting."
-    ssh assos "rm $remote_sql_file"
+    assos "rm $remote_sql_file"
     rm $sql_file
     exit 1
 fi
 mysql -u root $local_db_name < $sql_file
 rm $sql_file
-ssh assos "rm $remote_sql_file"
+assos "rm $remote_sql_file"
 
 ### modify settings.php
 python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
@@ -88,7 +89,7 @@ git commit -a -m "Modify sites.php"
 drush status > /dev/null
 ret=$?
 if [ $ret -ne 0 ] ; then
-    echo "drush or site has a problem. Exiting"
+    echo "drush or site has a problem. Exiting."
     exit 1
 fi
 drush -y dis piwik
