Project

General

Profile

Paste
Download (3.51 KB) Statistics
| Branch: | Revision:

root / bin / d7-create-site.sh @ 06e9d071

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 [--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 [ "$2" = "--no-init-database" ] ; then
16
    init_db=0
17
fi
18

    
19
######## Exceptions
20
check_arguments $# 1 "$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
###### Initialisation
41
cd $d7_dir
42
site_password=`generate_password`
43
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
44
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/home/assos/drupal7/', );"
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
commit "Creation of site: $d7_site_name"
88

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

    
97
# Init variables
98
d7-reset-variables.sh $d7_site_name
99

    
100
# Permissions
101
chmod -R 755 $d7_site_dir
102
chmod 400 $d7_site_settings
103

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