File: setup-config

package info (click to toggle)
b2evolution 0.9.2-3%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,972 kB
  • ctags: 5,460
  • sloc: php: 58,989; sh: 298; makefile: 36
file content (202 lines) | stat: -rw-r--r-- 6,276 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/sh -e

# This script handles the creation of a b2evolution database user and table.
# It is normally automatically run by debconf.
# Most of it is taken from the wordpress "setup-mysql" script.

usage() {
cat <<EOF
$0 [-n NAME] [-h | -d | -b] FQDN BASE_URL DB_NAME

Creates by default a b2evolution mysql configuration depending on required fully
qualified domain name(FQDN), for a blog accessible at BASE_URL. 

Options:
    -h  help
    -d  destroy and purge
    -b  backup

Example: You want your blog to be served from http://www.example.com/b2evolution
with a database named b2evolution then run:
sudo sh setup-config www.example.com http:///www.example.com/b2evolution b2evolution

EOF
}

gen_config() {
if [ -f $CONFIG_FILE ] ; then
	mv -f $CONFIG_FILE $CONFIG_FILE.back
fi

# Generate a random password
[ -x /usr/bin/makepasswd ] && \
   DB_PASSWORD=`makepasswd --chars 12 --randomseed 0`

# Write the config file for b2evolution
cat > $CONFIG_FILE << EOF
<?php
/**
 * This is b2evolution's main config file
 *
 * You need to edit this file to your settings before attempting to install the database!
 * Last significant changes to this file: version 0.9.0.2
 *
 *
 * Reminder: every line starting with # or // is a comment, multiline comments are
 *           surrounded by '/*' and '* /' (without space).
 *
 * IMPORTANT: Take special care not to erase quotes (') around text parameters
 * and semicolums (;) at the end of the lines. Otherwise you'll get some
 * "unexpected T_STRING" parse errors!
 *
 * Contributors: you should override this file by creating a file named _config_TEST.php
 * (see end of this file)
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package conf
 */


/**#@+
 * MySQL settings. Fill in your database details (check carefully or nothing will work!)
 */

define( 'DB_USER', '$NAME' );      // your MySQL username
define( 'DB_PASSWORD', '$DB_PASSWORD' );  // ...and password
define( 'DB_NAME', '$DB_NAME' );   // the name of the database
define( 'DB_HOST', 'localhost' );     // mySQL Server (typically 'localhost')
/**#@-*/


/**
 * If you want to be able to reset your existing b2evolution tables and start anew
 * you must set \$allow_evodb_reset to 1.
 *
 * NEVER LEAVE THIS SETTING ON ANYTHING ELSE THAN 0 (ZERO) ON A PRODUCTION SERVER.
 * IF THIS IS ON (1) AND YOU FORGET TO DELETE THE INSTALL FOLDER, ANYONE WOULD BE ABLE TO
 * ERASE YOUR B2EVOLUTION TABLES AND DATA BY A SINGLE CLICK!
 */
\$allow_evodb_reset = 0; // Set to 1 to enable. Do not leave this on 1 on production servers


/**
 * \$baseurl is where your blogs reside by default. CHECK THIS CAREFULLY or nothing will work.
 * It should be set to the URL where you can find the blog templates and/or the blog stub files,
 * that means index.php, blog_b.php, etc.
 * Note: Blogs can be in subdirectories of the baseurl. However, no blog should be outside
 * of there, or some tricky things may fail (e-g: pingback)
 *
 * IMPORTANT: If you want to test b2evolution on your local machine, do NOT use that machine's
 * name in the \$baseurl!
 * For example, if you machine is called HOMER, do not use http://homer/b2evolution/blogs !
 * Use http://localhost/b2evolution/blogs instead. And log in on localhost too, not homer!
 * If you don't, login cookies will not hold.
 *
 * @global string \$baseurl
 */
\$baseurl = '$BASE_URL'; // IMPORTANT: NO ENDING SLASH !!!


/**
 * Your email. Will be used in severe error messages so that users can contact you.
 * You will also receive notifications for new user registrations there.
 */
\$admin_email = 'postmaster@$DOMAIN';


/**
 * Once you have edited this file to your settings, set the following to 1 (one):
 */
\$config_is_done = 1;


# IMPORTANT: you will find more parameters in the other files of the /conf folder.
# IT IS RECOMMENDED YOU DO NOT TOUCH THOSE SETTINGS
# UNTIL YOU ARE FAMILIAR WITH THE DEFAULT INSTALLATION.
#
# It is however strongly recommended you browse through these files as soon as you've
# got your basic installation working. They'll let you customize a lot of things!

# DO NOT EDIT THE FOLLOWING!
\$debian_conf_path="/usr/share/b2evolution/conf";
@include_once "\$debian_conf_path/_config_TEST.php";    // Put testing conf in there (For testing, you can also set \$install_password here)
require_once  "\$debian_conf_path/_advanced.php";       // advanced settings
require_once  "\$debian_conf_path/_locales.php";        // locale settings
require_once  "\$debian_conf_path/_formatting.php";     // formatting settings
require_once  "\$debian_conf_path/_admin.php";          // admin settings
require_once  "\$debian_conf_path/_stats.php";          // stats/hitlogging settings
@include_once "\$debian_conf_path/_overrides_TEST.php"; // Override for testing in there
?>
EOF
}

create_db() {
# Create the database and user
# b2evolution's php install script will create the tables
mysql --defaults-extra-file=/etc/mysql/debian.cnf <<EOF
CREATE DATABASE $DB_NAME;
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
ON $DB_NAME.*
TO $NAME@localhost
IDENTIFIED BY '$DB_PASSWORD';
FLUSH PRIVILEGES;
EOF
}

backup_db() {
echo Enter root password for mysql:
BACKUPFILE=/tmp/blog-$DB_NAME.bak.sql.bz2
mysqldump --add-drop-table -u root -p $DB_NAME | bzip2 -c > $BACKUPFILE && echo Wrote $BACKUPFILE
}


destroy_db() {
mysql --defaults-extra-file=/etc/mysql/debian.cnf <<EOF
CONNECT mysql;
delete from user where user='$NAME'; 
DELETE FROM db WHERE User = '$NAME';
DELETE FROM tables_priv WHERE User = '$NAME';
DELETE FROM columns_priv WHERE User = '$NAME';
FLUSH PRIVILEGES ;
DROP DATABASE IF EXISTS $DB_NAME;
EOF
}

while getopts "n:hbd-" opt ; do
    case "$opt" in
    h) usage ; exit 0 ;;
    b) BACKUP=1 ;;
    d) DESTROY=1 ;;
    -) break ;;
    *) usage 1>&2 ; exit 1 ;;
    esac
done
shift $(($OPTIND - 1))

if [ "$(id -u)" != "0" ] ; then
  echo "You must be root to use this script."
  exit 1
fi

NAME="b2evolution"
DOMAIN="$1"
BASE_URL="$2"
DB_NAME="$3"

CONFIG_FILE="/etc/b2evolution/_config.php"

if [ $DESTROY ] ; then
destroy_db
exit 0
fi

if [ $BACKUP ] ; then
backup_db
exit 0
fi

gen_config
create_db