Projet

Général

Profil

Paste
Télécharger (5,16 ko) Statistiques
| Branche: | Révision:

root / bin / d7-create-site.sh @ a6e869e4

1
#!/bin/sh
2

    
3
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

    
50

    
51
. /home/assos/bin/scripts-config.sh
52
param="${site_name}" . /home/assos/bin/scripts-config-site.sh
53
. /home/assos/bin/scripts-utils.sh
54

    
55
# Check if site already exists.
56
if site_exists "${d7_site_name}" ; then
57
    exit 1
58
fi
59

    
60
######## Exceptions
61
echo "Checking if work tree is clean (may take a while)"
62
if ! work_tree_clean ; then
63
    echo "Your work tree is not clean. Solve this before $0 can continue."
64
    exit 2
65
fi
66

    
67
# "-" is forbidden because it provokes database error.
68
if [ $(echo "${site_name}" | grep -) ] ; then
69
    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
if [ $(echo "${site_name}" | wc -c) -gt 16 ] ; then
75
    echo "site name can't have more than 16 characters"
76
    exit 1
77
fi
78

    
79
# drush site-install needs the translation file
80
if [ ! -f "${translations_fr}" ] ; then
81
    echo "The translation file ${translations_fr} does not exist"
82
    exit 1
83
fi
84

    
85
###### Initialisation
86
cd "${d7_dir}"
87
site_password=$(generate_password)
88
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
89
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/home/assos/drupal7/', );"
90
# NB: site_name is initialised in script-config-site.sh
91
admin_password="${admin_password}"
92

    
93

    
94
###### Main
95
mkdir "${d7_site_dir}"
96
dir_site_name="assos.centrale-marseille.fr.${d7_site_name}"
97

    
98
# Backup requirements
99
mkdir "${d7_dir_individual_auto_backup}/${dir_site_name}"
100
mkdir "${d7_dir_individual_manual_backup}/${dir_site_name}"
101
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
102

    
103
# NB : ls sort by considering the 1st characters
104
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
touch "${d7_dir_individual_auto_backup}/${dir_site_name}/${current_date}.${dir_site_name}.sql4"
108

    
109
# Create and grant privileges on database
110
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

    
113
# Create settings.local.php
114
cp "${d7_settings}" "${d7_site_settings}"
115
generate_settings_local "${d7_site_name}" "${site_password}" "${d7_settings_local_template}" "${d7_site_settings_local}"
116

    
117
# Install the site
118
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

    
120
# Create symbolic link
121
cd "${d7_dir}"
122
ln -s . "${d7_site_name}"
123
git add "${d7_site_name}"
124

    
125
# Update sites.php
126
chmod +w "${sites_php}"
127
echo "${site_line_sites_php}" >> "${sites_php}"
128
chmod 400 "${sites_php}"
129

    
130
### Update aliases.drushrc.php
131
# For site
132
echo "${site_line_aliases_drushrc_php}" >> "${aliases_drushrc_php}"
133
# @d7
134
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

    
137
### Update nginx_sites_map
138
d7-generate-nginx-map.sh
139
# Reload nginx
140
sudo service nginx restart
141

    
142
commit "Creation of site: ${d7_site_name}"
143

    
144
# Next Instructions
145
if [ "${init_db}" -eq 0 ] ; then
146
    exit 0
147
fi
148

    
149
# Init variables
150
d7-reset-variables.sh "${d7_site_name}"
151

    
152
# Permissions
153
chmod -R u=rwX,go=rX "${d7_site_dir}"
154
chmod 400 "${d7_site_settings}"
155

    
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
echo -e "- If line to add to sites.php differs from the line below, please correct it\n\t$site_line_sites_php"