Project

General

Profile

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

root / bin / d7-create-site.sh @ 469b9d6d

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
# "-" is forbidden because it provokes database error.
13
if [ `echo $1 | grep -` ] ; then
14
    echo '"-" is forbidden in the site name'
15
    exit 1
16
fi
17

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

    
24
###### Initialisation
25
cd $d7_dir
26
db_password=`ask_password_db $db_server $db_user`
27
site_password=`generate_password`
28

    
29
# Check if site database already exists.
30
if mysql -h $db_server -u $db_user -e "USE $d7_site_name" -p$db_password 2>/dev/null ; then
31
    echo "Database $d7_site_name already exists"
32
    exit 1
33
fi
34

    
35
# Check if site folder already exists.
36
if [ -d $d7_site_dir ] ; then
37
    echo "Folder $d7_site_dir already exists"
38
    exit 1
39
fi
40

    
41
###### Main
42
mkdir $d7_site_dir
43
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
44

    
45
# Backup requirements
46
mkdir $d7_dir_individual_auto_backup/$dir_site_name
47
mkdir $d7_dir_individual_manual_backup/$dir_site_name
48
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
49

    
50
# NB : ls sort by considering the 1st characters
51
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql
52
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2
53
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3
54
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4
55

    
56
# Create and grant privileges on database
57
mysql -h $db_server -u $db_user -e "CREATE DATABASE $d7_site_name" -p$db_password
58
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
59

    
60
# Create settings.php
61
cp $d7_settings $d7_site_settings
62
generate_settings_local $d7_site_name $site_password $d7_settings_local_template $d7_site_settings_local
63

    
64
# Create symbolic link
65
cd $d7_dir
66
ln -s . $d7_site_name
67

    
68
# Next Instructions
69
echo "Go to http://assos.centrale-marseille.fr/$d7_site_name/install.php to continue."
70
echo "Press enter when ready to go on."
71
read key
72

    
73
# Init variables
74
d7-reset-variables.sh $d7_site_name
75

    
76
# Permissions
77
chmod -R 755 $d7_site_dir
78
chmod 400 $d7_site_settings
79

    
80
# Last instructions
81
echo "Last instructions:"
82
echo "- Advice the webmaster to close account creation on the website"
83
echo "- Give the webmaster a link to the club Drupal's tutorials "
84
echo "- Create a node of type \"Site\" on default"
85
echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr"