source: genesis/index.html@ 2989

Last change on this file since 2989 was 867, checked in by huub, 21 years ago

mime-type

  • Property svn:mime-type set to text/html
File size: 11.4 KB
Line 
1#! /usr/bin/perl
2#<BR><BR><BR>
3# <H1>start dit script op met:</H1><P> curl -s http://wLeiden.NET/genesis/ | perl --<P>
4#<BR><BR><BR><PRE>
5#! /usr/bin/perl
6#
7# aug 2002 jasper@WirelessLeiden.NL
8
9$version='0.3';
10
11#$DEBUG=1;
12
13
14$start=localtime();
15$home='/etc/wl';
16$url='http://wLeiden.NET/genesis';
17#$rpmurl='ftp://dl.xs4all.nl/pub/mirror/redhat/redhat-7.3-en/os/i386/RedHat/RPMS';
18$rpmurl='ftp://dl.xs4all.nl/pub/mirror/redhat/linux/7.3/en/os/i386/RedHat/RPMS/';
19
20@Packages=(
21'wget-1.8.1','curl-7.9.5','openssh-server-3.1p1','openssh-clients-3.1p1',
22'joe-2.9.7','zebra-0.92a-3','mrtg-2.9.17',
23'tcpdump-3.6.2','squid-2.4.STABLE6-1.7.2',
24'bind-9.2.0','apache-1.3.23','rdate-1.2-1',
25'dhcp-2.0pl5'
26);
27
28@MRTGJUNK=('cfgmaker.html','contrib.html','faq.html','forum.html','index.html',
29'indexmaker.html','logfile.html','mibhelp.html','mrtg-rrd.html','mrtg.html',
30'mrtglib.html','nt-guide.html','reference.html','squid.html','unix-guide.html',
31'webserver.html');
32
33@MRTGIMG=('mrtg-l.gif','mrtg-l.png','mrtg-m.gif','mrtg-m.png','mrtg-r.gif',
34'mrtg-r.png','mrtg-ti.gif','mrtg-ti.png');
35
36
37$curl='/usr/bin/curl';
38$inittab='/etc/inittab';
39$sshd_config='/etc/ssh/sshd_config';
40$authorized_keys='/root/.ssh/authorized_keys';
41$syslogd_conf='/etc/syslog.conf';
42$rclocal='/etc/rc.d/rc.local';
43$sc_network='/etc/sysconfig/network';
44$crontab='/etc/crontab';
45$liloconf='/etc/lilo.conf.anaconda';
46$mrtgdir='/var/www/html/mrtg';
47$passwd='/etc/passwd';
48$shadow='/etc/shadow';
49
50$var_named='/var/named';
51$var_named_slave="$var_named/slave";
52
53$hostname=`/bin/hostname`;chomp($hostname);$hostname=~s/\..*//;
54
55#select(STDOUT); $| = 1;
56
57printc( "\n\n===== Wireless Leiden Genesis $version for $hostname =====\n\n");
58printc("In the beginning there was /etc/wl");
59
60my_mkdir ($home,0750);
61
62###################### DIVERSEN #########################
63
64
65if ($ARGV[0])
66{
67 $hostname=$ARGV[0];
68 changeline($sc_network,"HOSTNAME","HOSTNAME=$hostname");
69 system("/bin/hostname $hostname.wleiden.net");
70 prints ("New hostname: $hostname");
71}
72
73
74$node=`$curl -s $url/nodes/$hostname/`;
75#print "NODE: [$node]\n";
76
77if (($node=~/found on this server/) || ($hostname eq ''))
78{
79 print "\n\nHostname \"$hostname\" unknown on genesis system.\n";
80 print "Please restart with hostname as agument:\n\n";
81 print "curl -s http://wLeiden.NET/genesis/ | perl -- - [hostname] \n\n";
82 die;
83}
84
85#goto skip;
86
87##################### PACKAGES ####################################
88
89foreach $package (@Packages) {InstallIfNotThere($package);}
90
91InstallIfNotThere("bing-1.0.4","ftp://rpmfind.net/linux/contrib/libc6/i386");
92InstallIfNotThere("fping-2.4b2","ftp://rpmfind.net/linux/PLD/current/dists/ra/PLD/i386/PLD/RPMS");
93#InstallIfNotThere("ntop-2.1-1","http://belnet.dl.sourceforge.net/sourceforge/ntop/");
94InstallIfNotThere("wavemon-0.3.3-1","ftp://rpmfind.net/linux/contrib/libc6/i386/");
95#InstallIfNotThere("idled-1.16-3","ftp://rpmfind.net/linux/PLD/current/dists/ra/PLD/i386/PLD/RPMS/");
96
97AddIfNotThere($inittab,'S0:123:respawn:/sbin/agetty -L 9600 ttyS0');
98AddIfNotThere($sshd_config,'PermitRootLogin yes');
99AddIfNotThere($syslogd_conf,'*.* /dev/tty9');
100AddIfNotThere($rclocal,'echo 60 > /proc/sys/kernel/panic');
101
102$doit='/usr/bin/rdate -s ntp.xs4all.nl;/sbin/clock --systohc --utc';
103system($doit);
104printc ("Checking /etc/crontab");
105if (! filegrep('rdate',$crontab))
106{
107 AddIfNotThere($crontab,"13 6 * * * root $doit");
108}
109
110printc ("Checking $liloconf"); if (! filegrep('timeout=15',$liloconf)) {
111 changeline($liloconf,'timeout','timeout=15'); system("/sbin/lilo -C
112 $liloconf");
113}
114
115# Jasper:
116#
117
118AddIfNotThere($authorized_keys,'1024 35
119112316178287877254070956100425865829142003519260838089408287428288025179160927766087063935502299240797274832024419201965494823824334871043373834738280496449985305215259303428888378450891325700353005777564637335420689043600277656759878355825032152723795185677246322116557728089284732770412581611008730473076369
120jasper@Foxtrot',0600); AddIfNotThere($authorized_keys,'1024 35
121118239913251009869865766536315021393707936886074250129280418473820786192419898669632268750479860782257598739847197103203348900588986714533679311193658890557424225585046131153077993767644932126481282093252667491668462126364793663058473958394234134729276158925678092948983706464884277485578826546212336317771647
122jasper@Rumba'); AddIfNotThere($authorized_keys,'1024 35
123131115877365044889919364159918102221501007851129140588698864391358409700706033130394488227521530533168939153736569754398766671594746877715705568124401657833947746079021505059669681909865480458530856596287241882611975228914550983484838927508168402688375217383947586789572836291240495264780490011259940976676783
124jasper@Tango');
125
126# Rudi:
127#
128
129AddIfNotThere($authorized_keys,'1024 35
130175064508659828994627143321524163097781640785788870666512791607844470773231705101704418403768320192803174740066957164497121494748184227124076884950318600937518771055598445142736335521690474047053323012366268793076855215471573920191862419906922134514121969462360529797078932635823683742743592103014922572913173
131rudi@flupke'); AddIfNotThere($authorized_keys,'1024 35
132143166375720170866349619197277385566768069875485196362699778322322352272754425517150081365776757054647703778864422036993461721791436126915970412582719415351906955315394823309461075762059061244401928288023541130196242097703041933109276811888686865551081981845265381340343445264057143590813968740962614380418301
133rudi@quick'); AddIfNotThere($authorized_keys,'1024 35
134124752035168971877893059147471720282336429451383717387223954769248711511091174717193477105333864864131448165452070009395515515659396169159755357937833999410182494957674293616658655374538654124880362749453138940491080015307589195673993882335454433811025091710719877693183773703706788265932234293023384253606179
135rudi@Classic');
136
137
138AddIfNotThere($passwd,'croot:x:0:0:root:/root:/bin/bash',0,'croot',1);
139AddIfNotThere($passwd,'rudi:x:1500:100::/home/rudi:/bin/bash',0,'rudi',1);
140AddIfNotThere($passwd,'jasper:x:1501:100::/home/jasper:/bin/bash',0,'jasper',1);
141
142AddIfNotThere($shadow,'croot:$1$0ngjFP1K$NFBRKYS5Ltdd6ohgf67i31:11918:0:99999:7:::',0,'croot',1);
143AddIfNotThere($shadow,'rudi:$1$Ni3ÁëñÍß$OnUTJgV3k.394Z1qDY.Vz0:11910:0:99999:7:::',0,'rudi',1);
144AddIfNotThere($shadow,'jasper:$1$hZdZY2yU$5MsprMarQcBE42NicTxib.:11881:0:99999:7:::',0,'jasper',1);
145
146
147########################## MRTG #############################3
148
149my_mkdir ($mrtgdir,0750); chdir($mrtgdir); unlink(@MRTGJUNK); foreach $file
150(@MRTGIMG) {
151 if (! -e "$mrtgdir/$file") {copyfile2("mrtg/$file",$mrtgdir,644);}
152}
153copyfile2("mrtg/cpuload.pl","/usr/local/sbin",755);
154copyfile2("mrtg/uptime.pl","/usr/local/sbin",755);
155copyfile2("mrtg/ipchains_traf.pl","/usr/local/sbin",755);
156copyfile2("mrtg/latency.pl","/usr/local/sbin",755);
157copyfile2("mrtg/memusage.pl","/usr/local/sbin",755);
158copyfile2("mrtg/throughput.pl","/usr/local/sbin",755);
159copyfile2("mrtg/uptime.pl","/usr/local/sbin",755);
160
161
162copyfile2("mrtg/wlan_bitrate.pl","/usr/local/sbin",755);
163copyfile2("mrtg/wlan_quality.pl","/usr/local/sbin",755);
164copyfile2("mrtg/wlan_snr.pl","/usr/local/sbin",755);
165copyfile2("mrtg/wlan_users.pl","/usr/local/sbin",755);
166
167AddIfNotThere($crontab,"*/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg.cfg",0,'mrtg');
168
169
170
171###################### NAMED #########################
172
173my_mkdir ($var_named,0750);
174my_mkdir ($var_named_slave,0750);
175($login,$pass,$uid,$gid) = getpwnam('named');
176chown($uid,$gid,$var_named_slave) ||
177 die "Could not change perms $var_named_slave to $uid/$gid";
178
179copyfile2('named/named.conf','/etc/',0644);
180copyfile2('named/localhost.zone','/var/named/',0644);
181copyfile2('named/127.0.0.zone','/var/named/',0644);
182copyfile2('named/root.hint','/var/named/',0644);
183copyfile2('named/resolv.conf','/root/',0644);
184
185if (! -e '/etc/rc3.d/S55named')
186{symlink('../init.d/named','/etc/rc3.d/S55named') ||
187 die "Could not symlink named.";}
188
189system("/etc/init.d/named restart"); # Direct zones gaan laden. --> cache
190
191###################### APACHE #########################
192
193copyfile2('apache/httpd.conf','/etc/httpd/conf/');
194
195###################### SQUID #########################
196
197copyfile2('squid/squid.conf','/etc/squid/');
198
199###################### NETWERK #########################
200
201
202copyfile2("nodes/$hostname/ifcfg-eth0","/etc/sysconfig/network-scripts/");
203
204copyfile2("tools/netmask","/usr/local/bin",0750);
205
206skip: copyfile2("areas.conf","/etc/wl/",0644);
207copyfile2("nodes/$hostname/wleiden.conf","/etc/wl/",0644);
208copyfile2("tools/wleiden.pl","/etc/wl/",0750);
209copyfile2("tools/firewall","/etc/wl/",0750);
210copyfile2("tools/nofirewall","/etc/wl/",0750);
211
212copyfile2("tools/wl-runlvl","/etc/init.d/wireless",0750);
213if (! -e '/etc/rc3.d/S30wireless')
214{symlink('../init.d/wireless','/etc/rc3.d/S30wireless') ||
215 die "Could not symlink wireless.";}
216
217
218
219
220printc("Starting /etc/wl/wleiden.pl\n");
221system("/etc/wl/wleiden.pl startall");
222
223
224
225###################### #########################
226
227
228# TODO:
229#
230# httpd
231# mrtg
232# eth0, wlan*
233# zebra
234# firewall
235
236exit;
237
238##########################################################################
239
240sub printc
241{
242 prints(@_);
243 $counter++;
244}
245
246sub prints
247{
248 local($line,$nlf)=@_;
249 local($time)=localtime();
250 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
251
252 printf ("[%02d %02d:%02d:%02d] $line",$counter,$hour,$min,$sec);
253 if ($nlf eq '') {print"\n";}
254}
255
256sub filegrep
257{
258 local($grep,$file)=@_;
259 local($found)=0;
260 open(FILE,$file) || die"Could not grep in file: $file\n";
261 while(<FILE>)
262 {
263 if (/$grep/) {$found=1;last;}
264 }
265 close(FILE);
266 return($found);
267}
268
269sub add2file
270{
271 local($file,$line,$nocr)=@_;
272 open (FILE,">>$file") || die "Coult not open $file\n";
273 if (! $nocr) {print FILE "\n";}
274 print FILE "$line\n";
275 close(FILE);
276
277}
278
279sub AddIfNotThere
280{
281 local($file,$line,$mode,$search,$nocr)=@_;
282 if (! $search) {$search="^$line";}
283 if (($mode) && (! -e $file)) # Create file?
284 {
285 print("Creating file with $line\n");
286 add2file($file,$line);
287 chmod($mode,$file);
288 } else
289 {
290 printc("Checking $file: ",1);
291 if (! filegrep("$search",$file))
292 {
293 print("Adding $line\n");
294 add2file($file,$line,$nocr);
295 } else {print "OK!\n";}
296 }
297}
298
299
300sub InstallIfNotThere
301{
302 local($package,$ru)=@_;if (! $ru) {$ru=$rpmurl;}
303 local($rpm);
304 printc("Checking for rpm $package: ",1);
305 $rpm=`rpm -q $package`;
306 if ($rpm=~/not installed/)
307 {
308 print "installing now.\n";
309 system("rpm -i $ru/${package}*-i386.rpm");
310 } else {print "OK: $rpm";}
311}
312
313sub copyfile2
314{
315 local($src,$dst,$perm)=@_;if (! $perm) {$perm=0640;}
316 local($fn,$ztime);
317 if (-d $dst)
318 {
319 $dst=~s/\/$//;
320 if ($src=~/\/([^\/]+)$/) {$dst.="/$1";} else {$dst.="/$src";}
321 }
322
323 printc("Copying $src to $dst");
324
325 if (-e $dst) {$ztime="-z $dst";}
326
327 if ($DEBUG) {print("DEBUG: $curl $ztime $url/$src -o $dst\n");}
328 system("$curl -s -f $ztime $url/$src -o $dst");
329 if (! -f $dst) {die "Error copying file $src to $dst.\n";}
330 chmod($perm,$dst) || die "Could not change permission for $dst to $perm.\n";
331}
332
333sub my_mkdir
334{
335 local($dir,$perm)=@_;if (! $perm) {$perm=0755;}
336 prints ("Checking dir: $dir: ",1);
337 if (! -d $dir) {mkdir ($dir,$perm) || die "Could not make dir: $dir\n";print "created.\n";}
338 else {print "OK!\n";}
339}
340
341sub changeline
342{
343 local($file,$old,$new)=@_;
344 open(OLD,$file) || die "Could not open old file: $file\n";
345 open(NEW,">$file.genesis.$$") || die "Could not create new file: $file.genesis.$$\n";
346 while(<OLD>)
347 {
348 if (/$old/) {print NEW "$new\n";}
349 else {print NEW $_;}
350 }
351 close(NEW);
352 close(OLD);
353 rename("$file.genesis.$$",$file) || die "Coult not overwrite old file: $file\n";
354}
355
356
357
358
359
360# </PRE>
361
362
Note: See TracBrowser for help on using the repository browser.