1
|
#!/bin/sh
|
2
|
|
3
|
. /users/guest/assos/bin/scripts-config.sh
|
4
|
. /users/guest/assos/bin/scripts-config-site.sh $1
|
5
|
. /users/guest/assos/bin/scripts-utils.sh
|
6
|
|
7
|
help="# ARGS: site name"
|
8
|
|
9
|
######## Exceptions
|
10
|
check_arguments $# 1 "$help"
|
11
|
|
12
|
if ! `work_tree_clean` ; then
|
13
|
echo "Your work tree is not clean. Solve this before $0 can continue."
|
14
|
exit 2
|
15
|
fi
|
16
|
|
17
|
# "-" is forbidden because it provokes database error.
|
18
|
if [ `echo $1 | grep -` ] ; then
|
19
|
echo '"-" is forbidden in the site name'
|
20
|
exit 1
|
21
|
fi
|
22
|
|
23
|
# Site name length must be lower or equal to 16 due to database limitations.
|
24
|
if [`echo $1 | wc -c` -gt 16 ] ; then
|
25
|
echo "site name can't have more than 16 characters"
|
26
|
exit 1
|
27
|
fi
|
28
|
|
29
|
###### Initialisation
|
30
|
cd $d7_dir
|
31
|
site_password=`generate_password`
|
32
|
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
|
33
|
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/users/guest/assos/drupal7/', );"
|
34
|
|
35
|
# Check if site database already exists.
|
36
|
if mysql --defaults-extra-file=$myassos_cnf -e "USE $d7_site_name" 2>/dev/null ; then
|
37
|
echo "Database $d7_site_name already exists"
|
38
|
exit 1
|
39
|
fi
|
40
|
|
41
|
# Check if site folder already exists.
|
42
|
if [ -d $d7_site_dir ] ; then
|
43
|
echo "Folder $d7_site_dir already exists"
|
44
|
exit 1
|
45
|
fi
|
46
|
|
47
|
###### Main
|
48
|
mkdir $d7_site_dir
|
49
|
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
|
50
|
|
51
|
# Backup requirements
|
52
|
mkdir $d7_dir_individual_auto_backup/$dir_site_name
|
53
|
mkdir $d7_dir_individual_manual_backup/$dir_site_name
|
54
|
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
|
55
|
|
56
|
# NB : ls sort by considering the 1st characters
|
57
|
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql
|
58
|
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2
|
59
|
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3
|
60
|
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4
|
61
|
|
62
|
# Create and grant privileges on database
|
63
|
mysql --defaults-extra-file=$myassos_cnf -e "CREATE DATABASE $d7_site_name"
|
64
|
mysql --defaults-extra-file=$myassos_cnf -e "GRANT ALL PRIVILEGES ON $d7_site_name.* TO '$d7_site_name'@'%' IDENTIFIED BY '$site_password'"
|
65
|
|
66
|
# Create settings.php
|
67
|
cp $d7_settings $d7_site_settings
|
68
|
generate_settings_local $d7_site_name $site_password $d7_settings_local_template $d7_site_settings_local
|
69
|
|
70
|
# Create symbolic link
|
71
|
cd $d7_dir
|
72
|
ln -s . $d7_site_name
|
73
|
|
74
|
# Update sites.php
|
75
|
chmod +w $sites_php
|
76
|
echo $site_line_sites_php >> $sites_php
|
77
|
chmod 400 $sites_php
|
78
|
|
79
|
### Update aliases.drushrc.php
|
80
|
# For site
|
81
|
echo $site_line_aliases_drushrc_php >> $aliases_drushrc_php
|
82
|
# @d7
|
83
|
sed s/"'site-list' => array("/"'site-list' => array(%'assos.centrale-marseille.fr\/$d7_site_name',"/ < $aliases_drushrc_php | tr '%' '\n ' > $dir_tmp/aliases.tmp
|
84
|
mv $dir_tmp/aliases.tmp $aliases_drushrc_php
|
85
|
|
86
|
# Next Instructions
|
87
|
echo "Go to http://assos.centrale-marseille.fr/$d7_site_name/install.php to continue."
|
88
|
echo "Press enter when ready to go on."
|
89
|
read key
|
90
|
|
91
|
# Init variables
|
92
|
d7-reset-variables.sh $d7_site_name
|
93
|
|
94
|
# Permissions
|
95
|
chmod -R 755 $d7_site_dir
|
96
|
chmod 400 $d7_site_settings
|
97
|
|
98
|
# Last instructions
|
99
|
echo "Last instructions:"
|
100
|
echo "- Advice the webmaster to close account creation on the website"
|
101
|
echo "- Give the webmaster a link to the club Drupal's tutorials "
|
102
|
echo "- Create a node of type \"Site\" on default"
|
103
|
echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr"
|
104
|
echo -e "- If line to add to sites.php differs from the line below, please correct it\n\t$site_line_sites_php"
|
105
|
|
106
|
commit "Creation of site: $d7_site_name"
|