1 |
d52a5b2f
|
jenselme
|
#!/bin/sh
|
2 |
|
|
|
3 |
06e9d071
|
Assos Assos
|
. /home/assos/bin/scripts-config.sh
|
4 |
|
|
. /home/assos/bin/scripts-config-site.sh $1
|
5 |
|
|
. /home/assos/bin/scripts-utils.sh
|
6 |
d52a5b2f
|
jenselme
|
|
7 |
07feb979
|
Julien Enselme
|
help="# ARGS: site_name site_mail admin_password [--no-init-database]"
|
8 |
a3d7801f
|
Julien Enselme
|
|
9 |
5adc00e9
|
Julien Enselme
|
# Check if site already exists.
|
10 |
4ed597de
|
Julien Enselme
|
if site_exists $d7_site_name ; then
|
11 |
5adc00e9
|
Julien Enselme
|
exit 1
|
12 |
|
|
fi
|
13 |
|
|
|
14 |
4ed597de
|
Julien Enselme
|
init_db=1
|
15 |
07feb979
|
Julien Enselme
|
if [ "$4" = "--no-init-database" ] ; then
|
16 |
4ed597de
|
Julien Enselme
|
init_db=0
|
17 |
a3d7801f
|
Julien Enselme
|
fi
|
18 |
d52a5b2f
|
jenselme
|
|
19 |
|
|
######## Exceptions
|
20 |
07feb979
|
Julien Enselme
|
check_arguments $# 3 "$help"
|
21 |
d52a5b2f
|
jenselme
|
|
22 |
64ad485a
|
Julien Enselme
|
echo "Checking if work tree is clean (may take a while)"
|
23 |
4ed597de
|
Julien Enselme
|
if ! work_tree_clean ; then
|
24 |
1c1c5a42
|
Julien Enselme
|
echo "Your work tree is not clean. Solve this before $0 can continue."
|
25 |
|
|
exit 2
|
26 |
|
|
fi
|
27 |
|
|
|
28 |
d52a5b2f
|
jenselme
|
# "-" is forbidden because it provokes database error.
|
29 |
683f57f9
|
Julien Enselme
|
if [ $(echo $1 | grep -) ] ; then
|
30 |
d52a5b2f
|
jenselme
|
echo '"-" is forbidden in the site name'
|
31 |
|
|
exit 1
|
32 |
|
|
fi
|
33 |
|
|
|
34 |
|
|
# Site name length must be lower or equal to 16 due to database limitations.
|
35 |
683f57f9
|
Julien Enselme
|
if [ $(echo $1 | wc -c) -gt 16 ] ; then
|
36 |
d52a5b2f
|
jenselme
|
echo "site name can't have more than 16 characters"
|
37 |
|
|
exit 1
|
38 |
|
|
fi
|
39 |
|
|
|
40 |
07feb979
|
Julien Enselme
|
# drush site-install needs the translation file
|
41 |
|
|
if [ ! -f $translation_fr ] ; then
|
42 |
|
|
echo "The translation file $translation_fr does not exist"
|
43 |
|
|
exit 1
|
44 |
|
|
fi
|
45 |
|
|
|
46 |
d52a5b2f
|
jenselme
|
###### Initialisation
|
47 |
|
|
cd $d7_dir
|
48 |
683f57f9
|
Julien Enselme
|
site_password=$(generate_password)
|
49 |
ad6711c7
|
Julien Enselme
|
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
|
50 |
06e9d071
|
Assos Assos
|
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/home/assos/drupal7/', );"
|
51 |
07feb979
|
Julien Enselme
|
# NB: site_name is initialised in script-config-site.sh
|
52 |
|
|
site_mail=$2
|
53 |
|
|
admin_password=$3
|
54 |
d52a5b2f
|
jenselme
|
|
55 |
|
|
|
56 |
|
|
###### Main
|
57 |
f92204ef
|
Julien Enselme
|
mkdir $d7_site_dir
|
58 |
|
|
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
|
59 |
|
|
|
60 |
d52a5b2f
|
jenselme
|
# Backup requirements
|
61 |
|
|
mkdir $d7_dir_individual_auto_backup/$dir_site_name
|
62 |
|
|
mkdir $d7_dir_individual_manual_backup/$dir_site_name
|
63 |
683f57f9
|
Julien Enselme
|
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
64 |
d52a5b2f
|
jenselme
|
|
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 |
ddeedc17
|
Julien Enselme
|
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4
|
70 |
d52a5b2f
|
jenselme
|
|
71 |
|
|
# Create and grant privileges on database
|
72 |
e0225b3a
|
Julien Enselme
|
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 |
d52a5b2f
|
jenselme
|
|
75 |
07feb979
|
Julien Enselme
|
# Create settings.local.php
|
76 |
469b9d6d
|
Julien Enselme
|
cp $d7_settings $d7_site_settings
|
77 |
|
|
generate_settings_local $d7_site_name $site_password $d7_settings_local_template $d7_site_settings_local
|
78 |
d52a5b2f
|
jenselme
|
|
79 |
07feb979
|
Julien Enselme
|
# 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
|
81 |
|
|
|
82 |
d52a5b2f
|
jenselme
|
# Create symbolic link
|
83 |
|
|
cd $d7_dir
|
84 |
|
|
ln -s . $d7_site_name
|
85 |
92b0ba80
|
Julien Enselme
|
git add $d7_site_name
|
86 |
d52a5b2f
|
jenselme
|
|
87 |
593e9a63
|
Julien Enselme
|
# Update sites.php
|
88 |
364f9fdd
|
Julien Enselme
|
chmod +w $sites_php
|
89 |
ad6711c7
|
Julien Enselme
|
echo $site_line_sites_php >> $sites_php
|
90 |
364f9fdd
|
Julien Enselme
|
chmod 400 $sites_php
|
91 |
593e9a63
|
Julien Enselme
|
|
92 |
0e4152d9
|
Julien Enselme
|
### Update aliases.drushrc.php
|
93 |
|
|
# For site
|
94 |
|
|
echo $site_line_aliases_drushrc_php >> $aliases_drushrc_php
|
95 |
|
|
# @d7
|
96 |
364f9fdd
|
Julien Enselme
|
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 |
0e4152d9
|
Julien Enselme
|
|
99 |
3d719e63
|
Julien Enselme
|
commit "Creation of site: $d7_site_name"
|
100 |
|
|
|
101 |
d52a5b2f
|
jenselme
|
# Next Instructions
|
102 |
a3d7801f
|
Julien Enselme
|
if [ $init_db -eq 0 ] ; then
|
103 |
|
|
exit 0
|
104 |
|
|
fi
|
105 |
d52a5b2f
|
jenselme
|
|
106 |
|
|
# Init variables
|
107 |
|
|
d7-reset-variables.sh $d7_site_name
|
108 |
|
|
|
109 |
|
|
# Permissions
|
110 |
|
|
chmod -R 755 $d7_site_dir
|
111 |
|
|
chmod 400 $d7_site_settings
|
112 |
|
|
|
113 |
|
|
# Last instructions
|
114 |
|
|
echo "Last instructions:"
|
115 |
|
|
echo "- Advice the webmaster to close account creation on the website"
|
116 |
|
|
echo "- Give the webmaster a link to the club Drupal's tutorials "
|
117 |
|
|
echo "- Create a node of type \"Site\" on default"
|
118 |
|
|
echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr"
|
119 |
ad6711c7
|
Julien Enselme
|
echo -e "- If line to add to sites.php differs from the line below, please correct it\n\t$site_line_sites_php" |