Projet

Général

Profil

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

root / bin / d7-create-site.sh @ 40dfeef4

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 [--no-init-database]"
8

    
9
init_db=0
10
if [ $2 = "--no-init-database" ] ; then
11
    init_db=1
12
fi
13

    
14
######## Exceptions
15
check_arguments $# 1 "$help"
16

    
17
echo "Checking if work tree is clean (may take a while)"
18
if ! `work_tree_clean` ; then
19
    echo "Your work tree is not clean. Solve this before $0 can continue."
20
    exit 2
21
fi
22

    
23
# "-" is forbidden because it provokes database error.
24
if [ `echo $1 | grep -` ] ; then
25
    echo '"-" is forbidden in the site name'
26
    exit 1
27
fi
28

    
29
# Site name length must be lower or equal to 16 due to database limitations.
30
if [`echo $1 | wc -c` -gt 16 ] ; then
31
    echo "site name can't have more than 16 characters"
32
    exit 1
33
fi
34

    
35
###### Initialisation
36
cd $d7_dir
37
site_password=`generate_password`
38
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
39
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/users/guest/assos/drupal7/', );"
40

    
41
# Check if site already exists.
42
if site_exists $d7_site_name ; then
43
    exit 1
44
fi
45

    
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
git add $d7_site_name
74

    
75
# Update sites.php
76
chmod +w $sites_php
77
echo $site_line_sites_php >> $sites_php
78
chmod 400 $sites_php
79

    
80
### Update aliases.drushrc.php
81
# For site
82
echo $site_line_aliases_drushrc_php >> $aliases_drushrc_php
83
# @d7
84
sed s/"'site-list' => array("/"'site-list' => array(%'assos.centrale-marseille.fr\/$d7_site_name',"/ < $aliases_drushrc_php | tr '%' '\n    ' > $dir_tmp/aliases.tmp
85
mv $dir_tmp/aliases.tmp $aliases_drushrc_php
86

    
87
# Next Instructions
88
if [ $init_db -eq 0 ] ; then
89
    exit 0
90
fi
91
echo "Go to https://assos.centrale-marseille.fr/$d7_site_name/install.php to continue."
92
echo "Press enter when ready to go on."
93
read key
94

    
95
# Init variables
96
d7-reset-variables.sh $d7_site_name
97

    
98
# Permissions
99
chmod -R 755 $d7_site_dir
100
chmod 400 $d7_site_settings
101

    
102
# Last instructions
103
echo "Last instructions:"
104
echo "- Advice the webmaster to close account creation on the website"
105
echo "- Give the webmaster a link to the club Drupal's tutorials "
106
echo "- Create a node of type \"Site\" on default"
107
echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr"
108
echo -e "- If line to add to sites.php differs from the line below, please correct it\n\t$site_line_sites_php"
109

    
110
commit "Creation of site: $d7_site_name"