Projet

Général

Profil

Révision 3e9236bd

Ajouté par Julien Enselme il y a plus de 9 ans

Update scritp so they respect the new convention.

  • Variables are quoted.
  • $(…) are quoted.

Voir les différences:

other-scripts/d7-sync.sh
16 16
### Init
17 17
# Config
18 18
source d7-sync-config.sh || source d7-sync-config.example.sh
19
cd $DIR_MULTIASSOS
20
ret=$?
21
if [ $ret -ne 0 ] ; then
19
cd "${DIR_MULTIASSOS}"
20
ret="$?"
21
if [ "${ret}" -ne 0 ] ; then
22 22
    echo "No config file. Exiting."
23 23
    exit 2
24 24
fi
25 25
# git
26 26
git checkout master
27
git branch $LOCAL_BRANCH_NAME
27
git branch "${LOCAL_BRANCH_NAME}"
28 28

  
29 29
### sync drupal tree
30 30
git pull --rebase
31
git checkout $LOCAL_BRANCH_NAME
31
git checkout "${LOCAL_BRANCH_NAME}"
32 32
# Auto solve conflicts: it takes the version from master in case of conflict.
33 33
git rebase master --strategy-option ours
34 34

  
......
37 37
    exit 0
38 38
fi
39 39

  
40
cd $DIR_DRUPAL7_SITES
40
cd "${DIR_DRUPAL7_SITES}"
41 41

  
42 42
# Some variables are different for default
43
if [ $1 = default ] ; then
44
    dir_site=$1
45
    base_url=http://$DOMAIN
43
if [ "$1" = default ] ; then
44
    dir_site="$1"
45
    base_url="http://${DOMAIN}"
46 46
    local_db_name=assos_default
47 47
else
48
    dir_site=assos.centrale-marseille.fr.$1
49
    base_url=http://$DOMAIN/$1
50
    local_db_name=$1
48
    dir_site="assos.centrale-marseille.fr.$1"
49
    base_url="http://${DOMAIN}/$1"
50
    local_db_name="$1"
51 51
fi
52 52

  
53
mkdir $dir_site
54
cd $dir_site
55
rsync -rltp --progress --delete $WEBASSOS_ID:drupal7/sites/$dir_site/ .
53
mkdir "${dir_site}"
54
cd "${dir_site}"
55
rsync -rltp --progress --delete "${WEBASSOS_ID}:drupal7/sites/${dir_site}/" .
56 56
# Change permissions for Apache
57 57
# TODO: do something less permissive than 755
58 58
chmod -R 755 .
......
60 60

  
61 61

  
62 62
### sync databases
63
now=$(date +%s)
64
sql_file="$1.$now.sql"
65
remote_sql_file="$REMOTE_DIR_TMP_SAS/$sql_file"
66
ssh $WEBASSOS_ID "drush @$1 sql-dump > $remote_sql_file"
67
scp $WEBASSOS_ID:$remote_sql_file .
63
now="$(date +%s)"
64
sql_file="$1.${now}.sql"
65
remote_sql_file="${REMOTE_DIR_TMP_SAS}/${sql_file}"
66
ssh "${WEBASSOS_ID}" "drush @$1 sql-dump > ${remote_sql_file}"
67
scp "${WEBASSOS_ID}:${remote_sql_file}" .
68 68
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
69
ret=$?
70
if [ $ret -ne 0 ] ; then
69
ret="$?"
70
if [ "${ret}" -ne 0 ] ; then
71 71
    echo "mysql daemon is not started. Exiting."
72 72
    assos "rm $remote_sql_file"
73
    rm $sql_file
73
    rm "${sql_file}"
74 74
    exit 1
75 75
fi
76
mysql -u root $local_db_name < $sql_file
77
rm $sql_file
78
ssh $WEBASSOS_ID "rm $remote_sql_file"
76
mysql -u root "${local_db_name}" < "${sql_file}"
77
rm "${sql_file}"
78
ssh "${WEBASSOS_ID}" "rm ${remote_sql_file}"
79 79

  
80 80
### modify settings.php
81
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
81
python3 "${DIR_MULTIASSOS}/other-scripts/modify-settings.py" "settings.local.php" --baseurl "${base_url}" --database "${local_db_name}"
82 82
chmod 666 *.php
83 83

  
84 84
### Modify sites.php
85
sed "s/\['assos.centrale-marseille.fr[a-b1-9]*/['$DOMAIN/g" < $SITES_PHP > $SITES_PHP.tmp
86
mv $SITES_PHP.tmp $SITES_PHP
85
sed "s/\['assos.centrale-marseille.fr[a-b1-9]*/['$DOMAIN/g" < "${SITES_PHP}" > "${SITES_PHP}.tmp"
86
mv "${SITES_PHP}.tmp" "${SITES_PHP}"
87 87
git commit -a -m "Modify sites.php"
88 88

  
89 89
### various drush cmd to finish synchronisation
90 90
drush status > /dev/null
91
ret=$?
92
if [ $ret -ne 0 ] ; then
91
ret="$?"
92
if [ "$ret" -ne 0 ] ; then
93 93
    echo "drush or site has a problem. Exiting."
94 94
    exit 1
95 95
fi

Formats disponibles : Unified diff