Project

General

Profile

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

root / bin / d7-create-site.sh @ 6d91f38e

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"
8

    
9
######## Exceptions
10
check_arguments $# 1 "$help"
11

    
12
if ! `work_tree_clean` ; then
13
    echo "Your work tree is not clean. Solve this before $0 can continue."
14
    exit 2
15
fi
16

    
17
# "-" is forbidden because it provokes database error.
18
if [ `echo $1 | grep -` ] ; then
19
    echo '"-" is forbidden in the site name'
20
    exit 1
21
fi
22

    
23
# Site name length must be lower or equal to 16 due to database limitations.
24
if [`echo $1 | wc -c` -gt 16 ] ; then
25
    echo "site name can't have more than 16 characters"
26
    exit 1
27
fi
28

    
29
###### Initialisation
30
cd $d7_dir
31
db_password=`ask_password_db $db_server $db_user`
32
site_password=`generate_password`
33
site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';"
34
site_line_aliases_drushrc_php="\$aliases['$d7_site_name'] = array('uri' => 'assos.centrale-marseille.fr/$d7_site_name', 'root' => '/users/guest/assos/htmltest/', );"
35

    
36
# Check if site database already exists.
37
if mysql -h $db_server -u $db_user -e "USE $d7_site_name" -p$db_password 2>/dev/null ; then
38
    echo "Database $d7_site_name already exists"
39
    exit 1
40
fi
41

    
42
# Check if site folder already exists.
43
if [ -d $d7_site_dir ] ; then
44
    echo "Folder $d7_site_dir already exists"
45
    exit 1
46
fi
47

    
48
###### Main
49
mkdir $d7_site_dir
50
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
51

    
52
# Backup requirements
53
mkdir $d7_dir_individual_auto_backup/$dir_site_name
54
mkdir $d7_dir_individual_manual_backup/$dir_site_name
55
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
56

    
57
# NB : ls sort by considering the 1st characters
58
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql
59
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2
60
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3
61
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4
62

    
63
# Create and grant privileges on database
64
mysql -h $db_server -u $db_user -e "CREATE DATABASE $d7_site_name" -p$db_password
65
mysql -h $db_server -u $db_user -e "GRANT ALL PRIVILEGES ON $d7_site_name.* TO '$d7_site_name'@'%' IDENTIFIED BY '$site_password'" -p$db_password
66

    
67
# Create settings.php
68
cp $d7_settings $d7_site_settings
69
generate_settings_local $d7_site_name $site_password $d7_settings_local_template $d7_site_settings_local
70

    
71
# Create symbolic link
72
cd $d7_dir
73
ln -s . $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
echo "Go to http://assos.centrale-marseille.fr/$d7_site_name/install.php to continue."
89
echo "Press enter when ready to go on."
90
read key
91

    
92
# Init variables
93
d7-reset-variables.sh $d7_site_name
94

    
95
# Permissions
96
chmod -R 755 $d7_site_dir
97
chmod 400 $d7_site_settings
98

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

    
107
commit "Creation of site: $d7_site_name"