3
/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* $Id: setup.in,v 1.1.1.1 2006/03/27 12:40:05 exodusd Exp $
22
constant cvs_version="$Id: setup.in,v 1.1.1.1 2006/03/27 12:40:05 exodusd Exp $";
24
string brand_name = "steam";
25
string config_dir = "/etc/steam";
26
string log_dir = "/var/log/steam";
27
string steam_dir = "/usr/share/steam";
28
string install_dir = "@install_dir@";
30
int replace_db_string_in_file ( string filename, string db_access_string )
33
string config_text = Stdio.read_file( filename );
34
if ( !stringp(config_text) ) return 0;
35
array config_lines = config_text / "\n";
36
for ( int i=0; i<sizeof(config_lines); i++ )
38
string line = config_lines[i];
39
if ( stringp(line) && sizeof(line)>=9 && line[0..8]=="database=" )
41
config_lines[i] = "database=" + db_access_string;
42
config_text = (config_lines * "\n") + "\n";
43
Stdio.write_file( filename, config_text );
51
int main(int argc, array argv)
60
for ( int i = 1; i < argc; i++ ) {
63
if ( sscanf(argv[i], "--newroot=%s", val) == 1 ) {
64
Process.system("mysqladmin -u root password " + val);
66
else if ( sscanf(argv[i], "--password=%s", val) == 1 )
67
conf["password"] = val;
68
else if ( sscanf(argv[i], "--user=%s", val) == 1 )
70
else if ( sscanf(argv[i], "--rootpw=%s", val) == 1 )
72
else if ( sscanf(argv[i], "--db=%s", val) == 1 )
74
else if ( argv[i] == "--drop" )
76
else if ( argv[i] == "--help" ) {
77
write("sTeam Setup utility creates an empty database. Options: \n"+
78
" --db= Choose the name for the new database (default: "+brand_name+")\n"+
79
" --rootpw= You MySQL root password\n"+
80
" --user= The mysql user for the database (default: steam)\n"+
81
" --password= The password for the user (default: steam)\n"+
82
" --drop Drops an old database with name specified by --db\n"+
83
" The utility returns the database access string for steam.cnf\n");
88
if ( catch(handle = Sql.Sql("mysql://root:"+conf->rootpw+"@localhost/mysql")) )
90
werror("Failed to connect to database:\n"+
91
"1) Make sure mysql is running.\n"+
92
"2) Is a root pw for mysql set? Use --rootpw=pw to login.\n");
95
array tables = handle->list_dbs();
96
if ( search(tables, conf->db) >= 0 ) {
97
write("The database "+ conf->db + " allready exists !\n");
99
handle->big_query("drop database " + conf->db);
100
write("Dropped database - creating new...\n");
105
handle->big_query("create database " + conf->db);
106
handle->big_query("use mysql");
107
handle->big_query("grant all privileges on " + conf->db + ".* to "+
108
conf->user + " @localhost identified by '" + conf->password+
109
"' with grant option;");
111
write("Database "+ conf->db + " has been created successfully.\n");
112
write("User " + conf->user + " has all privileges to new DB.\n");
113
string db_access_string = "mysql://" + conf->user + ":" + conf->password + "@localhost/" + conf->db;
115
// MySQL 4.1 and newer use a new password authentication hash. If login
116
// doesn't work, then try to use the old password format:
117
if ( objectp(handle) ) handle = 0; // disconnect
118
if ( catch( handle = Sql.Sql( db_access_string ) ) ) {
119
if ( catch( handle = Sql.Sql("mysql://root:"+conf->rootpw+"@localhost/mysql") ) == 0 ) {
120
write("Setting old password format for database user '"
121
+ conf->user + "'.\n");
122
handle->big_query("set password for " + conf->user +
123
"@localhost = OLD_PASSWORD('" + conf->password + "');" );
127
write("You acces string is: " + db_access_string + "\n");
129
replace_db_string_in_file( config_dir + "/steam.cnf", db_access_string );
130
replace_db_string_in_file( config_dir + "/config.template", db_access_string );