1 |
dpavlin |
1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
print `clear`; |
4 |
|
|
print ("************************************************************\n"); |
5 |
|
|
print ("** LibData OS Rel. 1.0 mySQL Database Loader - 10.06.2003 **\n"); |
6 |
|
|
print ("************************************************************\n"); |
7 |
|
|
print ("** WARNING! Do NOT run this script if you have a current **\n"); |
8 |
|
|
print ("** LibData installation. It will purge required libdata **\n"); |
9 |
|
|
print ("** databases and libdata users from the mysql.user and **\n"); |
10 |
|
|
print ("** mysql.db tables. **\n"); |
11 |
|
|
print ("************************************************************\n\n"); |
12 |
|
|
|
13 |
|
|
print ("This script performs the following installation steps:\n"); |
14 |
|
|
print ("(1) Prompt for a mySQL account (typically root) and password\n"); |
15 |
|
|
print (" capable of creating/dropping databases, modifying the\n"); |
16 |
|
|
print (" grants tables, and reloading/refreshing them.\n"); |
17 |
|
|
print ("(2) It will then confirm your decision and DESTROY any\n"); |
18 |
|
|
print (" currently existing mySQL databases named libdata, libstats,\n"); |
19 |
|
|
print (" or libsession.\n"); |
20 |
|
|
print ("(3) The libdata and libsession users in the mysql.user table\n"); |
21 |
|
|
print (" will be purged, as well as references to these databases\n"); |
22 |
|
|
print (" in the mysql.db table.\n"); |
23 |
|
|
print ("(4) New libdata, libstats, and libsession databases will be\n"); |
24 |
|
|
print (" created. They'll be populated with minimal data sets.\n"); |
25 |
|
|
print ("(5) New entries for libdata and libsession will be added with\n"); |
26 |
|
|
print (" minimal required SQL rights to the mysql.user and mysql.db\n"); |
27 |
|
|
print (" grants tables.\n\n"); |
28 |
|
|
|
29 |
|
|
print ("************************************************************\n"); |
30 |
|
|
print ("** Do NOT run this script if there is data in libdata, **\n"); |
31 |
|
|
print ("** libstats, or libsession databases that you wish to **\n"); |
32 |
|
|
print ("** keep! **\n"); |
33 |
|
|
print ("************************************************************\n\n"); |
34 |
|
|
|
35 |
|
|
# collect inputs |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
# This part commented out for now - not a good idea to offer this capability? |
39 |
|
|
# print ("DNS name or IP of the mySQL host upon which to install lidata: "); |
40 |
|
|
# my $mysql_host; |
41 |
|
|
# $mysql_host = <STDIN>; |
42 |
|
|
# chomp($mysql_host); |
43 |
|
|
|
44 |
|
|
print ("mySQL user name capable of adding/dropping databases: "); |
45 |
|
|
my $mysql_user; |
46 |
|
|
$mysql_user = <STDIN>; |
47 |
|
|
chomp($mysql_user); |
48 |
|
|
|
49 |
|
|
print ("mySQL password associated with the specified user: "); |
50 |
|
|
use Term::ReadKey; |
51 |
|
|
ReadMode('noecho'); |
52 |
|
|
$mysql_pwd = ReadLine(0); |
53 |
|
|
chomp($mysql_pwd); |
54 |
|
|
ReadMode('normal'); |
55 |
|
|
|
56 |
|
|
# confirm for delete, display settings |
57 |
|
|
print ("\n\nYou entered:\n"); |
58 |
|
|
print ("mySQL server name: $mysql_host\n"); |
59 |
|
|
print ("mySQL user name: $mysql_user\n"); |
60 |
|
|
|
61 |
|
|
print ("Continue with install? WARNING: This will DROP any databases \n"); |
62 |
|
|
print ("named libdata, libstats, and session on the specified mySQL\n"); |
63 |
|
|
print ("server. Type YES (caps) if you wish to continue.\n\n"); |
64 |
|
|
|
65 |
|
|
print ("Load fresh LibData installation? "); |
66 |
|
|
my $load_flag; |
67 |
|
|
$load_flag = <STDIN>; |
68 |
|
|
chomp($load_flag); |
69 |
|
|
|
70 |
|
|
if ($load_flag eq "YES") { |
71 |
|
|
|
72 |
|
|
# dump existing libdata, libstats, session |
73 |
|
|
print ( "Dropping libdata, libstats, and session databases!\n" ); |
74 |
|
|
`cat drop.sql | mysql -u$mysql_user -p$mysql_pwd`; |
75 |
|
|
|
76 |
|
|
# create new databases |
77 |
|
|
print ("Creating new libdata, libstats and libsessions databases.\n"); |
78 |
|
|
`cat create.sql | mysql -u$mysql_user -p$mysql_pwd`; |
79 |
|
|
|
80 |
|
|
print ("Populating libdata tables & data.\n"); |
81 |
|
|
`cat libdata.sql | mysql -u$mysql_user -p$mysql_pwd libdata`; |
82 |
|
|
|
83 |
|
|
print ("Populating libstats tables.\n"); |
84 |
|
|
`cat libstats.sql | mysql -u$mysql_user -p$mysql_pwd libstats`; |
85 |
|
|
|
86 |
|
|
print ("Populating libsession tables.\n"); |
87 |
|
|
`cat libsession.sql | mysql -u$mysql_user -p$mysql_pwd libsession`; |
88 |
|
|
|
89 |
|
|
# refresh/reload grants tables |
90 |
|
|
print("Reloading and refreshing the mySQL grants tables.\n"); |
91 |
|
|
`mysqladmin -u$mysql_user -p$mysql_pwd refresh`; |
92 |
|
|
`mysqladmin -u$mysql_user -p$mysql_pwd reload`; |
93 |
|
|
|
94 |
|
|
# The "done" message |
95 |
|
|
print ("\nInstallation steps finished. Script terminated.\n"); |
96 |
|
|
|
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
else { |
100 |
|
|
|
101 |
|
|
print ("Installation cancelled. No changes made.\n\n"); |
102 |
|
|
|
103 |
|
|
} |
104 |
|
|
|