source: genesis/tools/genesis-to-yaml.pl@ 8621

Last change on this file since 8621 was 8621, checked in by rick, 14 years ago

Make sure path is set correctly

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1#!/usr/bin/env perl
2use File::Basename;
3
4eval {
5 require Geo::Coordinates::RDNAP;
6};
7if (! $@) {
8 Geo::Coordinates::RDNAP->import(qw/from_rd to_rd dms/);
9} else {
10 sub from_rd {
11 return (0,0,0);
12 }
13}
14
15# RD X,Y -> RD Noorderbreedte, Oosterbreedte
16# http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
17
18# Little perl to convert genesis files into python config files,
19# Which gonna be used for more logic stuff ;-)
20
21$argc = $#ARGV + 1;
22if ($argc == 0) {
23 print STDERR "Usage $_ <wleiden.conf> ...\n";
24 exit 1;
25# Hack to easy support multiple files without remembering any variable in between
26} elsif ($argc > 1) {
27 foreach $file (@ARGV) {
28 $output = $file;
29 $output =~ s/conf$/yaml/;
30 print "# Processing $file\n";
31 $CMD=dirname(__FILE__) . "/genesis-to-yaml.pl";
32 `$CMD $file > $output`;
33 }
34 exit 0;
35}
36
37
38do($ARGV[0]) || die;
39
40my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
41
42$interfaces = [];
43foreach $if (keys %config) {
44 push(@interfaces, $if) if ($if =~ m/^[a-z0-9]+$/g);
45}
46$interfaces = join(",",@interfaces);
47
48if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
49 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
50} else {
51 $lat = $lon = $h = 0;
52}
53
54$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
55$comment = $comment || 'None';
56
57print <<EOF;
58# Genesis config yaml style
59# vim:ts=2:et:sw=2:ai
60#
61comment : $comment
62interfaces: $interfaces
63latitude : $lat
64location : $location
65longitude : $lon
66masterip : $master_ip
67nodename : $nodename
68nodetype : $nodetype
69rdnap_x : $X
70rdnap_y : $Y
71status : $status
72EOF
73
74
75foreach $if (keys %config) {
76 ($iflabel, $alias) = split(':',$if);
77 $iflabel .= "_alias${alias}" if ($alias =~ m/[0-9]/);
78
79 print <<EOF;
80iface_$iflabel:
81EOF
82 %tmp = (
83 'dhcp' => 'False',
84 'compass' => 'None',
85 'interface' => $if,
86 );
87 foreach $line (split('\n',$config{$if})) {
88 ($key, $value) = split(/=/,$line);
89 # Remove trailing and leading white spaces
90 $value =~ s/^\s+//;
91 $value =~ s/\s+$//;
92 if ($key and (lc($key) =~ /^[a-z].*/)) {
93 #print "$key : $value\n";
94 $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
95 if ($key =~ /^type$/i) {
96 if ($value eq 'ethernet') {
97 $value = 'eth';
98 } else {
99 $value = '11b';
100 }
101 } elsif ($key =~ /^mode$/i) {
102 if ($value eq 'master') {
103 $value = 'ap-wds';
104 } else { # managed
105 $value = 'station-wds';
106 }
107 } elsif ($key =~ /^polar$/i) {
108 if ($value eq 'hor') {
109 $value = 'hr';
110 } else {
111 $value = 'vr';
112 }
113 } elsif ($key =~ /^essid$/i) {
114 $key = 'ssid';
115
116 # Dirty hack to fetch compass direction of essid
117 $value =~ /[a-z]+-([a-z]+)\..*/;
118 $direction = $1;
119 # Translate into English
120 if ($direction ne "omni") {
121 $direction =~ tr/oz/es/;
122 }
123 # node AMwtrt1 and 'test' directions
124 if ($direction eq "wtrtr" or $direction eq "test") {
125 $direction = 'None';
126 }
127 if ($direction) {
128 $tmp{'compass'} = $direction;
129 } else {
130 $tmp{'compass'} = 'None';
131 }
132 } elsif ($key =~ /^gain$/i) {
133 $value =~ s/dbi//;
134 }
135 $tmp{lc($key)} = $value;
136 }
137 }
138# ethernet2wifi bridges
139 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
140 $tmp{type} = 'eth';
141 }
142# 11a
143 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
144 $tmp{type} = '11a';
145 }
146
147 foreach $key (sort keys %tmp) {
148 printf " %-11s: '$tmp{$key}'\n", $key;
149 }
150 print "\n";
151}
152
Note: See TracBrowser for help on using the repository browser.