Projet

Général

Profil

Paste
Télécharger (3,87 ko) Statistiques
| Branche: | Révision:

root / bin / d7-create-site.sh @ 349952e5

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 if site already exists.
10
if site_exists $d7_site_name ; then
11
    exit 1
12
fi
13

    
14
init_db=1
15
if [ "$4" = "--no-init-database" ] ; then
16
    init_db=0
17
fi
18

    
19
######## Exceptions
20
check_arguments $# 3 "$help"
21

    
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
# Backup requirements
58
mkdir $d7_dir_individual_auto_backup/$dir_site_name
59
mkdir $d7_dir_individual_manual_backup/$dir_site_name
60
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
61

    
62
# NB : ls sort by considering the 1st characters
63
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql
64
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2
65
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3
66
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4
67

    
68
# Create and grant privileges on database
69
mysql --defaults-extra-file=$myassos_cnf -e "CREATE DATABASE $d7_site_name"
70
mysql --defaults-extra-file=$myassos_cnf -e "GRANT ALL PRIVILEGES ON $d7_site_name.* TO '$d7_site_name'@'%' IDENTIFIED BY '$site_password'"
71

    
72
mkdir $d7_site_dir
73
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
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"