~gz/ubuntu/wily/steam/new_rel_udev_rules

« back to all changes in this revision

Viewing changes to setup

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/pike7.6
2
 
 
3
 
/* Copyright (C) 2000-2004  Thomas Bopp, Thorsten Hampel, Ludger Merkens
4
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 * 
19
 
 * $Id: setup.in,v 1.1.1.1 2006/03/27 12:40:05 exodusd Exp $
20
 
 */
21
 
 
22
 
constant cvs_version="$Id: setup.in,v 1.1.1.1 2006/03/27 12:40:05 exodusd Exp $";
23
 
 
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@";
29
 
 
30
 
int replace_db_string_in_file ( string filename, string db_access_string )
31
 
{
32
 
    mixed err = catch {
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++ )
37
 
        {
38
 
            string line = config_lines[i];
39
 
            if ( stringp(line) && sizeof(line)>=9 && line[0..8]=="database=" )
40
 
            {
41
 
                config_lines[i] = "database=" + db_access_string;
42
 
                config_text = (config_lines * "\n") + "\n";
43
 
                Stdio.write_file( filename, config_text );
44
 
                return 1;
45
 
            }
46
 
        }
47
 
    };
48
 
    return 0;
49
 
}
50
 
 
51
 
int main(int argc, array argv)
52
 
{
53
 
    Sql.Sql handle;
54
 
    mapping conf = ([ 
55
 
        "rootpw": "", 
56
 
        "password": "steam", 
57
 
        "user":"steam", 
58
 
        "db":brand_name,]);
59
 
 
60
 
    for ( int i = 1; i < argc; i++ ) {
61
 
      string val;
62
 
      
63
 
      if ( sscanf(argv[i], "--newroot=%s", val) == 1 ) {
64
 
        Process.system("mysqladmin -u root password " + val);
65
 
      }
66
 
      else if ( sscanf(argv[i], "--password=%s", val) == 1 )
67
 
        conf["password"] = val;
68
 
      else if ( sscanf(argv[i], "--user=%s", val) == 1 )
69
 
        conf["user"] = val;
70
 
      else if ( sscanf(argv[i], "--rootpw=%s", val) == 1 )
71
 
        conf["rootpw"] = val;
72
 
      else if ( sscanf(argv[i], "--db=%s", val) == 1 )
73
 
        conf["db"] = val;
74
 
      else if ( argv[i] == "--drop" )
75
 
        conf->drop = "true";
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");
84
 
        return 0;
85
 
      }
86
 
      
87
 
    }  
88
 
    if ( catch(handle = Sql.Sql("mysql://root:"+conf->rootpw+"@localhost/mysql")) )
89
 
    {
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");
93
 
        return 1;
94
 
    }
95
 
    array tables = handle->list_dbs();
96
 
    if ( search(tables, conf->db) >= 0 ) {
97
 
        write("The database "+ conf->db + " allready exists !\n");
98
 
        if ( conf->drop ) {
99
 
            handle->big_query("drop database " + conf->db);
100
 
            write("Dropped database - creating new...\n");
101
 
        }
102
 
        else
103
 
            return 1;
104
 
    }
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;");
110
 
 
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;
114
 
 
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 + "');" );
124
 
        }
125
 
    }
126
 
 
127
 
    write("You acces string is: " + db_access_string + "\n");
128
 
 
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 );
131
 
 
132
 
    return 0;
133
 
}