Révision 3e9236bd
Ajouté par Julien Enselme il y a plus de 9 ans
bin/all-reset-permissions.sh | ||
---|---|---|
5 | 5 |
# This script puts the correct permissions to sites folders, settings.php and scripts. |
6 | 6 |
|
7 | 7 |
######### drupal 7 |
8 |
for dir in $(find $d7_dir_sites -type d -maxdepth 1 -mindepth 1 ! -name all) ; do
|
|
9 |
chmod 755 $dir
|
|
10 |
chmod 400 $dir/settings.php
|
|
11 |
chmod 400 $dir/settings.local.php
|
|
8 |
for dir in "$(find "${d7_dir_sites}" -type d -maxdepth 1 -mindepth 1 ! -name all)" ; do
|
|
9 |
chmod 755 "${dir}"
|
|
10 |
chmod 400 "${dir}/settings.php"
|
|
11 |
chmod 400 "${dir}/settings.local.php"
|
|
12 | 12 |
done |
13 | 13 |
|
14 | 14 |
####### bin |
15 |
chmod -R 700 $dir_scripts
|
|
15 |
chmod -R 700 "${dir_scripts}"
|
|
16 | 16 |
|
17 | 17 |
####### backup |
18 |
chmod -R 700 $dir_backup
|
|
18 |
chmod -R 700 "${dir_backup}"
|
|
19 | 19 |
|
20 | 20 |
####### log |
21 |
chmod -R 700 $dir_log
|
|
21 |
chmod -R 700 "${dir_log}"
|
|
22 | 22 |
|
23 | 23 |
####### private |
24 |
chmod -R 700 $dir_private |
|
24 |
chmod -R 700 "${dir_private}" |
bin/d7-all-drush.sh | ||
---|---|---|
5 | 5 |
|
6 | 6 |
help="# ARGS: drush_command" |
7 | 7 |
|
8 |
check_arguments $# 1 "$help"
|
|
8 |
check_arguments "$#" 1 "${help}"
|
|
9 | 9 |
|
10 |
for dir in $(find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort) ; do
|
|
11 |
cd $dir
|
|
12 |
echo $dir
|
|
10 |
for dir in "$(find "${d7_dir_sites}" -maxdepth 1 -mindepth 1 -type d ! -name all | sort)" ; do
|
|
11 |
cd "${dir}"
|
|
12 |
echo "${dir}"
|
|
13 | 13 |
drush "$@" |
14 | 14 |
sleep 5 |
15 | 15 |
done |
bin/d7-all-dump-full.sh | ||
---|---|---|
3 | 3 |
. /home/assos/bin/scripts-config.sh |
4 | 4 |
. /home/assos/bin/scripts-utils.sh |
5 | 5 |
|
6 |
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
|
6 |
current_date="$(date "+%Y-%m-%d-%Hh%Mm%Ss")"
|
|
7 | 7 |
|
8 | 8 |
# Dump D7 databases at once. |
9 |
mysqldump --defaults-extra-file=$myassos_cnf --all-databases | gzip > $d7_dir_full_backup/myassos/$current_date.d7_full.sql.gz |
|
9 |
mysqldump --defaults-extra-file="${myassos_cnf}" --all-databases | gzip > "${d7_dir_full_backup}/myassos/${current_date}.d7_full.sql.gz" |
bin/d7-all-dump-individual.sh | ||
---|---|---|
5 | 5 |
|
6 | 6 |
help="# ARGS: auto or manual" |
7 | 7 |
|
8 |
check_arguments $# 1 "$help"
|
|
8 |
check_arguments "$#" 1 "$help"
|
|
9 | 9 |
|
10 |
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
|
10 |
current_date="$(date "+%Y-%m-%d-%Hh%Mm%Ss")"
|
|
11 | 11 |
|
12 |
cd $d7_dir_sites
|
|
12 |
cd "${d7_dir_sites}"
|
|
13 | 13 |
|
14 |
for dir in $(find . -maxdepth 1 -mindepth 1 -type d ! -name all | cut -c3-) ; do
|
|
15 |
cd $dir
|
|
14 |
for dir in "$(find . -maxdepth 1 -mindepth 1 -type d ! -name all | cut -c3-)" ; do
|
|
15 |
cd "${dir}"
|
|
16 | 16 |
drush cc all |
17 |
if [ $1 = 'auto' ] ; then
|
|
18 |
drush sql-dump --result-file=$d7_dir_individual_auto_backup/$dir/$current_date.$dir.sql --gzip
|
|
17 |
if [ "$1" = 'auto' ] ; then
|
|
18 |
drush sql-dump --result-file="${d7_dir_individual_auto_backup}/${dir}/${current_date}.${dir}.sql --gzip"
|
|
19 | 19 |
else |
20 |
drush sql-dump --result-file=$d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql --gzip
|
|
20 |
drush sql-dump --result-file="${d7_dir_individual_manual_backup}/${dir}/${current_date}.${dir}.sql --gzip"
|
|
21 | 21 |
fi |
22 | 22 |
cd - |
23 | 23 |
done |
bin/d7-all-releases-info.sh | ||
---|---|---|
6 | 6 |
# and all versions that are available for same project on drupal.org |
7 | 7 |
|
8 | 8 |
# modules |
9 |
cd $d7_dir_sites/all/modules
|
|
10 |
for dir in $(ls -1) ; do
|
|
11 |
if [ -d $dir ] ; then
|
|
12 |
drush pm-releases $dir
|
|
9 |
cd "${d7_dir_sites}/all/modules"
|
|
10 |
for dir in "$(ls -1)" ; do
|
|
11 |
if [ -d "${dir}" ] ; then
|
|
12 |
drush pm-releases "${dir}"
|
|
13 | 13 |
fi |
14 | 14 |
done |
15 | 15 |
|
16 | 16 |
# themes |
17 |
cd $d7_dir_sites/all/themes
|
|
18 |
for dir in $(ls -1) ; do
|
|
19 |
if [ -d $dir ] ; then
|
|
20 |
drush pm-releases $dir
|
|
17 |
cd "${d7_dir_sites}/all/themes"
|
|
18 |
for dir in "$(ls -1)" ; do
|
|
19 |
if [ -d "${dir}" ] ; then
|
|
20 |
drush pm-releases "${dir}"
|
|
21 | 21 |
fi |
22 | 22 |
done |
bin/d7-all-reset-variables.sh | ||
---|---|---|
2 | 2 |
|
3 | 3 |
. /home/assos/bin/scripts-config.sh |
4 | 4 |
|
5 |
for dir in $(find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort) ; do
|
|
6 |
echo $dir
|
|
7 |
site_name=$(echo $dir | tr '.' '\n' | tail -n 1)
|
|
8 |
d7-reset-variables.sh $site_name
|
|
5 |
for dir in "$(find "${d7_dir_sites}" -maxdepth 1 -mindepth 1 -type d ! -name all | sort)" ; do
|
|
6 |
echo "${dir}"
|
|
7 |
site_name="$(echo "${dir}" | tr '.' '\n' | tail -n 1)"
|
|
8 |
d7-reset-variables.sh "${site_name}"
|
|
9 | 9 |
done |
bin/d7-all-security-review.sh | ||
---|---|---|
3 | 3 |
. /home/assos/bin/scripts-config.sh |
4 | 4 |
|
5 | 5 |
# grep -v success to keep site_name and error lines. |
6 |
bash -c "d7-all-drush.sh security-review --store |& grep -v success | mail -s d7-all-security-review.sh $email_multi_assos" |
|
6 |
bash -c "d7-all-drush.sh security-review --store |& grep -v success | mail -s d7-all-security-review.sh ${email_multi_assos}" |
bin/d7-all-update-contrib.sh | ||
---|---|---|
18 | 18 |
|
19 | 19 |
d7-all-drush.sh cron |
20 | 20 |
|
21 |
git add -A $d7_dir_sites/all
|
|
21 |
git add -A "${d7_dir_sites}/all"
|
|
22 | 22 |
commit "Weekly update of contrib modules" |
bin/d7-all-update-core.sh | ||
---|---|---|
6 | 6 |
Please do not launch in cron." |
7 | 7 |
|
8 | 8 |
if ! tty -s ; then |
9 |
echo $help
|
|
9 |
echo "${help}"
|
|
10 | 10 |
exit 1 |
11 | 11 |
fi |
12 | 12 |
|
... | ... | |
14 | 14 |
|
15 | 15 |
# Backup translations |
16 | 16 |
translations_backupdir=/var/tmp |
17 |
cp $translations_fr $translations_backupdir
|
|
17 |
cp "${translations_fr}" "${translations_backupdir}"
|
|
18 | 18 |
|
19 | 19 |
d7-all-dump-individual.sh manual |
20 | 20 |
|
21 | 21 |
d7-all-drush.sh -y en update |
22 | 22 |
|
23 |
cd $d7_dir
|
|
23 |
cd "${d7_dir}"
|
|
24 | 24 |
drush -y upc drupal |
25 | 25 |
|
26 | 26 |
d7-all-drush.sh -y updb |
... | ... | |
30 | 30 |
# Get the new subversion number: |
31 | 31 |
# cd to $d7_dir, filter drush status to get the drupal version line, |
32 | 32 |
# remove end line whitespaces, and get the 2 last caracters of the string. |
33 |
drupal_version=$(cd $d7_dir && drush status | grep "Drupal version" | tr -d ' ' | tail -c 3)
|
|
33 |
drupal_version="$(cd "${d7_dir}" && drush status | grep "Drupal version" | tr -d ' ' | tail -c 3)"
|
|
34 | 34 |
|
35 | 35 |
# Try to download new translation. If it fails, restore the old one. |
36 |
if ! curl -f http://ftp.drupal.org/files/translations/7.x/drupal/drupal-7.$drupal_version.fr.po -o $translations_fr ; then
|
|
37 |
cp $translations_backupdir/fr.po $translations_fr
|
|
36 |
if ! curl -f "http://ftp.drupal.org/files/translations/7.x/drupal/drupal-7.${drupal_version}.fr.po" -o "${translations_fr}" ; then
|
|
37 |
cp "${translations_backupdir}/fr.po" "${translations_fr}"
|
|
38 | 38 |
fi |
39 | 39 |
|
40 | 40 |
echo "Check for settings.php update." |
41 | 41 |
echo "If everything is fine, run:" |
42 |
echo -e "\tgit add -A drupal7 && git commit -m 'Udpate to 7.$drupal_version'" |
|
42 |
echo -e "\tgit add -A drupal7 && git commit -m 'Udpate to 7.${drupal_version}'" |
bin/d7-all-update-settings.sh | ||
---|---|---|
5 | 5 |
|
6 | 6 |
# This script updates all drupal 7 settings.php according to a new template. Site informations located in settings.local.php are left intact. |
7 | 7 |
|
8 |
for settings in $(find $d7_dir_sites -mindepth 2 -maxdepth 2 -name settings.php) ; do
|
|
8 |
for settings in "$(find "${d7_dir_sites}" -mindepth 2 -maxdepth 2 -name settings.php)" ; do
|
|
9 | 9 |
|
10 | 10 |
# We go into the settings.php directory. |
11 |
settings_dir=$(give_dir $settings)
|
|
12 |
cd $settings_dir
|
|
11 |
settings_dir="$(give_dir "${settings}")"
|
|
12 |
cd "${settings_dir}"
|
|
13 | 13 |
|
14 |
chmod 700 $settings
|
|
15 |
rm $settings
|
|
14 |
chmod 700 "${settings}"
|
|
15 |
rm "${settings}"
|
|
16 | 16 |
|
17 |
cp $d7_settings settings.php
|
|
17 |
cp "${d7_settings}" settings.php
|
|
18 | 18 |
chmod 400 settings.php |
19 | 19 |
done |
bin/d7-all-usage.sh | ||
---|---|---|
4 | 4 |
|
5 | 5 |
# For each modules and themes, list and count how much sites use its. |
6 | 6 |
|
7 |
cd $d7_dir_sites
|
|
7 |
cd "${d7_dir_sites}"
|
|
8 | 8 |
|
9 |
for line in $(drush pml --no-core --pipe); do
|
|
10 |
usage.sh d7 enabled "$line"
|
|
9 |
for line in "$(drush pml --no-core --pipe)"; do
|
|
10 |
usage.sh d7 enabled "${line}"
|
|
11 | 11 |
echo -e "\n" |
12 | 12 |
done |
bin/d7-create-site.sh | ||
---|---|---|
1 | 1 |
#!/bin/sh |
2 | 2 |
|
3 | 3 |
. /home/assos/bin/scripts-config.sh |
4 |
. /home/assos/bin/scripts-config-site.sh $1
|
|
4 |
. /home/assos/bin/scripts-config-site.sh "$1"
|
|
5 | 5 |
. /home/assos/bin/scripts-utils.sh |
6 | 6 |
|
7 | 7 |
help="# ARGS: site_name site_mail admin_password [--no-init-database]" |
8 | 8 |
|
9 |
check_arguments $# 3 "$help"
|
|
9 |
check_arguments "$#" 3 "${help}"
|
|
10 | 10 |
|
11 | 11 |
# Check if site already exists. |
12 |
if site_exists $d7_site_name ; then
|
|
12 |
if site_exists "${d7_site_name}" ; then
|
|
13 | 13 |
exit 1 |
14 | 14 |
fi |
15 | 15 |
|
... | ... | |
26 | 26 |
fi |
27 | 27 |
|
28 | 28 |
# "-" is forbidden because it provokes database error. |
29 |
if [ $(echo $1 | grep -) ] ; then
|
|
29 |
if [ "$(echo "$1" | grep -)" ] ; then
|
|
30 | 30 |
echo '"-" is forbidden in the site name' |
31 | 31 |
exit 1 |
32 | 32 |
fi |
33 | 33 |
|
34 | 34 |
# Site name length must be lower or equal to 16 due to database limitations. |
35 |
if [ $(echo $1 | wc -c) -gt 16 ] ; then
|
|
35 |
if [ "$(echo "$1" | wc -c)" -gt 16 ] ; then
|
|
36 | 36 |
echo "site name can't have more than 16 characters" |
37 | 37 |
exit 1 |
38 | 38 |
fi |
39 | 39 |
|
40 | 40 |
# drush site-install needs the translation file |
41 |
if [ ! -f $translation_fr ] ; then
|
|
41 |
if [ ! -f "${translation_fr}" ] ; then
|
|
42 | 42 |
echo "The translation file $translation_fr does not exist" |
43 | 43 |
exit 1 |
44 | 44 |
fi |
45 | 45 |
|
46 | 46 |
###### Initialisation |
47 |
cd $d7_dir
|
|
48 |
site_password=$(generate_password)
|
|
47 |
cd "${d7_dir}"
|
|
48 |
site_password="$(generate_password)"
|
|
49 | 49 |
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';" |
50 | 50 |
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/home/assos/drupal7/', );" |
51 | 51 |
# NB: site_name is initialised in script-config-site.sh |
52 |
site_mail=$2
|
|
53 |
admin_password=$3
|
|
52 |
site_mail="$2"
|
|
53 |
admin_password="$3"
|
|
54 | 54 |
|
55 | 55 |
|
56 | 56 |
###### Main |
57 |
mkdir $d7_site_dir
|
|
58 |
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
|
|
57 |
mkdir "${d7_site_dir}"
|
|
58 |
dir_site_name="assos.centrale-marseille.fr.${d7_site_name}"
|
|
59 | 59 |
|
60 | 60 |
# Backup requirements |
61 |
mkdir $d7_dir_individual_auto_backup/$dir_site_name
|
|
62 |
mkdir $d7_dir_individual_manual_backup/$dir_site_name
|
|
63 |
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
|
61 |
mkdir "${d7_dir_individual_auto_backup}/${dir_site_name}"
|
|
62 |
mkdir "${d7_dir_individual_manual_backup}/${dir_site_name}"
|
|
63 |
current_date="$(date "+%Y-%m-%d-%Hh%Mm%Ss")"
|
|
64 | 64 |
|
65 | 65 |
# NB : ls sort by considering the 1st characters |
66 |
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql
|
|
67 |
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2
|
|
68 |
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3
|
|
69 |
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4
|
|
66 |
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql"
|
|
67 |
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql2"
|
|
68 |
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql3"
|
|
69 |
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql4}"
|
|
70 | 70 |
|
71 | 71 |
# Create and grant privileges on database |
72 |
mysql --defaults-extra-file=$myassos_cnf -e "CREATE DATABASE $d7_site_name"
|
|
73 |
mysql --defaults-extra-file=$myassos_cnf -e "GRANT ALL PRIVILEGES ON $d7_site_name.* TO '$d7_site_name'@'%' IDENTIFIED BY '$site_password'"
|
|
72 |
mysql --defaults-extra-file="${myassos_cnf}" -e "CREATE DATABASE ${d7_site_name}"
|
|
73 |
mysql --defaults-extra-file="${myassos_cnf}" -e "GRANT ALL PRIVILEGES ON ${d7_site_name}.* TO '${d7_site_name}'@'%' IDENTIFIED BY '${site_password}'"
|
|
74 | 74 |
|
75 | 75 |
# Create settings.local.php |
76 |
cp $d7_settings $d7_site_settings
|
|
77 |
generate_settings_local $d7_site_name $site_password $d7_settings_local_template $d7_site_settings_local
|
|
76 |
cp "${d7_settings}" "${d7_site_settings}"
|
|
77 |
generate_settings_local "${d7_site_name}" "${site_password}" "${d7_settings_local_template}" "${d7_site_settings_local}"
|
|
78 | 78 |
|
79 | 79 |
# Install the site |
80 |
drush site-install -y standard --account-mail=$site_mail --account-name="admin" --account-pass=$admin_password --locale=fr --site-mail=$site_mail --site-name=$d7_site_name --sites-subdir=$dir_site_name
|
|
80 |
drush site-install -y standard --account-mail="${site_mail}" --account-name="admin" --account-pass="${admin_password}" --locale=fr --site-mail="${site_mail}" --site-name="${d7_site_name}" --sites-subdir="${dir_site_name}"
|
|
81 | 81 |
|
82 | 82 |
# Create symbolic link |
83 |
cd $d7_dir
|
|
84 |
ln -s . $d7_site_name
|
|
85 |
git add $d7_site_name
|
|
83 |
cd "${d7_dir}"
|
|
84 |
ln -s . "${d7_site_name}"
|
|
85 |
git add "${d7_site_name}"
|
|
86 | 86 |
|
87 | 87 |
# Update sites.php |
88 |
chmod +w $sites_php
|
|
89 |
echo $site_line_sites_php >> $sites_php
|
|
90 |
chmod 400 $sites_php
|
|
88 |
chmod +w "${sites_php}"
|
|
89 |
echo "${site_line_sites_php}" >> "${sites_php}"
|
|
90 |
chmod 400 "${sites_php}"
|
|
91 | 91 |
|
92 | 92 |
### Update aliases.drushrc.php |
93 | 93 |
# For site |
94 |
echo $site_line_aliases_drushrc_php >> $aliases_drushrc_php
|
|
94 |
echo "${site_line_aliases_drushrc_php}" >> "${aliases_drushrc_php}"
|
|
95 | 95 |
# @d7 |
96 |
sed s/"'site-list' => array("/"'site-list' => array(%'assos.centrale-marseille.fr\/$d7_site_name',"/ < $aliases_drushrc_php | tr '%' '\n ' > $dir_tmp/aliases.tmp
|
|
97 |
mv $dir_tmp/aliases.tmp $aliases_drushrc_php
|
|
96 |
sed s/"'site-list' => array("/"'site-list' => array(%'assos.centrale-marseille.fr\/$d7_site_name',"/ < "${aliases_drushrc_php}" | tr '%' '\n ' > "${dir_tmp}/aliases.tmp"
|
|
97 |
mv "${dir_tmp}/aliases.tmp" "${aliases_drushrc_php}"
|
|
98 | 98 |
|
99 |
commit "Creation of site: $d7_site_name"
|
|
99 |
commit "Creation of site: ${d7_site_name}"
|
|
100 | 100 |
|
101 | 101 |
# Next Instructions |
102 |
if [ $init_db -eq 0 ] ; then
|
|
102 |
if [ "${init_db}" -eq 0 ] ; then
|
|
103 | 103 |
exit 0 |
104 | 104 |
fi |
105 | 105 |
|
106 | 106 |
# Init variables |
107 |
d7-reset-variables.sh $d7_site_name
|
|
107 |
d7-reset-variables.sh "${d7_site_name}"
|
|
108 | 108 |
|
109 | 109 |
# Permissions |
110 |
chmod -R 755 $d7_site_dir
|
|
111 |
chmod 400 $d7_site_settings
|
|
110 |
chmod -R 755 "${d7_site_dir}"
|
|
111 |
chmod 400 "${d7_site_settings}"
|
|
112 | 112 |
|
113 | 113 |
# Last instructions |
114 | 114 |
echo "Last instructions:" |
bin/d7-delete-site.sh | ||
---|---|---|
1 | 1 |
#!/bin/sh |
2 | 2 |
|
3 | 3 |
. /home/assos/bin/scripts-config.sh |
4 |
. scripts-config-site.sh $1
|
|
4 |
. scripts-config-site.sh "$1"
|
|
5 | 5 |
. scripts-utils.sh |
6 | 6 |
|
7 | 7 |
help="# ARGS: site name." |
8 | 8 |
|
9 |
check_arguments $# 1 "$help"
|
|
9 |
check_arguments "$#" 1 "${help}"
|
|
10 | 10 |
|
11 | 11 |
echo 'Awaiting for git status. (may take a while)' |
12 | 12 |
if ! work_tree_clean ; then |
... | ... | |
15 | 15 |
fi |
16 | 16 |
|
17 | 17 |
echo 'Delete database.' |
18 |
mysql --defaults-extra-file=$myassos_cnf -e "DROP DATABASE $d7_site_name"
|
|
18 |
mysql --defaults-extra-file="${myassos_cnf}" -e "DROP DATABASE ${d7_site_name}"
|
|
19 | 19 |
|
20 | 20 |
echo 'Delete MYSQL user.' |
21 |
mysql --defaults-extra-file=$myassos_cnf -e "DROP USER '$d7_site_name'@'%'"
|
|
21 |
mysql --defaults-extra-file="${myassos_cnf}" -e "DROP USER '${d7_site_name}'@'%'"
|
|
22 | 22 |
|
23 | 23 |
echo "Delete site's folder." |
24 |
chmod -R 700 $d7_site_dir
|
|
25 |
rm -r $d7_site_dir
|
|
24 |
chmod -R 700 "${d7_site_dir}"
|
|
25 |
rm -r "${d7_site_dir}"
|
|
26 | 26 |
|
27 | 27 |
# Delete symbolic link. |
28 |
rm $d7_dir/$d7_site_name
|
|
28 |
rm "${d7_dir}/${d7_site_name}"
|
|
29 | 29 |
|
30 | 30 |
echo 'Remove site line from sites.php' |
31 |
chmod +w $sites_php
|
|
32 |
grep -sv "^\$.*$d7_site_name';$" $sites_php > $dir_tmp/sites.php
|
|
33 |
mv $dir_tmp/sites.php $sites_php
|
|
34 |
chmod 400 $sites_php
|
|
31 |
chmod +w "${sites_php}"
|
|
32 |
grep -sv "^\$.*$d7_site_name';$" "${sites_php}" > "${dir_tmp}/sites.php"
|
|
33 |
mv "${dir_tmp}/sites.php" "${sites_php}"
|
|
34 |
chmod 400 "${sites_php}"
|
|
35 | 35 |
|
36 | 36 |
echo 'Remove site alias from aliases.drushrc.php' |
37 |
grep -sv "$d7_site_name'" $aliases_drushrc_php > $dir_tmp/aliases.php
|
|
38 |
mv $dir_tmp/aliases.php $aliases_drushrc_php
|
|
37 |
grep -sv "${d7_site_name}'" "${aliases_drushrc_php}" > "${dir_tmp}/aliases.php"
|
|
38 |
mv "${dir_tmp}/aliases.php" "${aliases_drushrc_php}"
|
|
39 | 39 |
|
40 | 40 |
echo 'Delete database backups.' |
41 |
rm -r $d7_dir_individual_auto_backup/assos.centrale-marseille.fr.$d7_site_name
|
|
42 |
rm -r $d7_dir_individual_manual_backup/assos.centrale-marseille.fr.$d7_site_name
|
|
41 |
rm -r "${d7_dir_individual_auto_backup}/assos.centrale-marseille.fr.${d7_site_name}"
|
|
42 |
rm -r "${d7_dir_individual_manual_backup}/assos.centrale-marseille.fr.${d7_site_name}"
|
|
43 | 43 |
|
44 | 44 |
echo "Don't forget to:" |
45 | 45 |
echo "- Refresh node site on default" |
46 | 46 |
echo "- Check particular behavior (normally detailed on site node)" |
47 | 47 |
|
48 |
commit "Deletion of site: $d7_site_name" |
|
48 |
commit "Deletion of site: ${d7_site_name}" |
bin/d7-reset-piwik-variables.sh | ||
---|---|---|
15 | 15 |
|
16 | 16 |
##### Specific |
17 | 17 |
# Note: you can read the piwik site id from the url in piwik |
18 |
case $1 in
|
|
18 |
case "$1" in
|
|
19 | 19 |
accueil) |
20 | 20 |
piwik_id=286 |
21 | 21 |
;; |
... | ... | |
76 | 76 |
tvp) |
77 | 77 |
piwik_id=110 |
78 | 78 |
;; |
79 |
ftorregrosa)
|
|
80 |
piwik_id=314
|
|
81 |
;;
|
|
79 |
ftorregrosa)
|
|
80 |
piwik_id=314
|
|
81 |
;;
|
|
82 | 82 |
*) |
83 | 83 |
piwik_id=287 |
84 | 84 |
;; |
85 | 85 |
esac |
86 | 86 |
|
87 | 87 |
# Default is an exception and cannot be treated in the case |
88 |
if echo $1 | grep default ; then
|
|
88 |
if echo "$1" | grep default ; then
|
|
89 | 89 |
piwik_id=101 |
90 | 90 |
fi |
91 | 91 |
|
92 |
drush -yq vset piwik_site_id $piwik_id |
|
92 |
drush -yq vset piwik_site_id "${piwik_id}" |
bin/d7-reset-variables.sh | ||
---|---|---|
4 | 4 |
|
5 | 5 |
# ARGS: [site_name] |
6 | 6 |
|
7 |
if [ ! -z $1 ] ; then
|
|
8 |
. scripts-config-site.sh $1
|
|
7 |
if [ -n "$1" ] ; then
|
|
8 |
. scripts-config-site.sh "$1"
|
|
9 | 9 |
# default is an exception to the rule |
10 |
if echo $1 | grep default > /dev/null ; then
|
|
11 |
cd $d7_dir_sites/default
|
|
10 |
if echo "$1" | grep default > /dev/null ; then
|
|
11 |
cd "${d7_dir_sites}/default"
|
|
12 | 12 |
else |
13 |
cd $d7_site_dir
|
|
13 |
cd "${d7_site_dir}"
|
|
14 | 14 |
fi |
15 | 15 |
fi |
16 | 16 |
|
17 |
current_timestamp=$(date "+%s")
|
|
17 |
current_timestamp="$(date "+%s")"
|
|
18 | 18 |
|
19 |
random_1=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ")
|
|
20 |
random_2=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ")
|
|
19 |
random_1="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ")"
|
|
20 |
random_2="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ")"
|
|
21 | 21 |
|
22 | 22 |
####### General variables |
23 | 23 |
drush -yq vset --always-set reverse_proxy TRUE |
... | ... | |
41 | 41 |
|
42 | 42 |
|
43 | 43 |
####### Piwik |
44 |
d7-reset-piwik-variables.sh $d7_site_name
|
|
44 |
d7-reset-piwik-variables.sh "${d7_site_name}"
|
|
45 | 45 |
|
46 | 46 |
###### Security review |
47 | 47 |
# For untrusted roles: |
bin/d7-sync-site.sh | ||
---|---|---|
14 | 14 |
. /home/assos/bin/scripts-config.sh |
15 | 15 |
. /home/assos/bin/scripts-utils.sh |
16 | 16 |
|
17 |
check_arguments $# 2 "$help"
|
|
17 |
check_arguments "$#" 2 "${help}"
|
|
18 | 18 |
|
19 | 19 |
|
20 | 20 |
# Create site if necessary |
21 |
if ! site_exists $2 > /dev/null ; then
|
|
21 |
if ! site_exists "$2" > /dev/null ; then
|
|
22 | 22 |
echo "$2 does not exit. We will create it" |
23 |
d7-create-site.sh $2 --no-init-database
|
|
23 |
d7-create-site.sh "$2" --no-init-database
|
|
24 | 24 |
# if the site is new, there is no database |
25 | 25 |
new_site=1 |
26 | 26 |
fi |
27 | 27 |
|
28 | 28 |
|
29 | 29 |
# Backup the database of SOURCE_SITE |
30 |
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
|
31 |
if [ $1 = "default" ] ; then
|
|
32 |
dir=$2
|
|
30 |
current_date="$(date "+%Y-%m-%d-%Hh%Mm%Ss")"
|
|
31 |
if [ "$1" = "default" ] ; then
|
|
32 |
dir="$2"
|
|
33 | 33 |
else |
34 |
dir=assos.centrale-marseille.fr.$2
|
|
34 |
dir="assos.centrale-marseille.fr.$2"
|
|
35 | 35 |
fi |
36 |
if [ -z "$new_site" ] ; then
|
|
37 |
drush -y @$1 sql-dump --result-file=$d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql --gzip
|
|
36 |
if [ -z "${new_site}" ] ; then
|
|
37 |
drush -y "@$1" sql-dump --result-file="${d7_dir_individual_manual_backup}/${dir}/${current_date}.${dir}.sql" --gzip
|
|
38 | 38 |
fi |
39 | 39 |
|
40 | 40 |
|
41 | 41 |
# Sync files |
42 |
drush -y rsync --delete --exclude="*.php" @${1}:%site @${2}:%site
|
|
42 |
drush -y rsync --delete --exclude="*.php" "@${1}:%site" "@${2}:%site"
|
|
43 | 43 |
|
44 | 44 |
|
45 | 45 |
# Sync databases |
46 | 46 |
## Save file system |
47 |
if [ -z "$new_site" ] ; then
|
|
48 |
private_path=$(drush @$2 vget --format=string file_private_path 2> /dev/null)
|
|
49 |
public_path=$(drush @$2 vget --format=string file_public_path 2> /dev/null)
|
|
50 |
temp_path=$(drush @$2 vget --format=string file_temporary_path 2> /dev/null)
|
|
47 |
if [ -z "${new_site}" ] ; then
|
|
48 |
private_path="$(drush "@$2" vget --format=string file_private_path 2> /dev/null)"
|
|
49 |
public_path="$(drush "@$2" vget --format=string file_public_path 2> /dev/null)"
|
|
50 |
temp_path="$(drush "@$2" vget --format=string file_temporary_path 2> /dev/null)"
|
|
51 | 51 |
fi |
52 | 52 |
|
53 | 53 |
## Sync |
54 |
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
|
55 |
sql_file=$dir_tmp/$current_date.$1.sql
|
|
56 |
drush -y @$1 sql-dump --result-file=$sql_file
|
|
57 |
sed -i -e "s#https?://assos.centrale-marseille.fr/$1#https://assos.centrale-marseille.fr/$2#g" $sql_file
|
|
58 |
sed -i -e "s#/$1/sites/assos.centrale-marseille.fr.$1#/$2/sites/assos.centrale-marseille.fr.$2#g" $sql_file
|
|
59 |
drush @$2 sql-drop
|
|
60 |
drush @$2 sql-cli < $sql_file
|
|
61 |
rm $sql_file
|
|
54 |
current_date="$(date "+%Y-%m-%d-%Hh%Mm%Ss")"
|
|
55 |
sql_file="${dir_tmp}/${current_date}.$1.sql"
|
|
56 |
drush -y "@$1" sql-dump --result-file="${sql_file}"
|
|
57 |
sed -i -e "s#https?://assos.centrale-marseille.fr/$1#https://assos.centrale-marseille.fr/$2#g" "${sql_file}"
|
|
58 |
sed -i -e "s#/$1/sites/assos.centrale-marseille.fr.$1#/$2/sites/assos.centrale-marseille.fr.$2#g" "${sql_file}"
|
|
59 |
drush "@$2" sql-drop
|
|
60 |
drush "@$2" sql-cli < "${sql_file}"
|
|
61 |
rm "${sql_file}"
|
|
62 | 62 |
|
63 | 63 |
## Restore file system |
64 |
if [ -n "$private_path" ] ; then
|
|
65 |
drush -y @$2 vset file_private_path $private_path
|
|
64 |
if [ -n "${private_path}" ] ; then
|
|
65 |
drush -y "@$2" vset file_private_path "${private_path}"
|
|
66 | 66 |
fi |
67 |
if [ -n "$public_path" ] ; then
|
|
68 |
drush -y @$2 vset file_public_path $public_path
|
|
67 |
if [ -n "${public_path}" ] ; then
|
|
68 |
drush -y "@$2" vset file_public_path "${public_path}"
|
|
69 | 69 |
fi |
70 |
if [ -n "$temp_path" ] ; then
|
|
71 |
drush -y @$2 vset file_temporary_path $temp_path
|
|
70 |
if [ -n "${temp_path}" ] ; then
|
|
71 |
drush -y "@$2" vset file_temporary_path "${temp_path}"
|
|
72 | 72 |
fi |
73 | 73 |
|
74 | 74 |
if [ "$3" = "--prod" ] ; then |
75 |
drush -y @$2 vset maintenance_mode 0
|
|
75 |
drush -y "@$2" vset maintenance_mode 0
|
|
76 | 76 |
else |
77 |
drush -y @$2 vset maintenance_mode 1
|
|
77 |
drush -y "@$2" vset maintenance_mode 1
|
|
78 | 78 |
fi |
bin/delete-temporary-files.sh | ||
---|---|---|
2 | 2 |
|
3 | 3 |
. /home/assos/bin/scripts-config.sh |
4 | 4 |
|
5 |
find $dir_multi_assos -name '*~' -delete |
|
5 |
find "${dir_multi_assos}" -name '*~' -delete |
bin/disk-usage.sh | ||
---|---|---|
6 | 6 |
echo -e "\n" |
7 | 7 |
|
8 | 8 |
echo "Assos:" |
9 |
du -hcs $dir_multi_assos | grep total
|
|
9 |
du -hcs "${dir_multi_assos}" | grep total
|
|
10 | 10 |
echo -e "\n" |
11 | 11 |
|
12 | 12 |
echo "D7:" |
13 |
cd $d7_dir_sites
|
|
13 |
cd "${d7_dir_sites}"
|
|
14 | 14 |
du -h -d 1 |
15 | 15 |
echo -e "\n" |
16 | 16 |
|
17 | 17 |
echo "Logs:" |
18 |
du -hcs $dir_log | grep total
|
|
18 |
du -hcs "${dir_log}" | grep total
|
|
19 | 19 |
echo -e "\n" |
20 | 20 |
|
21 | 21 |
echo "Backups:" |
22 |
cd $dir_backup
|
|
22 |
cd "${dir_backup}"
|
|
23 | 23 |
du -h -d 2 |
bin/flush-files.sh | ||
---|---|---|
6 | 6 |
# from the terminal." |
7 | 7 |
|
8 | 8 |
# Check if scripts-utils.sh is imported. |
9 |
if [ -z $scripts_utils ] ; then
|
|
9 |
if [ -z "${scripts_utils}" ] ; then
|
|
10 | 10 |
echo "Import of scripts-utils.sh required." |
11 | 11 |
. scripts-utils.sh |
12 | 12 |
fi |
13 | 13 |
|
14 |
check_arguments $# 1 "$help"
|
|
14 |
check_arguments "$#" 1 "$help"
|
|
15 | 15 |
|
16 |
# Must not be quoted to avoid problem with ((…)) |
|
16 | 17 |
backups_number=$(ls | wc -l) |
17 |
let "number_of_backups_to_delete = backups_number - $1" > /dev/null
|
|
18 |
((number_of_backups_to_delete = backups_number - $1))
|
|
18 | 19 |
|
19 |
if [ $number_of_backups_to_delete -gt 0 ] ; then
|
|
20 |
ls | head -$number_of_backups_to_delete | xargs rm
|
|
20 |
if [ "${number_of_backups_to_delete}" -gt 0 ] ; then
|
|
21 |
ls | head "-${number_of_backups_to_delete}" | xargs rm
|
|
21 | 22 |
else |
22 |
if [ ! -z $2 ] ; then
|
|
23 |
dir=$(pwd)
|
|
24 |
echo "There are not enough files in $dir to Flush it. Check if backup script works fine." | mail -s "[db] $dir has a backup problem" $2
|
|
23 |
if [ ! -z "$2" ] ; then
|
|
24 |
dir="$(pwd)"
|
|
25 |
echo "There are not enough files in $dir to Flush it. Check if backup script works fine." | mail -s "[db] $dir has a backup problem" "$2"
|
|
25 | 26 |
fi |
26 | 27 |
fi |
bin/flush-full-databases-backups.sh | ||
---|---|---|
4 | 4 |
|
5 | 5 |
# ARGS: Drupal version |
6 | 6 |
|
7 |
cd $dir_full_backup/$1
|
|
7 |
cd "${dir_full_backup}/$1"
|
|
8 | 8 |
|
9 |
for dir in $(ls) ; do
|
|
10 |
cd $dir
|
|
11 |
flush-files.sh $db_full_backup_number $email_multi_assos
|
|
9 |
for dir in "$(ls)" ; do
|
|
10 |
cd "${dir}"
|
|
11 |
flush-files.sh "${db_full_backup_number}" "${email_multi_assos}"
|
|
12 | 12 |
cd - |
13 | 13 |
done |
bin/flush-individual-databases-backups.sh | ||
---|---|---|
4 | 4 |
|
5 | 5 |
# ARGS: manual or auto, Drupal version |
6 | 6 |
|
7 |
cd $dir_individual_backup/$1/$2
|
|
7 |
cd "${dir_individual_backup}/$1/$2"
|
|
8 | 8 |
|
9 |
for dir in $(ls) ; do
|
|
10 |
cd $dir
|
|
9 |
for dir in "$(ls)" ; do
|
|
10 |
cd "${dir}"
|
|
11 | 11 |
if [ $1 = 'auto' ] ; then |
12 |
flush-files.sh $db_individual_auto_backup_number $email_multi_assos
|
|
12 |
flush-files.sh "${db_individual_auto_backup_number}" "${email_multi_assos}"
|
|
13 | 13 |
else |
14 |
flush-files.sh $db_individual_manual_backup_number
|
|
14 |
flush-files.sh "${db_individual_manual_backup_number}"
|
|
15 | 15 |
fi |
16 | 16 |
cd - |
17 | 17 |
done |
bin/scripts-config-site.sh | ||
---|---|---|
6 | 6 |
# check_argumements is not used to avoid multiple imports |
7 | 7 |
|
8 | 8 |
# Check if scripts-config.sh is imported. |
9 |
if [ -z $scripts_config ] ; then
|
|
9 |
if [ -z "${scripts_config}" ] ; then
|
|
10 | 10 |
echo "Import of scripts-config.sh required." |
11 | 11 |
exit 1 |
12 | 12 |
fi |
13 | 13 |
|
14 |
if [ -z $1 ] ; then
|
|
14 |
if [ -z "$1" ] ; then
|
|
15 | 15 |
echo "This script needs a site name as argument." |
16 | 16 |
exit 1 |
17 | 17 |
fi |
18 | 18 |
|
19 | 19 |
scripts_config_site='imported' |
20 | 20 |
|
21 |
d7_site_name=$1 |
|
22 |
d7_site_dir="$d7_dir_sites/assos.centrale-marseille.fr.$d7_site_name" |
|
23 |
d7_site_settings="$d7_site_dir/settings.php" |
|
24 |
d7_site_settings_local="$d7_site_dir/settings.local.php" |
|
21 |
d7_site_name="$1" |
|
22 |
d7_site_dir="${d7_dir_sites}/assos.centrale-marseille.fr.${d7_site_name}" |
|
23 |
d7_site_settings="${d7_site_dir}/settings.php" |
|
24 |
d7_site_settings_local="${d7_site_dir}/settings.local.php" |
bin/scripts-config.sh | ||
---|---|---|
6 | 6 |
# *These variables must be used in scripts* |
7 | 7 |
|
8 | 8 |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin |
9 |
PATH=$PATH:/home/assos/bin
|
|
9 |
PATH="$PATH":/home/assos/bin
|
|
10 | 10 |
|
11 | 11 |
scripts_config='imported' |
12 | 12 |
|
... | ... | |
14 | 14 |
email_multi_assos_update="assos+update@centrale-marseille.fr" |
15 | 15 |
|
16 | 16 |
dir_multi_assos='/home/assos' |
17 |
dir_scripts="$dir_multi_assos/bin"
|
|
18 |
dir_template="$dir_multi_assos/template"
|
|
19 |
dir_private="$dir_multi_assos/private"
|
|
20 |
dir_tmp="$dir_multi_assos/tmp"
|
|
17 |
dir_scripts="${dir_multi_assos}/bin"
|
|
18 |
dir_template="${dir_multi_assos}/template"
|
|
19 |
dir_private="${dir_multi_assos}/private"
|
|
20 |
dir_tmp="${dir_multi_assos}/tmp"
|
|
21 | 21 |
|
22 | 22 |
###### Aliases |
23 | 23 |
### Bash |
24 |
. $dir_multi_assos/.aliases
|
|
24 |
. "${dir_multi_assos}/.aliases"
|
|
25 | 25 |
|
26 | 26 |
### Drush |
27 |
dot_drush="$dir_multi_assos/.drush"
|
|
28 |
aliases_drushrc_php="$dot_drush/aliases.drushrc.php"
|
|
27 |
dot_drush="${dir_multi_assos}/.drush"
|
|
28 |
aliases_drushrc_php="${dot_drush}/aliases.drushrc.php"
|
|
29 | 29 |
|
30 | 30 |
###### Database |
31 | 31 |
db_server="myassos.serv.int" |
32 | 32 |
db_user="assos" |
33 |
dir_log="$dir_multi_assos/log"
|
|
33 |
dir_log="${dir_multi_assos}/log"
|
|
34 | 34 |
|
35 | 35 |
###### Backup |
36 | 36 |
db_full_backup_number=3 |
37 | 37 |
db_individual_manual_backup_number=2 |
38 | 38 |
db_individual_auto_backup_number=3 |
39 | 39 |
|
40 |
dir_backup="$dir_multi_assos/backup"
|
|
41 |
dir_full_backup="$dir_backup/full"
|
|
42 |
dir_individual_backup="$dir_backup/individual"
|
|
43 |
dir_individual_manual_backup="$dir_individual_backup/manual"
|
|
44 |
dir_individual_auto_backup="$dir_individual_backup/auto"
|
|
40 |
dir_backup="${dir_multi_assos}/backup"
|
|
41 |
dir_full_backup="${dir_backup}/full"
|
|
42 |
dir_individual_backup="${dir_backup}/individual"
|
|
43 |
dir_individual_manual_backup="${dir_individual_backup}/manual"
|
|
44 |
dir_individual_auto_backup="${dir_individual_backup}/auto"
|
|
45 | 45 |
|
46 |
myassos_cnf="$dir_private/myassos.cnf"
|
|
46 |
myassos_cnf="${dir_private}/myassos.cnf"
|
|
47 | 47 |
|
48 | 48 |
###### D7 variables |
49 |
d7_dir="$dir_multi_assos/drupal7"
|
|
50 |
d7_dir_sites="$d7_dir/sites"
|
|
51 |
sites_php="$d7_dir_sites/sites.php"
|
|
52 |
translations_fr="$d7_dir/profiles/standard/translations/fr.po"
|
|
49 |
d7_dir="${dir_multi_assos}/drupal7"
|
|
50 |
d7_dir_sites="${d7_dir}/sites"
|
|
51 |
sites_php="${d7_dir_sites}/sites.php"
|
|
52 |
translations_fr="${d7_dir}/profiles/standard/translations/fr.po"
|
|
53 | 53 |
|
54 | 54 |
### Log |
55 |
d7_dir_log="$dir_log/d7"
|
|
55 |
d7_dir_log="${dir_log}/d7"
|
|
56 | 56 |
|
57 | 57 |
### Backup |
58 |
d7_dir_full_backup="$dir_full_backup/d7"
|
|
59 |
d7_dir_individual_manual_backup="$dir_individual_manual_backup/d7"
|
|
60 |
d7_dir_individual_auto_backup="$dir_individual_auto_backup/d7"
|
|
58 |
d7_dir_full_backup="${dir_full_backup}/d7"
|
|
59 |
d7_dir_individual_manual_backup="${dir_individual_manual_backup}/d7"
|
|
60 |
d7_dir_individual_auto_backup="${dir_individual_auto_backup}/d7"
|
|
61 | 61 |
|
62 | 62 |
### Template |
63 | 63 |
d7_settings_name="d7-settings.php" |
64 | 64 |
d7_settings_local_template_name="d7-settings-local-template.php" |
65 |
d7_settings="$dir_template/$d7_settings_name" |
|
66 |
d7_settings_local_template="$dir_template/$d7_settings_local_template_name" |
|
65 |
d7_settings="${dir_template}/${d7_settings_name}" |
|
66 |
d7_settings_local_template="${dir_template}/${d7_settings_local_template_name}" |
bin/scripts-utils.sh | ||
---|---|---|
3 | 3 |
# This script contains useful functions for other scripts. |
4 | 4 |
|
5 | 5 |
# Check if scripts-config.sh is imported. |
6 |
if [ -z $scripts_config ] ; then
|
|
6 |
if [ -z "${scripts_config}" ] ; then
|
|
7 | 7 |
echo "Import of scripts-config.sh required." |
8 | 8 |
. scripts-config.sh |
9 | 9 |
fi |
... | ... | |
13 | 13 |
ask_password() { |
14 | 14 |
# read -s doesn't work with sh. |
15 | 15 |
# usage: pass=$(ask_password "password please:") |
16 |
echo $1 >&2
|
|
16 |
echo "$1" >&2
|
|
17 | 17 |
echo -n ">" >&2 |
18 | 18 |
stty_avant=$(stty -g) |
19 | 19 |
stty -echo |
20 | 20 |
read password |
21 |
stty $stty_avant
|
|
22 |
echo "$password"
|
|
21 |
stty "${stty_avant}"
|
|
22 |
echo "${password}"
|
|
23 | 23 |
unset password |
24 | 24 |
} |
25 | 25 |
|
... | ... | |
29 | 29 |
|
30 | 30 |
local site_password='/' |
31 | 31 |
|
32 |
if [ -z $1 ] ; then
|
|
32 |
if [ -z "$1" ] ; then
|
|
33 | 33 |
local password_length=20 |
34 | 34 |
else |
35 |
local password_length=$1
|
|
35 |
local password_length="$1"
|
|
36 | 36 |
fi |
37 | 37 |
|
38 | 38 |
while echo "$site_password" | grep -Fq '/' ; do |
39 |
site_password=$(dd if=/dev/random count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-$password_length)
|
|
39 |
site_password="$(dd if=/dev/random count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-"${password_length}")"
|
|
40 | 40 |
done |
41 | 41 |
|
42 |
echo $site_password
|
|
42 |
echo "$site_password"
|
|
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
count_d7_sites() { |
46 |
find $d7_dir_sites -type d ! -name all -maxdepth 1 | wc -l
|
|
46 |
find "${d7_dir_sites}" -type d ! -name all -maxdepth 1 | wc -l
|
|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
check_arguments() { |
50 | 50 |
# ARGS: number of arguments passed to script, number of arguments required, [help text] |
51 |
if [ $1 -lt $2 ] ; then
|
|
51 |
if [ "$1" -lt "$2" ] ; then
|
|
52 | 52 |
echo "Number of arguments insuffisant." |
53 |
echo -e $3
|
|
53 |
echo -e "$3"
|
|
54 | 54 |
exit 1 |
55 | 55 |
fi |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
generate_settings_local() { |
59 | 59 |
# ARGS: site_name, site_password, d7_settings_local_template, d7_site_settings_local |
60 |
sed "s/\%\%DBUSER\%\%/$1/ ; s/\%\%DBNAME\%\%/$1/ ; s/\%\%DBPASS\%\%/$2/ ; s/\%\%SITE_NAME\%\%/$1/" < $3 > $4
|
|
60 |
sed "s/\%\%DBUSER\%\%/$1/ ; s/\%\%DBNAME\%\%/$1/ ; s/\%\%DBPASS\%\%/$2/ ; s/\%\%SITE_NAME\%\%/$1/" < "$3" > "$4"
|
|
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
give_dir() { |
64 | 64 |
# ARG: file |
65 | 65 |
# Return the abosulte directory path of a file or a dir. |
66 |
settings_location=$(realpath $1)
|
|
67 |
echo $(dirname $settings_location)
|
|
66 |
settings_location="$(realpath "$1")"
|
|
67 |
echo "$(dirname "${settings_location}")"
|
|
68 | 68 |
} |
69 | 69 |
|
70 | 70 |
work_tree_clean() { |
71 |
git_status_output=$(git status --porcelain)
|
|
72 |
if [ -z "$git_status_output" ] ; then
|
|
71 |
git_status_output="$(git status --porcelain)"
|
|
72 |
if [ -z "${git_status_output}" ] ; then
|
|
73 | 73 |
return 0 |
74 | 74 |
else |
75 | 75 |
return 1 |
... | ... | |
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
mail_unclean_work_tree() { |
80 |
cd $dir_multi_assos
|
|
81 |
git_status_output=$(git status)
|
|
82 |
echo "$git_status_output" | mail -s "$1" $email_multi_assos
|
|
80 |
cd "$dir_multi_assos"
|
|
81 |
git_status_output="$(git status)"
|
|
82 |
echo "${git_status_output}" | mail -s "$1" "${email_multi_assos}"
|
|
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
commit_if_unclean() { |
86 | 86 |
if ! work_tree_clean ; then |
87 | 87 |
commit_message="COMMIT OF UNCLEAN STUFF" |
88 |
commit -a -m "$commit_message"
|
|
89 |
mail_unclean_work_tree "[git] $commit_message"
|
|
88 |
commit -a -m "${commit_message}"
|
|
89 |
mail_unclean_work_tree "[git] ${commit_message}"
|
|
90 | 90 |
fi |
91 | 91 |
} |
92 | 92 |
|
... | ... | |
96 | 96 |
echo "Empty commit message. Nothing was commited." |
97 | 97 |
return 2 |
98 | 98 |
fi |
99 |
cd $dir_multi_assos
|
|
99 |
cd "${dir_multi_assos}"
|
|
100 | 100 |
git commit -a -m "$1" |
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
site_exists() { |
104 | 104 |
# Check if site database exists. |
105 |
if mysql --defaults-extra-file=$myassos_cnf -e "USE $1" 2>/dev/null ; then
|
|
105 |
if mysql --defaults-extra-file="${myassos_cnf}" -e "USE $1" 2>/dev/null ; then
|
|
106 | 106 |
echo "Database $1 already exits." |
107 | 107 |
return 0 |
108 | 108 |
fi |
109 | 109 |
|
110 | 110 |
# Check if site folder already exists. |
111 |
dir=$d7_dir_sites/$1
|
|
112 |
if [ -d "$dir" ] ; then
|
|
113 |
echo "Foder $dir already exists."
|
|
111 |
dir="${d7_dir_sites}/$1"
|
|
112 |
if [ -d "${dir}" ] ; then
|
|
113 |
echo "Foder ${dir} already exists."
|
|
114 | 114 |
return 0 |
115 | 115 |
fi |
116 | 116 |
return 1 |
bin/usage.sh | ||
---|---|---|
7 | 7 |
# List sites that have the project_name with the corresponding project_status.\n |
8 | 8 |
# project status: enabled or disabled" |
9 | 9 |
|
10 |
check_arguments $# 3 "$help"
|
|
10 |
check_arguments "$#" 3 "${help}"
|
|
11 | 11 |
|
12 |
if [ $1 = d7 ] ; then
|
|
13 |
cd $d7_dir_sites
|
|
12 |
if [ "$1" = d7 ] ; then
|
|
13 |
cd "${d7_dir_sites}"
|
|
14 | 14 |
else |
15 | 15 |
echo Unrecognize version. |
16 | 16 |
fi |
17 | 17 |
|
18 | 18 |
number_found=0 |
19 | 19 |
|
20 |
for dir in $(find . -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort) ; do
|
|
20 |
for dir in "$(find . -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort)" ; do
|
|
21 | 21 |
# List projects that correspond to the status. |
22 | 22 |
# Keep project_name if listed. |
23 | 23 |
# Count line result. 0 if not listed or 1 if listed. |
24 | 24 |
# Print site_dir if listed. |
25 | 25 |
|
26 |
cd $dir;
|
|
27 |
if [ 1 -le $(drush pml --status=$2 | grep $3 | wc -l) ] ; then
|
|
28 |
echo $dir;
|
|
26 |
cd "${dir}";
|
|
27 |
if [ 1 -le "$(drush pml --status="$2" | grep "$3" | wc -l)" ] ; then
|
|
28 |
echo "${dir}";
|
|
29 | 29 |
number_found=$(($number_found + 1)) |
30 | 30 |
fi |
31 | 31 |
cd - |
other-scripts/d7-sync-config.example.sh | ||
---|---|---|
1 | 1 |
# Example file for d7-sync.sh. Adapt to your own needs in d7-sync-config.sh |
2 | 2 |
|
3 |
DIR_MULTIASSOS=/home/jenselme/Documents/assos/drupal
|
|
4 |
DIR_DRUPAL7=$DIR_MULTIASSOS/drupal7
|
|
5 |
DIR_DRUPAL7_SITES=$DIR_DRUPAL7/sites
|
|
6 |
SITES_PHP=$DIR_DRUPAL7_SITES/sites.php
|
|
3 |
DIR_MULTIASSOS='/home/jenselme/Documents/assos/drupal'
|
|
4 |
DIR_DRUPAL7="${DIR_MULTIASSOS}/drupal7"
|
|
5 |
DIR_DRUPAL7_SITES="${DIR_DRUPAL7}/sites"
|
|
6 |
SITES_PHP="${DIR_DRUPAL7_SITES}/sites.php"
|
|
7 | 7 |
LOCAL_BRANCH_NAME=local |
8 | 8 |
DOMAIN=assos.local |
9 | 9 |
WEBASSOS_ID=webassos |
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
Update scritp so they respect the new convention.