1 |
d52a5b2f
|
jenselme
|
#!/bin/sh
|
2 |
|
|
|
3 |
15ed27d8
|
Julien Enselme
|
usage() {
|
4 |
|
|
printf "d7-create-site.sh -s site_name -m site_mail -p admin_password [-l admin_login] [-d]\n"
|
5 |
|
|
printf "Options:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n"\
|
6 |
|
|
"-s The name of the site"\
|
7 |
|
|
"-m The mail of the site"\
|
8 |
|
|
"-p The password for the administrator (must be changed)"\
|
9 |
|
|
"-l The login of the admin. Optional, set to admin by default"\
|
10 |
|
|
"-d If passed, the database is not setup."
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
site_name=''
|
14 |
|
|
site_mail=''
|
15 |
|
|
admin_password=''
|
16 |
|
|
admin_login=''
|
17 |
|
|
init_db=true
|
18 |
|
|
|
19 |
|
|
while getopts "hs:m:p:l:d" opt; do
|
20 |
|
|
case "${opt}" in
|
21 |
|
|
h)
|
22 |
|
|
usage; exit 0;;
|
23 |
|
|
s)
|
24 |
|
|
site_name="${OPTARG}";;
|
25 |
|
|
m)
|
26 |
|
|
site_mail="${OPTARG}";;
|
27 |
|
|
p)
|
28 |
|
|
admin_password="${OPTARG}";;
|
29 |
|
|
l)
|
30 |
|
|
admin_login="${OPTARG}";;
|
31 |
|
|
d)
|
32 |
|
|
init_db=false;;
|
33 |
|
|
:)
|
34 |
|
|
echo "Option -$OPTARG requires an argument." >&2
|
35 |
|
|
usage >&2; exit 1;;
|
36 |
|
|
\?)
|
37 |
|
|
usage >&2; exit 1;;
|
38 |
|
|
esac
|
39 |
|
|
done
|
40 |
|
|
shift $((OPTIND-1))
|
41 |
|
|
admin_login=${admin_login:-'admin'}
|
42 |
|
|
|
43 |
|
|
# Check that all required parameters are there
|
44 |
|
|
if [ -z "${site_name}" ] || [ -z "${site_mail}" ] || [ -z "${admin_password}" ]; then
|
45 |
|
|
echo "At least a required parameter is missing." >&2
|
46 |
|
|
usage >&2
|
47 |
|
|
exit 1
|
48 |
|
|
fi
|
49 |
d52a5b2f
|
jenselme
|
|
50 |
a3d7801f
|
Julien Enselme
|
|
51 |
15ed27d8
|
Julien Enselme
|
. /home/assos/bin/scripts-config.sh
|
52 |
a629a580
|
Benjamin LUCE
|
param="${site_name}" . /home/assos/bin/scripts-config-site.sh
|
53 |
15ed27d8
|
Julien Enselme
|
. /home/assos/bin/scripts-utils.sh
|
54 |
d4221f52
|
Julien Enselme
|
|
55 |
5adc00e9
|
Julien Enselme
|
# Check if site already exists.
|
56 |
3e9236bd
|
Julien Enselme
|
if site_exists "${d7_site_name}" ; then
|
57 |
5adc00e9
|
Julien Enselme
|
exit 1
|
58 |
|
|
fi
|
59 |
|
|
|
60 |
d52a5b2f
|
jenselme
|
######## Exceptions
|
61 |
64ad485a
|
Julien Enselme
|
echo "Checking if work tree is clean (may take a while)"
|
62 |
4ed597de
|
Julien Enselme
|
if ! work_tree_clean ; then
|
63 |
1c1c5a42
|
Julien Enselme
|
echo "Your work tree is not clean. Solve this before $0 can continue."
|
64 |
|
|
exit 2
|
65 |
|
|
fi
|
66 |
|
|
|
67 |
d52a5b2f
|
jenselme
|
# "-" is forbidden because it provokes database error.
|
68 |
15ed27d8
|
Julien Enselme
|
if [ $(echo "${site_name}" | grep -) ] ; then
|
69 |
d52a5b2f
|
jenselme
|
echo '"-" is forbidden in the site name'
|
70 |
|
|
exit 1
|
71 |
|
|
fi
|
72 |
|
|
|
73 |
|
|
# Site name length must be lower or equal to 16 due to database limitations.
|
74 |
15ed27d8
|
Julien Enselme
|
if [ $(echo "${site_name}" | wc -c) -gt 16 ] ; then
|
75 |
d52a5b2f
|
jenselme
|
echo "site name can't have more than 16 characters"
|
76 |
|
|
exit 1
|
77 |
|
|
fi
|
78 |
|
|
|
79 |
07feb979
|
Julien Enselme
|
# drush site-install needs the translation file
|
80 |
1062c26c
|
Julien Enselme
|
if [ ! -f "${translations_fr}" ] ; then
|
81 |
|
|
echo "The translation file ${translations_fr} does not exist"
|
82 |
07feb979
|
Julien Enselme
|
exit 1
|
83 |
|
|
fi
|
84 |
|
|
|
85 |
d52a5b2f
|
jenselme
|
###### Initialisation
|
86 |
3e9236bd
|
Julien Enselme
|
cd "${d7_dir}"
|
87 |
eac776e8
|
Julien Enselme
|
site_password=$(generate_password)
|
88 |
ad6711c7
|
Julien Enselme
|
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
|
89 |
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/', );"
|
90 |
07feb979
|
Julien Enselme
|
# NB: site_name is initialised in script-config-site.sh
|
91 |
15ed27d8
|
Julien Enselme
|
admin_password="${admin_password}"
|
92 |
d52a5b2f
|
jenselme
|
|
93 |
|
|
|
94 |
|
|
###### Main
|
95 |
3e9236bd
|
Julien Enselme
|
mkdir "${d7_site_dir}"
|
96 |
|
|
dir_site_name="assos.centrale-marseille.fr.${d7_site_name}"
|
97 |
f92204ef
|
Julien Enselme
|
|
98 |
d52a5b2f
|
jenselme
|
# Backup requirements
|
99 |
3e9236bd
|
Julien Enselme
|
mkdir "${d7_dir_individual_auto_backup}/${dir_site_name}"
|
100 |
|
|
mkdir "${d7_dir_individual_manual_backup}/${dir_site_name}"
|
101 |
eac776e8
|
Julien Enselme
|
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
|
102 |
d52a5b2f
|
jenselme
|
|
103 |
|
|
# NB : ls sort by considering the 1st characters
|
104 |
3e9236bd
|
Julien Enselme
|
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql"
|
105 |
|
|
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql2"
|
106 |
|
|
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql3"
|
107 |
73a967a6
|
Julien Enselme
|
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql4"
|
108 |
d52a5b2f
|
jenselme
|
|
109 |
|
|
# Create and grant privileges on database
|
110 |
3e9236bd
|
Julien Enselme
|
mysql --defaults-extra-file="${myassos_cnf}" -e "CREATE DATABASE ${d7_site_name}"
|
111 |
|
|
mysql --defaults-extra-file="${myassos_cnf}" -e "GRANT ALL PRIVILEGES ON ${d7_site_name}.* TO '${d7_site_name}'@'%' IDENTIFIED BY '${site_password}'"
|
112 |
d52a5b2f
|
jenselme
|
|
113 |
07feb979
|
Julien Enselme
|
# Create settings.local.php
|
114 |
3e9236bd
|
Julien Enselme
|
cp "${d7_settings}" "${d7_site_settings}"
|
115 |
|
|
generate_settings_local "${d7_site_name}" "${site_password}" "${d7_settings_local_template}" "${d7_site_settings_local}"
|
116 |
d52a5b2f
|
jenselme
|
|
117 |
07feb979
|
Julien Enselme
|
# Install the site
|
118 |
15ed27d8
|
Julien Enselme
|
drush site-install -y standard --account-mail="${site_mail}" --account-name="${admin_login}" --account-pass="${admin_password}" --locale=fr --site-mail="${site_mail}" --site-name="${d7_site_name}" --sites-subdir="${dir_site_name}"
|
119 |
07feb979
|
Julien Enselme
|
|
120 |
d52a5b2f
|
jenselme
|
# Create symbolic link
|
121 |
3e9236bd
|
Julien Enselme
|
cd "${d7_dir}"
|
122 |
|
|
ln -s . "${d7_site_name}"
|
123 |
|
|
git add "${d7_site_name}"
|
124 |
d52a5b2f
|
jenselme
|
|
125 |
593e9a63
|
Julien Enselme
|
# Update sites.php
|
126 |
3e9236bd
|
Julien Enselme
|
chmod +w "${sites_php}"
|
127 |
|
|
echo "${site_line_sites_php}" >> "${sites_php}"
|
128 |
|
|
chmod 400 "${sites_php}"
|
129 |
593e9a63
|
Julien Enselme
|
|
130 |
0e4152d9
|
Julien Enselme
|
### Update aliases.drushrc.php
|
131 |
|
|
# For site
|
132 |
3e9236bd
|
Julien Enselme
|
echo "${site_line_aliases_drushrc_php}" >> "${aliases_drushrc_php}"
|
133 |
0e4152d9
|
Julien Enselme
|
# @d7
|
134 |
3e9236bd
|
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"
|
135 |
|
|
mv "${dir_tmp}/aliases.tmp" "${aliases_drushrc_php}"
|
136 |
0e4152d9
|
Julien Enselme
|
|
137 |
bf546089
|
Julien Enselme
|
### Update nginx_sites_map
|
138 |
5fbc698e
|
Julien Enselme
|
d7-generate-nginx-map.sh
|
139 |
73a967a6
|
Julien Enselme
|
# Reload nginx
|
140 |
be524722
|
Julien Enselme
|
sudo service nginx restart
|
141 |
bf546089
|
Julien Enselme
|
|
142 |
3e9236bd
|
Julien Enselme
|
commit "Creation of site: ${d7_site_name}"
|
143 |
3d719e63
|
Julien Enselme
|
|
144 |
d52a5b2f
|
jenselme
|
# Next Instructions
|
145 |
3e9236bd
|
Julien Enselme
|
if [ "${init_db}" -eq 0 ] ; then
|
146 |
a3d7801f
|
Julien Enselme
|
exit 0
|
147 |
|
|
fi
|
148 |
d52a5b2f
|
jenselme
|
|
149 |
|
|
# Init variables
|
150 |
3e9236bd
|
Julien Enselme
|
d7-reset-variables.sh "${d7_site_name}"
|
151 |
d52a5b2f
|
jenselme
|
|
152 |
|
|
# Permissions
|
153 |
35e0bbf4
|
Julien Enselme
|
chmod -R u=rwX,go=rX "${d7_site_dir}"
|
154 |
3e9236bd
|
Julien Enselme
|
chmod 400 "${d7_site_settings}"
|
155 |
d52a5b2f
|
jenselme
|
|
156 |
|
|
# Last instructions
|
157 |
|
|
echo "Last instructions:"
|
158 |
|
|
echo "- Advice the webmaster to close account creation on the website"
|
159 |
|
|
echo "- Give the webmaster a link to the club Drupal's tutorials "
|
160 |
|
|
echo "- Create a node of type \"Site\" on default"
|
161 |
|
|
echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr"
|
162 |
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" |