1
|
#!/bin/sh
|
2
|
|
3
|
. /home/assos/bin/scripts-config.sh
|
4
|
. /home/assos/bin/scripts-config-site.sh $1
|
5
|
. /home/assos/bin/scripts-utils.sh
|
6
|
|
7
|
help="# ARGS: site_name site_mail admin_password [--no-init-database]"
|
8
|
|
9
|
check_arguments $# 3 "$help"
|
10
|
|
11
|
# Check if site already exists.
|
12
|
if site_exists $d7_site_name ; then
|
13
|
exit 1
|
14
|
fi
|
15
|
|
16
|
init_db=1
|
17
|
if [ "$4" = "--no-init-database" ] ; then
|
18
|
init_db=0
|
19
|
fi
|
20
|
|
21
|
######## Exceptions
|
22
|
echo "Checking if work tree is clean (may take a while)"
|
23
|
if ! work_tree_clean ; then
|
24
|
echo "Your work tree is not clean. Solve this before $0 can continue."
|
25
|
exit 2
|
26
|
fi
|
27
|
|
28
|
# "-" is forbidden because it provokes database error.
|
29
|
if [ $(echo $1 | grep -) ] ; then
|
30
|
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
|
if [ $(echo $1 | wc -c) -gt 16 ] ; then
|
36
|
echo "site name can't have more than 16 characters"
|
37
|
exit 1
|
38
|
fi
|
39
|
|
40
|
# 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
|
###### Initialisation
|
47
|
cd $d7_dir
|
48
|
site_password=$(generate_password)
|
49
|
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
|
50
|
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/home/assos/drupal7/', );"
|
51
|
# NB: site_name is initialised in script-config-site.sh
|
52
|
site_mail=$2
|
53
|
admin_password=$3
|
54
|
|
55
|
|
56
|
###### Main
|
57
|
mkdir $d7_site_dir
|
58
|
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
|
59
|
|
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")
|
64
|
|
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
|
70
|
|
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'"
|
74
|
|
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
|
78
|
|
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
|
81
|
|
82
|
# Create symbolic link
|
83
|
cd $d7_dir
|
84
|
ln -s . $d7_site_name
|
85
|
git add $d7_site_name
|
86
|
|
87
|
# Update sites.php
|
88
|
chmod +w $sites_php
|
89
|
echo $site_line_sites_php >> $sites_php
|
90
|
chmod 400 $sites_php
|
91
|
|
92
|
### Update aliases.drushrc.php
|
93
|
# For site
|
94
|
echo $site_line_aliases_drushrc_php >> $aliases_drushrc_php
|
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
|
98
|
|
99
|
commit "Creation of site: $d7_site_name"
|
100
|
|
101
|
# Next Instructions
|
102
|
if [ $init_db -eq 0 ] ; then
|
103
|
exit 0
|
104
|
fi
|
105
|
|
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
|
echo -e "- If line to add to sites.php differs from the line below, please correct it\n\t$site_line_sites_php"
|