Project

General

Profile

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

root / bin / d7-create-site.sh @ d52a5b2f

1
#!/bin/sh
2

    
3
. /users/guest/assos/bin/scripts-config.sh
4
. scripts-config-site.sh $1
5
. 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

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

    
59
# Create settings.php
60
sed "s/\%\%DBUSER\%\%/$d7_site_name/ ; s/\%\%DBNAME\%\%/$d7_site_name/ ; s/\%\%DBPASS\%\%/$site_password/ ; s/\%\%nomsite\%\%/$d7_site_name/" < $d7_settings_template > $d7_site_settings
61

    
62
# Create symbolic link
63
cd $d7_dir
64
ln -s . $d7_site_name
65

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

    
71
# Init variables
72
d7-reset-variables.sh $d7_site_name
73

    
74
# Permissions
75
chmod -R 755 $d7_site_dir
76
chmod 400 $d7_site_settings
77

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