Révision 15ed27d8
Ajouté par Julien Enselme il y a plus de 9 ans
bin/d7-create-site.sh | ||
---|---|---|
1 | 1 |
#!/bin/sh |
2 | 2 |
|
3 |
. /home/assos/bin/scripts-config.sh |
|
4 |
. /home/assos/bin/scripts-config-site.sh "$1" |
|
5 |
. /home/assos/bin/scripts-utils.sh |
|
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 |
|
6 | 49 |
|
7 |
help="# ARGS: site_name site_mail admin_password [--no-init-database]" |
|
8 | 50 |
|
9 |
check_arguments "$#" 3 "${help}" |
|
51 |
. /home/assos/bin/scripts-config.sh |
|
52 |
. /home/assos/bin/scripts-config-site.sh "${site_name}" |
|
53 |
. /home/assos/bin/scripts-utils.sh |
|
10 | 54 |
|
11 | 55 |
# Check if site already exists. |
12 | 56 |
if site_exists "${d7_site_name}" ; then |
13 | 57 |
exit 1 |
14 | 58 |
fi |
15 | 59 |
|
16 |
init_db=1 |
|
17 |
if [ "$4" = "--no-init-database" ] ; then |
|
18 |
init_db=0 |
|
19 |
fi |
|
20 |
|
|
21 | 60 |
######## Exceptions |
22 | 61 |
echo "Checking if work tree is clean (may take a while)" |
23 | 62 |
if ! work_tree_clean ; then |
... | ... | |
26 | 65 |
fi |
27 | 66 |
|
28 | 67 |
# "-" is forbidden because it provokes database error. |
29 |
if [ $(echo "$1" | grep -) ] ; then
|
|
68 |
if [ $(echo "${site_name}" | grep -) ] ; then
|
|
30 | 69 |
echo '"-" is forbidden in the site name' |
31 | 70 |
exit 1 |
32 | 71 |
fi |
33 | 72 |
|
34 | 73 |
# Site name length must be lower or equal to 16 due to database limitations. |
35 |
if [ $(echo "$1" | wc -c) -gt 16 ] ; then
|
|
74 |
if [ $(echo "${site_name}" | wc -c) -gt 16 ] ; then
|
|
36 | 75 |
echo "site name can't have more than 16 characters" |
37 | 76 |
exit 1 |
38 | 77 |
fi |
... | ... | |
49 | 88 |
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';" |
50 | 89 |
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/home/assos/drupal7/', );" |
51 | 90 |
# NB: site_name is initialised in script-config-site.sh |
52 |
site_mail="$2" |
|
53 |
admin_password="$3" |
|
91 |
admin_password="${admin_password}" |
|
54 | 92 |
|
55 | 93 |
|
56 | 94 |
###### Main |
... | ... | |
77 | 115 |
generate_settings_local "${d7_site_name}" "${site_password}" "${d7_settings_local_template}" "${d7_site_settings_local}" |
78 | 116 |
|
79 | 117 |
# 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}"
|
|
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}"
|
|
81 | 119 |
|
82 | 120 |
# Create symbolic link |
83 | 121 |
cd "${d7_dir}" |
Formats disponibles : Unified diff
Use getopts to print help and to parse script arguments.