File: install

package info (click to toggle)
gnudip 2.1.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 252 kB
  • ctags: 24
  • sloc: perl: 2,088; sh: 95; makefile: 43
file content (238 lines) | stat: -rwxr-xr-x 7,369 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/perl
#####################################################
#  install    Part of GnuDIP 2.1.1                  #
#                                                   #
#    Install script for GnuDIP (MySQL Only!)        #
#                                                   #
#    See COPYING for licensing information          #
#                                                   #
#       Mike Machado <mike@innercite.com>           #
#                                                   #
#####################################################


use strict;
use DBI;

my ($sth, $dbtype, $onboot, $initdir, $isinuser, $isindb);
my $VER = "2.1.1";

my $ROOTUSER = 'root';
my $ROOTGROUP = 'root';

die "Must run install as root\n" if $> ne '0';

print "\n-Installing GnuDIP version $VER-\n\n";

while ($dbtype ne "1" && $dbtype ne "2") {
  print "Please select database type \n\t\t 1 - MySQL < 3.22.11\n\t\t[2 - MySQL >= 3.22.11] ";
  $dbtype = <STDIN>;
  chop($dbtype);
  if ($dbtype eq "") {
   $dbtype = "2";
  }
}


print "\nEnter root mysql username [root] ";
my $rootmysqluser = <STDIN>;
chop($rootmysqluser);
if ($rootmysqluser eq "") {
   $rootmysqluser = "root";
}

print "Enter root mysql password: ";
system("stty -echo");
my $rootmysqlpass = <STDIN>;
chop($rootmysqlpass);
system("stty echo");

my $dbh = DBI->connect("DBI:mysql:mysql",$rootmysqluser, $rootmysqlpass) || die "Could not connect to database server. Invalid login?\n";


print "\n\nEnter username GnuDIP should connect to database as [gnudip] ";
my $gnudipuser = <STDIN>;
chop($gnudipuser);
if ($gnudipuser eq "") {
   $gnudipuser = "gnudip";
}

my $gnudippass;
while ($gnudippass eq '') {
  print "Enter password you wish to use with the user $gnudipuser: ";
  $gnudippass = <STDIN>;
  chop($gnudippass);
}

print "\nEnter the user your webserver runs as [nobody] ";
my $webuser = <STDIN>;
chop($webuser);
if ($webuser eq "") {
   $webuser = "nobody";
}

print "Enter the user group the webserver runs as [nobody] ";
my $webgroup = <STDIN>;
chop($webgroup);
if ($webgroup eq "") {
   $webgroup = "nobody";
}

print "\nEnter the user to run the GnuDIP daemon as [nobody] ";
my $daemonuser = <STDIN>;
chop($daemonuser);
if ($daemonuser eq "") {
   $daemonuser = "nobody";
}

print "Enter the group to run the GnuDIP daemon as [nobody] ";
my $daemongroup = <STDIN>;
chop($daemongroup);
if ($daemongroup eq "") {
   $daemongroup = "nobody";
}

print "\nEnter the install prefix [/usr/local] ";
my $prefix = <STDIN>;
chop($prefix);
if ($prefix eq "") {
   $prefix = "/usr/local";
}
my $sedprefix = $prefix;
$sedprefix =~ s/\//\\\\\//g;

print "Enter the web server cgi-bin directory [/usr/local/apache/cgi-bin] ";
my $cgidir = <STDIN>;
chop($cgidir);
if ($cgidir eq "") {
   $cgidir = "/usr/local/apache/cgi-bin";
}

my $perldir;
if (-d "/usr/lib/perl5") {
 $perldir = "/usr/lib/perl5";
} elsif (-d "/usr/local/lib/perl5") {
 $perldir = "/usr/lib/perl5";
} else {
 print "Unable to determine perl library directory. Please enter perl5 library directory: ";
 chop ($perldir = <STDIN>);
}
my $correctperldir;
foreach my $inc (@INC) {
  if ($perldir eq $inc) {
    $correctperldir = "YES";
  }
}
if ($correctperldir ne "YES") {
 print "Perl library directory found is not in your INC path, resetting to a valid INC path\n";
 $perldir = $INC[0];
} 

while ($onboot ne "Y" && $onboot ne "y" && $onboot ne "N" && $onboot ne "n") {
  print "Would you like to automatically start GnuDIP on boot [Y,n] ";
  $onboot = <STDIN>;
  chop($onboot);
  if ($onboot eq "") {
   $onboot = "Y";
  } elsif ($onboot eq "y") {
   $onboot = "Y";
  } elsif ($onboot eq "n") {
   $onboot = "N";
  }

  if ($onboot eq "Y") {
    print "Enter the rc directory to place S99gnudip [/etc/rc.d/rc3.d] ";
    $initdir = <STDIN>;
    chop($initdir);
    if ($initdir eq "") {
       $initdir = "/etc/rc.d/rc3.d";
    }
  }
}


my $mysqlpassstring;
if ($rootmysqlpass eq '') {
  $mysqlpassstring = "";
} else {
  $mysqlpassstring = "-p$rootmysqlpass";
}


######### DO INSTALL STUFF ################
print "\n\n***********DOING INSTALL*************\n";


  system("mysqladmin -u$rootmysqluser $mysqlpassstring create gnudip2");
  system("mysql -u$rootmysqluser $mysqlpassstring gnudip2 < gnudip2.db");

  $sth = $dbh->prepare("select user from user where user = \"$gnudipuser\"");
  $sth->execute;
  $isinuser = $sth->fetchrow_array;
  $sth = $dbh->prepare("select user from db where user = \"$gnudipuser\" and db = \"gnudip2\"");
  $sth->execute;
  $isindb = $sth->fetchrow_array;

  if ($dbtype eq "1") {
    if ($isinuser eq '') {
      $sth = $dbh->do("insert into user \(host, user, password\) values \(\"localhost\", \"$gnudipuser\", password\(\"$gnudippass\"\)\)") || die "Could not add user to MySQL database\n";
    } else {
      $sth = $dbh->do("update user set password = password\(\"$gnudippass\"\) where user = \"$gnudipuser\"") || die "Could not add user to MySQL database\n";
    }
    if ($isindb eq '') {
      $sth = $dbh->do("insert into db values \(\"localhost\", \"gnudip2\", \"$gnudipuser\", \"Y\", \"Y\", \"Y\", \"Y\", \"N\", \"N\"\)") || die "Could not add database rule entry\n";
    }

  } elsif ($dbtype = "2") {
    if ($isinuser eq '') {
      $sth = $dbh->do("insert into user \(host, user, password\) values \(\"localhost\", \"$gnudipuser\", password\(\"$gnudippass\"\)\)") || die "Could not add user to MySQL database\n";
    } else {
      $sth = $dbh->do("update user set password = password\(\"$gnudippass\"\) where user = \"$gnudipuser\"") || die "Could not add user to MySQL database\n";
    }
    if ($isindb eq '') {
      $sth = $dbh->do("insert into db values \(\"localhost\", \"gnudip2\", \"$gnudipuser\", \"Y\", \"Y\", \"Y\", \"Y\", \"N\", \"N\", \"N\", \"N\", \"N\", \"N\"\)") || die "Could not add database rule entry\n";
    }

  }

  system("mysqladmin -u$rootmysqluser $mysqlpassstring reload");

  system("sed -e s/#MYSQLUSER#/$gnudipuser/g -e s/#MYSQLPASS#/$gnudippass/g -e s/#DAEMONUSER#/$daemonuser/g -e s/#DAEMONGROUP#/$daemongroup/g < gnudip.conf > tmp1");
 
   system("sed -e s/#PREFIX#/$sedprefix/g < S99gnudip > tmp3");

print "Substituted gnudip username and password into scripts\n";


system("install -m 644 gnudip-lib.pl $perldir/gnudip-lib.pl");
print "Succesfully installed gnudip-lib.pl into $perldir\n";

system("install -m 660 -o $ROOTUSER -g $webgroup tmp1 /etc/gnudip.conf");
print "Succesfully installed gnudip.conf into /etc\n";
unlink("tmp1");

system("mkdir -p $prefix/sbin");
system("install -m 750 -o $ROOTUSER -g $ROOTGROUP gdips.pl $prefix/sbin/gdips.pl");
print "Succesfully installed gdips.pl into $prefix/sbin\n";

system("mkdir -p $prefix/sbin");
system("install -m 755 -o $ROOTUSER -g $ROOTGROUP gdipc.pl $prefix/bin");
print "Succesfully installed gdipc.pl into $prefix/bin\n";


system("install -m 750 -o $webuser -g $webgroup gnudip2.cgi $cgidir/gnudip2.cgi");
print "Succesfully installed gnudip2.cgi into $cgidir\n";

if ($onboot eq "Y") {
  system("install -m 750 -o $ROOTUSER -g $ROOTGROUP tmp3 $initdir/S99gnudip");
  print "Succesfully installed S99gnudip into $initdir\n";
  unlink("tmp3");
} else {
  system("mv tmp3 S99gnudip");
  system("chmod 755 S99gnudip");
}   

print "\nYou may now goto your web server and run the gnudip2.cgi and login as 'admin' with password 'GnuDIP' to configure your settings\n";


$dbh->disconnect;