-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFOOCAB.pl
753 lines (627 loc) · 18.9 KB
/
FOOCAB.pl
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
#!/usr/bin/perl
use Getopt::Long;
use NetAddr::IP::Lite;
my $host;
my $node;
my $wimax = 0;
$result = GetOptions ("host=s" => \$host,
"node=s" => \$node,
"wimax" => \$wimax);
print "wimax = $wimax\n";
open(NODEDB,"nodedb.txt");
open(SED,">foocab.sed");
$header = <NODEDB>;
chomp $header;
@vars = split /\t/, $header;
my $hi = undef;
my $ni = undef;
my $di = undef; # index of DHCPSTART
for ($i = 0 ; $i < @vars ; $i++)
{
if (defined $host && ($vars[$i] eq "HOSTNAME")) {
$hi = $i;
}
elsif (defined $node && ($vars[$i] eq "NODE")) {
$ni = $i;
}
elsif ($vars[$i] eq "DHCPSTART") {
$di = $i;
}
}
my $logo = undef;
my $bridge = undef;
my $device = undef;
my $filter = undef;
my $pubifaces = undef;
my $privifaces = undef;
my $waniface = undef;
my $vpniface = "ptp";
my $hwclock = undef;
while(<NODEDB>) {
chomp;
@vals = split /\t/;
if ((defined $hi && ($vals[$hi] eq $host)) ||
(defined $ni && ($vals[$ni] eq $node)))
{
my $masklen = undef;
my $pubaddr = undef;
my $privaddr = undef;
my $privmasklen = undef;
for ($i = 0 ; $i < @vars ; $i++)
{
# provide an overridable default value for DHCPSTART
if ($i == $di && ((not defined($vals[$i])) || ($vals[$i] eq ""))) {
$vals[$i] = 5;
}
print SED "s/PTP_$vars[$i]_PTP/$vals[$i]/g\n";
if ($vars[$i] eq "PUBMASKLEN") {
$masklen = $vals[$i];
}
if ($vars[$i] eq "PUBADDR") {
$pubaddr = $vals[$i];
}
if ($vars[$i] eq "LOGOFILE") {
$logo = $vals[$i];
}
if ($vars[$i] eq "BRIDGE") {
$bridge = $vals[$i];
}
if ($vars[$i] eq "DEVICE") {
$device = $vals[$i];
}
if ($vars[$i] eq "PRIVADDR") {
$privaddr = $vals[$i];
}
if ($vars[$i] eq "PRIVMASKLEN") {
$privmasklen = $vals[$i];
}
if ($vars[$i] eq "FILTER") {
$filter = $vals[$i];
}
}
# IPv6 prefix - this one belongs to PTP
my $ipv6slash48 = "2001:470:e962";
my @octets = split(/\./, $pubaddr);
printf(SED "s/PTP_PUB6PREFIX_PTP/%s:%02x%02x::/g\n", $ipv6slash48, @octets[2], @octets[3]);
printf(SED "s/PTP_VPN6ADDRESS_PTP/%s::%02x%02x/g\n", $ipv6slash48, @octets[2], @octets[3]);
print "DEVICE=$device\n";
if($device eq "WGT") {
$waniface = "eth0.1";
if ($bridge) {
$pubifaces = "eth0.0";
$privifaces = "";
} else {
$pubifaces = "";
$privifaces = "eth0.0";
}
print SED "s/PTP_ARCH_PTP/wgt634u/g\n";
} elsif ($device eq "ALIX") {
$waniface = "eth0";
if ($bridge) {
$pubifaces = "eth1 eth2";
$privifaces = "";
} else {
$pubifaces = "eth1";
$privifaces = "eth2";
}
print SED "s/PTP_ARCH_PTP/alix2/g\n";
$hwclock = true;
} elsif ($device eq "NET4521") {
$waniface = "eth0";
if ($bridge) {
$pubifaces = "eth1";
$privifaces = "";
} else {
$pubifaces = "";
$privifaces = "eth1";
}
print SED "s/PTP_ARCH_PTP/net4521/g\n";
$hwclock = true;
} elsif ($device eq "MR3201A") {
$waniface = "eth0";
$pubifaces = "";
$privifaces = "";
print SED "s/PTP_ARCH_PTP/atheros/g\n";
} elsif ($device eq "WNDR3800") {
$waniface = "eth1";
if ($bridge) {
$pubifaces = "eth0.1";
$privifaces = "";
} else {
$pubiface = "";
$privifaces = "eth0.1";
}
} elsif ($device eq "WDR3600") {
$waniface = "eth0.2";
if ($bridge) {
$pubifaces = "eth0.1";
$privifaces = "";
} else {
$pubiface = "";
$privifaces = "eth0.1";
}
} elsif ($device eq "WZR600DHP" || $device eq "AIRROUTER") {
$waniface = "eth1";
if ($bridge) {
$pubifaces = "eth0";
$privifaces = "";
} else {
$pubifaces = "";
$privifaces = "eth0";
}
}
print SED "s/PTP_WANIFACE_PTP/$waniface/g\n";
print SED "s/PTP_PRIVIFACES_PTP/$privifaces/g\n";
print SED "s/PTP_PUBIFACES_PTP/$pubifaces/g\n";
(defined $masklen && defined $pubaddr) || die "Not enough information to compute network!";
my $ip = NetAddr::IP::Lite->new("$pubaddr/$masklen");
my $network = $ip->network();
my $netaddr = $network->addr();
my $mask = $ip->mask();
print SED "s/PTP_PUBNET_PTP/$netaddr/g\n";
print SED "s/PTP_PUBNETMASK_PTP/$mask/g\n";
if ($privifaces ne "") {
$ip = NetAddr::IP::Lite->new("$privaddr/$privmasklen");
$network = $ip->network();
$netaddr = $network->addr();
$mask = $ip->mask();
print SED "s/PTP_PRIVNET_PTP/$netaddr/g\n";
print SED "s/PTP_PRIVNETMASK_PTP/$mask/g\n";
}
}
}
open(FILES,"find etc lib usr root -type f |");
while(<FILES>) {
chomp;
my $src = $_;
my @path = split('/',$src);
my $fname = pop @path;
my $outdir = join('/',"output",@path);
my $dest = join('/',"output",@path,$fname);
# print "source = $src ; outdir = $outdir ; dest = $dest\n";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($src);
unless (-d $outdir) { system("mkdir -p $outdir"); }
print "sed -f foocab.sed < $src > $dest\n";
system("sed -f foocab.sed < $src > $dest");
chmod($mode,$dest);
chown($uid,$gid,$dest);
}
if ($device eq "ALIX" || $device eq "NET4521" || $device eq "MR3201A" || $device eq "WNDR3800" || $device eq "WZR600DHP" || $device eq "AIRROUTER" || $device eq "WDR3600") {
# if alix or net4521 or mr3201a, remove the vlan configuration from etc/config/network
system("mv output/etc/config/network output/etc/config/network.orig ; tail -n +`grep -n 'loopback' output/etc/config/network.orig | cut -d: -f 1` output/etc/config/network.orig > output/etc/config/network ; rm output/etc/config/network.orig");
}
if ($device eq "WNDR3800") {
# if wndr3800, append vlan/led config taken from default r34240
open(NETWORKOUT,">>output/etc/config/network");
open(SYSTEMOUT,">>output/etc/config/system");
print NETWORKOUT <<EOF;
config switch
option name rtl8366s
option reset 1
option enable_vlan 1
# Blinkrate: 0=43ms; 1=84ms; 2=120ms; 3=170ms; 4=340ms; 5=670ms
option blinkrate 2
config switch_vlan
option device rtl8366s
option vlan 1
option ports "0 1 2 3 5t"
config switch_port
# Port 1 controls the GREEN configuration of LEDs for
# the switch and the section does not correspond to a real
# switch port.
#
# 0=LED off; 1=Collision/FDX; 2=Link/activity; 3=1000 Mb/s;
# 4=100 Mb/s; 5=10 Mb/s; 6=1000 Mb/s+activity; 7=100 Mb/s+activity;
# 8=10 Mb/s+activity; 9=10/100 Mb/s+activity; 10: Fiber;
# 11: Fault; 12: Link/activity(tx); 13: Link/activity(rx);
# 14: Link (master); 15: separate register
option device rtl8366s
option port 1
option led 6
config switch_port
# Port 2 controls the ORANGE configuration of LEDs for
# the switch and the section does not correspond to a real
# switch port.
#
# See the key above for switch port 1 for the meaning of the
# 'led' setting below.
option device rtl8366s
option port 2
option led 9
config switch_port
# Port 5 controls the configuration of the WAN LED and the
# section does not correspond to a real switch port.
#
# To toggle the use of green or orange LEDs for the WAN port,
# see the LED setting for wndr3700:green:wan in /etc/config/system.
#
# See the key above for switch port 1 for the meaning of the
# 'led' setting below.
option device rtl8366s
option port 5
option led 2
EOF
print SYSTEMOUT <<EOF;
config led 'led_wan'
option name 'WAN LED (green)'
option sysfs 'wndr3700:green:wan'
option default '0'
config led 'led_usb'
option name 'USB'
option sysfs 'wndr3700:green:usb'
option trigger 'usbdev'
option dev '1-1'
option interval '50'
EOF
}
if ($device eq "WZR600DHP") {
# if wzr600dhp, append vlan/led config taken from default r35052
open(NETWORKOUT,">>output/etc/config/network");
open(SYSTEMOUT,">>output/etc/config/system");
print NETWORKOUT <<EOF;
config switch
option reset '1'
option enable_vlan '1'
option name 'switch0'
config switch_vlan
option vlan '1'
option ports '0 1 2 3 4'
option device 'switch0'
EOF
print SYSTEMOUT <<EOF;
config led 'led_diag'
option name 'DIAG'
option sysfs 'buffalo:red:diag'
option default '0'
config led 'led_router'
option name 'ROUTER'
option sysfs 'buffalo:green:router'
option trigger 'netdev'
option dev 'eth1'
option mode 'link tx rx'
config led 'led_usb'
option name 'USB'
option sysfs 'buffalo:green:usb'
option trigger 'usbdev'
option dev '1-1'
option interval '50'
EOF
close(NETWORKOUT);
close(SYSTEMOUT);
}
if ($device eq "WDR3600") {
open(NETWORKOUT,">>output/etc/config/network");
open(WIRELESSOUT,">output/etc/config/wireless");
open(SYSTEMOUT,">>output/etc/config/system");
print NETWORKOUT <<EOF;
config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
config switch_vlan
option device 'switch0'
option vlan '1'
option ports '0t 2 3 4 5'
config switch_vlan
option device 'switch0'
option vlan '2'
option ports '0t 1'
EOF
print WIRELESSOUT <<EOF;
config wifi-device radio0
option type mac80211
option channel 11
option hwmode 11ng
option path 'platform/ar934x_wmac'
option htmode HT20
list ht_capab LDPC
list ht_capab SHORT-GI-20
list ht_capab SHORT-GI-40
list ht_capab TX-STBC
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
# REMOVE THIS LINE TO ENABLE WIFI:
# option disabled 1
config wifi-iface
option device radio0
option network pub
option mode ap
option ssid www.personaltelco.net/notyet
option encryption none
config wifi-device radio1
option type mac80211
option channel 36
option hwmode 11na
option path 'pci0000:00/0000:00:00.0'
option htmode HT20
list ht_capab LDPC
list ht_capab SHORT-GI-20
list ht_capab SHORT-GI-40
list ht_capab TX-STBC
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
# REMOVE THIS LINE TO ENABLE WIFI:
# option disabled 1
config wifi-iface
option device radio1
option network pub
option mode ap
option ssid www.personaltelco.net/notyet
option encryption none
EOF
print SYSTEMOUT <<EOF;
config led 'led_usb1'
option name 'USB1'
option sysfs 'tp-link:green:usb1'
option trigger 'usbdev'
option dev '1-1.1'
option interval '50'
config led 'led_usb2'
option name 'USB2'
option sysfs 'tp-link:green:usb2'
option trigger 'usbdev'
option dev '1-1.2'
option interval '50'
config led 'led_wlan2g'
option name 'WLAN2G'
option sysfs 'tp-link:blue:wlan2g'
option trigger 'phy0tpt'
EOF
close(SYSTEMOUT);
close(WIRELESSOUT);
close(NETWORKOUT);
}
if ($device eq "AIRROUTER") {
# if airrouter, append vlan config taken from r37493
open(NETWORKOUT,">>output/etc/config/network");
open(WIRELESSOUT,">output/etc/config/wireless");
print NETWORKOUT <<EOF;
config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
config switch_vlan
option device 'switch0'
option vlan '1'
option ports '0 1 2 3 4'
EOF
print WIRELESSOUT <<EOF;
config wifi-device radio0
option type mac80211
option channel 1
option hwmode 11ng
option path 'pci0000:00/0000:00:00.0'
option htmode HT20
list ht_capab SHORT-GI-40
list ht_capab TX-STBC
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
# REMOVE THIS LINE TO ENABLE WIFI:
# option disabled 1
config wifi-iface
option device radio0
option network pub
option mode ap
option ssid www.personaltelco.net/notyet
option encryption none
EOF
close(NETWORKOUT);
close(WIRELESSOUT);
}
if ($device eq "WNDR3800" || $device eq "WZR600DHP") {
open(WIRELESSOUT,">output/etc/config/wireless");
print WIRELESSOUT <<EOF;
config wifi-device radio0
option type mac80211
option channel 11
option hwmode 11ng
option path 'pci0000:00/0000:00:11.0'
option htmode HT20
list ht_capab SHORT-GI-40
list ht_capab TX-STBC
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
# REMOVE THIS LINE TO ENABLE WIFI:
#option disabled 1
config wifi-iface
option device radio0
option network pub
option mode ap
option ssid www.personaltelco.net/notyet
option encryption none
config wifi-device radio1
option type mac80211
option channel 36
option hwmode 11na
option path 'pci0000:00/0000:00:12.0'
option htmode HT20
list ht_capab SHORT-GI-40
list ht_capab TX-STBC
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
# REMOVE THIS LINE TO ENABLE WIFI:
#option disabled 1
config wifi-iface
option device radio1
option network pub
option mode ap
option ssid www.personaltelco.net/notyet
option encryption none
EOF
close(WIRELESSOUT);
}
if ($device eq "ALIX") {
# delete the etc/config/wireless
system("rm output/etc/config/wireless");
}
if ($privifaces eq "") {
# delete the priv network configuration from etc/config/network
open(NETWORKIN,"output/etc/config/network");
open(NETWORKOUT,">output/etc/config/network.out");
my $output = 1;
while(<NETWORKIN>) {
chomp;
if($_ =~ /priv/) {
$output = 0;
print "output off\n";
}
if($_ =~ /pub/) {
$output = 1;
}
if ($output) {
print NETWORKOUT "$_\n";
}
}
system("mv output/etc/config/network.out output/etc/config/network");
# delete the priv network configuration from etc/config/dhcp
open(DHCPIN,"output/etc/config/dhcp");
open(DHCPOUT,">output/etc/config/dhcp.out");
my $output = 1;
while(<DHCPIN>) {
chomp;
if($_ =~ /^config dhcp priv/) {
$output = 0;
print "output off\n";
}
if($_ =~ /^config dhcp pub/) {
$output = 1;
}
if ($output) {
print DHCPOUT "$_\n";
}
}
system("mv output/etc/config/dhcp.out output/etc/config/dhcp");
# delete the priv network rules from etc/init.d/firewall_rss
open(FIREWALLIN,"output/etc/init.d/firewall_rss");
open(FIREWALLOUT,">output/etc/init.d/firewall_rss.out");
while(<FIREWALLIN>) {
chomp;
if($_ !~ /PRIVNET/) {
print FIREWALLOUT "$_\n";
}
}
system("mv output/etc/init.d/firewall_rss.out output/etc/init.d/firewall_rss");
chmod(0755,"output/etc/init.d/firewall_rss");
}
open(LINKS,"find etc usr root www -type l |");
while(<LINKS>) {
chomp;
my $src = $_;
my @path = split('/',$src);
my $fname = pop @path;
my $outdir = join('/',"output",@path);
my $dest = join('/',"output",@path,$fname);
unless (-d $outdir) { system("mkdir -p $outdir"); }
print "cp -a $src $dest\n";
system("cp -a $src $dest");
}
if ($filter ne "NONE") {
my $outdir = "output/etc/hotplug.d/iface";
unless (-d $outdir) { system("mkdir -p $outdir"); }
# create filter script and /etc/rc.d link
open(FILTER,">$outdir/60-filter");
print FILTER "#!/bin/sh\n\n";
if ($filter eq "WAN" || $filter eq "BOTH") {
print FILTER
"WANF=/tmp/run/wanfilter.net
[ \"\$INTERFACE\" = \"wan\" ] && {
[ \"\$ACTION\" = ifup ] && {
# prevent first-hop WAN destinations from being reached from the public or ptp (vpn) interfaces
for wannet in \$(ip addr show dev \$DEVICE | grep 'inet ' | awk '{ print \$2 }') ; do
echo \$wannet >> \$WANF
iptables -I FORWARD -i br-pub -d \$wannet -j DROP ;
iptables -I FORWARD -i $vpniface -d \$wannet -j DROP ;
done
# not needed for ipv6 because we don't currently provision ipv6 from the upstream network
# all ipv6 traffic goes via our vpn tunnel, and link-local addresses aren't relevent to
# FORWARDing (you don't need to drop link-local traffic at a routing boundary, it's not
# forwarded by definition, since it isn't link-local anymore).
}
[ \"\$ACTION\" = ifdown ] && {
if [ -f \$WANF ]; then
for wannet in \$(cat \$WANF) ; do
iptables -D FORWARD -i br-pub -d \$wannet -j DROP
iptables -D FORWARD -i $vpniface -d \$wannet -j DROP
done
rm \$WANF
fi
}
}\n";
}
if (($privifaces ne "") && ($filter eq "PRIV" || $filter eq "BOTH")) {
print FILTER "
[ \"\$INTERFACE\" = \"priv\" ] && {
[ \"\$ACTION\" = ifup ] && {
# prevent PRIV destinations from being reached from the public or ptp (vpn) interfaces
iptables -I FORWARD -o br-priv -i br-pub -j DROP
iptables -I FORWARD -o br-priv -i $vpniface -j DROP
}
[ \"\$ACTION\" = ifdown ] && {
iptables -D FORWARD -o br-priv -i br-pub -j DROP
iptables -D FORWARD -o br-priv -i $vpniface -j DROP
}
}\n";
}
close(FILTER);
}
if($hwclock) {
open(INITCLOCK,">output/etc/init.d/initclock");
print INITCLOCK
"#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org
START=11
start() {
# set clock to hardware clock value
/sbin/hwclock -s -u
}\n";
close(INITCLOCK);
chmod 0755,"output/etc/init.d/initclock";
open(CRONTAB,">>output/etc/crontabs/root");
print CRONTAB "0 0 * * * /sbin/hwclock -w -u\n";
close(CRONTAB);
}
if($wimax) {
open(CRONTAB,">>output/etc/crontabs/root");
print CRONTAB "*/5 * * * * /usr/bin/motorola.sh > /dev/null 2>&1\n";
close(CRONTAB);
system("cp -a wimax/* output/");
}
# fetch_image.sh script
if($device eq "ALIX") { $imagename = "x86/openwrt-x86-alix2-combined-squashfs.img"; }
elsif($device eq "NET4521" || $device eq "NET4826") { $imagename = "x86/openwrt-x86-generic-combined-squashfs.img"; }
elsif($device eq "MR3201A") { $imagename = "atheros/openwrt-atheros-combined.squashfs.img"; }
elsif($device eq "WNDR3800") { $imagename = "ar71xx/openwrt-ar71xx-generic-wndr3800-squashfs-sysupgrade.bin"; }
elsif($device eq "WZR600DHP") { $imagename = "ar71xx/openwrt-ar71xx-generic-wzr-600dhp-squashfs-sysupgrade.bin"; }
elsif($device eq "WDR3600") { $imagename = "ar71xx/openwrt-ar71xx-generic-tl-wdr3600-v1-squashfs-sysupgrade.bin"; }
elsif($device eq "WGT") { $imagename = "brcm47xx/openwrt-brcm47xx-squashfs.trx"; }
elsif($device eq "AIRROUTER") { $imagename = "ar71xx/openwrt-ar71xx-generic-ubnt-airrouter-squashfs-sysupgrade.bin"; }
else { $imagename = ""; }
open(FIS,">output/usr/bin/fetch_image.sh");
print FIS <<EOF;
#!/bin/sh
cd /tmp
scp russell\@iris.personaltelco.net:src/openwrt/bin/$imagename /tmp/
EOF
system("chmod 755 output/usr/bin/fetch_image.sh");
open(WWW,"find www -type f | grep -v nodes |");
while(<WWW>) {
chomp;
my $src = $_;
my @path = split('/',$src);
my $fname = pop @path;
my $outdir = join('/',"output",@path);
my $dest = join('/',"output",@path,$fname);
# print "source = $src ; outdir = $outdir ; dest = $dest\n";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
= stat($src);
unless (-d $outdir) { system("mkdir -p $outdir"); }
print "sed -f foocab.sed < $src > $dest\n";
system("sed -f foocab.sed < $src > $dest");
chmod($mode,$dest);
chown($uid,$gid,$dest);
}
if (defined($logo) && $logo ne "") {
my $src = "www/images/nodes/$logo";
print "cp -p $src output/www/images/$logo\n";
system("cp -p $src output/www/images/$logo");
}