forked from nakedible/vpnease-l2tp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
executable file
·2542 lines (2012 loc) · 98.8 KB
/
build.py
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import sys, os, re, textwrap, datetime
sys.path.append(os.path.join('src', 'python'))
from codebay.build import build
from codebay.common import helpers
# Notes:
# - linux_restricted_modules currently not built for our kernel version
# - kernel .udeb packages are not installed
# - packages removed automatically because of they dependencies vanish are not purged, but deleted
# maybe TODO:
# - change default kernel options?
# - f.ex panic=N could be used to recover from temporary kernel panics..
# - preseed debconf database with config for daemons: openswan, monit, etc
# TODO:
# - purge more ubuntu packages: language packs for example
# - usplash customization
# - status information for first virtual console?
# - user/passwd configuration: root password?
# - vpnease package must depend on all essential ubuntu packages: share dependencies with livecd build so that the list is not duplicated..
# changes made by build process which could be done from a debian package to allow update:
# - distro startup modifications (diverts, etc)
# - default config modifications: /etc/default options, syslogd config, etc.
class DebSourceBuild(build.Build):
name = None
description = None
sdir=None
debname = None
debver = None
debprefix = None
deborigversion=None
deborigrevision=None
debnewversion=None
patchnames=None
def check_revision(self):
try:
self.revision.index(':')
raise build.BuildError('Cannot build from mixed-version source-tree (%s), please update.' % self.revision)
except ValueError:
pass
def append_revision_to_version(self, ver=None):
if ver is None:
ver = self.debver
return '%s+codebay+r%s' % (ver, self.revision)
# Overwrite when needed
def get_plain_deb_ver(self, ver=None):
self.check_revision()
return self.append_revision_to_version(ver=ver)
# Overwrite when needed
def get_deb_ver(self, ver=None, deb_prefix=None):
self.check_revision()
if ver is None:
ver = self.debver
if deb_prefix is not None:
ver = deb_prefix + ':' + ver
elif self.debprefix is not None:
ver = self.debprefix + ':' + ver
return self.append_revision_to_version(ver=ver)
# Overwrite when needed
def get_targets(self):
return [self.get_deb_target()]
def get_deb_name(self):
return self.debname
def get_deb_target(self, arch='i386', name=None, version=None, fileversion=None, deb_prefix=None):
if name is None: name = self.get_deb_name()
if version is None: version = self.get_deb_ver(deb_prefix=deb_prefix)
if fileversion is None: fileversion = self.get_plain_deb_ver()
return ['%s_%s_%s.deb' % (name, fileversion, arch), name, version]
def get_deb_srcdir(self):
return self.sdir
def get_deb_dsc(self):
if self.deborigrevision is not None:
dsc_end = '-' + self.deborigrevision + '.dsc'
else:
dsc_end = '.dsc'
return '%s_%s%s' % (self.debsrcname, self.deborigversion, dsc_end)
def get_deb_dirname(self):
return '%s_%s' % (self.debsrcname, self.deborigversion)
def _parse_dsc(self, dsc_file):
files_re = re.compile(r'^Files:$')
empty_re = re.compile(r'^$')
filename_re = re.compile(r'^\ [^\ ]+\ [^\ ]+\ ([^\ ]+)$')
files_start = False
filenames = []
f = open(dsc_file, 'rb')
for l in f.read().split('\n'):
if files_re.match(l.strip()) is not None:
files_start = True
continue
if not files_start:
continue
if files_start:
if empty_re.match(l.strip()) is not None:
break
m = filename_re.match(l) # NB: do not strip..
if m is not None:
filenames.append(m.groups()[0])
else:
raise build.BuildError('mismatched line "%s" in .dsc file "%s"' % (l, dsc_file))
f.close()
if len(filenames) < 1:
raise build.BuileError('no filenames found in .dsc file "%s"' % dsc_file)
return filenames
def get_deb_source_files(self):
dsc = os.path.join(self.get_deb_srcdir(), self.get_deb_dsc())
filelist = self._parse_dsc(dsc)
r = [dsc]
for f in filelist:
r.append(os.path.join(self.get_deb_srcdir(), f))
return r
def _prepare_source(self, b, bd, dscfile, patchfunc, changelog_msg='VPNease specific changes included.'):
olddebsrcdir = self.debsrcname + '-' + self.deborigversion
newdebsrcdir = self.debsrcname + '-' + self.get_plain_deb_ver()
bd.unpack_deb_source(dscfile)
if patchfunc is not None:
patchfunc(b, olddebsrcdir)
for i in self.patchnames:
bd.patch_dir(olddebsrcdir, [os.path.join(self.srcdir, self.get_deb_srcdir(), self.debsrcname + '_' + self.deborigversion + '-' + i)])
if self.deborigversion != self.debnewversion:
if changelog_msg is None:
logmsg = 'VPNease specific changes included.'
else:
logmsg = changelog_msg
bd.changelog_newversion(olddebsrcdir, self.get_deb_ver(), logmsg)
return newdebsrcdir
def _export_revision(self, bd, revision, path, dest=None):
if dest is None: dest = path
bd.ex('svn', 'export', '-r', revision, 'http://ode.intra.codebay.fi/svn/codebay/prod/main/l2tp-dev/%s' % path, dest)
def _get_source_files(self, bd):
return [os.path.join(bd.env.path, '%s_%s.dsc' % (self.debsrcname, self.get_plain_deb_ver())),
os.path.join(bd.env.path, '%s_%s.tar.gz' % (self.debsrcname, self.get_plain_deb_ver()))]
def build_source_deb(self, b, release_revision, patchfunc=None, changelog_msg=None):
self.revision = release_revision
self.srcdir = b.srcdir
bd = b.get_cwd(self.builddir)
self._export_revision(bd, release_revision, self.sdir)
newdebsrcdir = self._prepare_source(b, bd, os.path.join(self.sdir, self.get_deb_dsc()), patchfunc, changelog_msg=changelog_msg)
bd.ex('dpkg-source', '-b', newdebsrcdir, '')
return self._get_source_files(bd)
def run_source(self, b, release_revision):
return self.build_source_deb(b, release_revision, patchfunc=None,)
def build_deb(self, b, patchfunc=None, nodep=False):
bd = b.get_cwd(self.builddir)
newdebsrcdir = self._prepare_source(b, bd, os.path.join(self.srcdir, self.get_deb_srcdir(), self.get_deb_dsc()), patchfunc)
bd.build_deb_from_source(newdebsrcdir, nodep=nodep)
class VpnEaseHelper:
def __init__(self, b):
self.major = '1'
self.minor = '2'
self.revision = '0'
self.b = b
def get_ubuntu_depends(self):
# FIXME: pdf-viewer required?
return ['gawk', 'ipsec-tools', 'portmap', 'exim4', 'python-zopeinterface', 'python-tz', 'ssh', 'libltdl3', 'libmyspell3c2', 'dhcp3-server']
def get_version_history(self, revision):
history = []
# Create past timestamps like this:
# date -d "`python -c \"import datetime;print str(datetime.datetime(2007,7,6,15,5))\"`" +%a, %_d %b %Y %T +0000
now = datetime.datetime.utcnow()
build_date = datetime.datetime(now.year, now.month, now.day, now.hour, now.minute)
[rv, out, err] = self.b.ex_c(['/bin/date', '-d', '%s' % str(build_date), '+%a, %_d %b %Y %T +0000'])
if (out is None) or (out.strip() == ''):
raise build.BuildError('missing datestamp')
build_datestamp = out.strip()
history.append(['1', '0',
'5287',
['First release.'],
'Fri, 6 Jul 2007 15:05:00 +0000'])
history.append(['1', '0',
'5529',
['Minor improvements to handling of system time synchronization, \nother minor fixes.'],
'Thu, 19 Jul 2007 14:58:00 +0000'])
history.append(['1', '1',
'6708',
['RADIUS authentication support. Users can now be authenticated\n' +
'using a remote RADIUS server. The Internet Authentication Service\n' +
'(IAS) component available for Windows servers provides RADIUS ' +
'support, and allows existing Windows accounts to be used for VPN\n' +
'and web access authentication.',
'SNMP support. VPNease server can now be monitored using an SNMP\n' +
'monitoring system. A custom VPNease Management Information Base\n' +
'(MIB) module provides access to VPNease specific monitoring values.',
'Automatic VPN connection configuration for Windows XP and Windows Vista \n' +
'(available for 32-bit Windows platforms).',
'Minor improvements and bug fixes.'
],
'Fri, 19 Oct 2007 20:36:00 +0000'])
history.append(['1', '2',
8605,
['Automatic VPN connection configuration improvements. Check and\n' +
're-enable Windows IPsec and RasMan services if disabled, re-enable\n'
'L2TP encryption if disabled, support for Windows 2000 and 64-bit\n' +
'Windows versions, avoid initial Windows reboot if possible,\n' +
'automatic Desktop shortcut, automatic defaulting\n' +
'of username, automatic administrative privilege elevation for Vista.\n' +
'Mac OS X Leopard configuration using a configuration template.',
'Site-to-site error feedback improved. Address check failures caused\n' +
'by overlapping VPN subnets in client and server are now shown on web\n' +
'UI status page.',
'Installer improvements. Recovery feature allows configuration from\n' +
'a previous installation to be recovered and imported into a new installation.\n' +
'Installer now uses separate partitions for boot (/boot) and root (/)\n' +
'partitions if installation target is 4 GB or larger. This improves\n' +
'compatibility with old BIOSes unable to boot from partitions larger\n' +
'than 512 MB.',
'Dynamic DNS improvements. Addressing options now include forced address\n' +
'and NATted address of the server. More providers supported.\n',
'External SSL certificate can be configured to reduce browser warnings for\n' +
'administrator and user web user interface connections.\n',
'Minor improvements to status views, other cosmetic improvements.',
],
'Sat, 12 Jul 2008 17:44:00 +0000'])
#history.append(['1', '3',
# revision,
# ['FIXME',
# 'FIXME'],
# build_datestamp])
return history
def build(self, b, bd, targets, revision, srcdir):
b.info(' Creating vpnease metapackage:')
workdir = 'vpnease'
debiandir = os.path.join(workdir, 'debian')
controlfile = os.path.join(debiandir, 'control')
bd.makedirs(debiandir)
bd.ex('/bin/cp',
os.path.join(srcdir, 'vpnease/debian/rules'),
os.path.join(srcdir, 'vpnease/debian/changelog'),
debiandir)
depends = self.get_ubuntu_depends()
for i in targets:
# Remove casper and ubiquity-casper from depends: only used in live-cd
# Remove linux-headers.. not useful.
# Note: -dev packages are not strictly required (unless ppp-dev is?), but currently we depend from them
# and install all such packages
r = re.compile('casper|ubiquity-casper|linux-headers')
if r.match(i[1]):
continue
depends.append('%s (= %s)' % (i[1], i[2]))
helpers.write_file(os.path.join(bd.env.path, controlfile),
textwrap.dedent("""\
Source: vpnease
Maintainer: VPNease support <[email protected]>
Section: net
Priority: optional
Standards-Version: 3.6.2
Package: vpnease
Depends: %(depends)s
Architecture: all
Description: A clientless VPN product
VPNEase is a VPN product which uses the built-in client of several
operating systems for remote access.
.
Supported client operating systems include Mac OS X, all modern Windows
versions and Linux.
""" % {'depends': ', '.join(depends)}))
history = self.get_version_history(revision)
for major, minor, rev, msgs, date in history:
self.major = major
self.minor = minor
self.revision = rev
history.reverse()
logs = []
for major, minor, rev, msgs, date in history:
infos = ''
for msg in msgs:
lines = msg.split('\n')
infos += ' * %s\n' % lines[0]
for l in lines[1:]:
infos += ' %s\n' % l
logs.append(textwrap.dedent("""\
vpnease (%s.%s.%s) dapper; urgency=high
%s
-- VPNease support <[email protected]> %s
""") % (major, minor, rev, infos, date))
changelog = '\n'.join(logs)
bd.write('vpnease/debian/changelog', changelog, append=False, perms=0644)
bd.build_deb_from_source(workdir, nodep=True)
ver = '%s.%s.%s' % (self.major, self.minor, self.revision)
return [[os.path.join(bd.env.path, 'vpnease_%s_all.deb' % ver), 'vpnease', ver]]
class VpnEaseBuild(build.Build):
name = 'vpneasebuild'
description = 'Build or update vpnease package repository'
def get_targets(self):
name = 'vpnease-repository'
vers = 'r' + self.revision
self.repository_path = os.path.join(self.builddir, '%s_%s' % (name, vers))
self.targets = [[self.repository_path, name, vers]]
option_list = [build.Option('--module-search-path', type='string', dest='module_search_path', required=False),
build.Option('--major', type='string', dest='major', required=False),
build.Option('--minor', type='string', dest='minor', required=False),
build.Option('--vpnease-repokey', type='string', dest='vpnease_repokey', required=False),
build.Option('--ubuntu-repokey', type='string', dest='ubuntu_repokey', required=False),
build.Option('--kernel-path', type='string', dest='kernel_path', required=False),
build.Option('--openswan-path', type='string', dest='openswan_path', required=False),
build.Option('--l2tpgw-path', type='string', dest='l2tpgw_path', required=False),
build.Option('--ezipupdate-path', type='string', dest='ezipupdate_path', required=False),
build.Option('--basefiles-path', type='string', dest='basefiles_path', required=False),
build.Option('--monit-path', type='string', dest='monit_path', required=False),
build.Option('--openl2tp-path', type='string', dest='openl2tp_path', required=False),
build.Option('--ippool-path', type='string', dest='ippool_path', required=False),
build.Option('--twisted-path', type='string', dest='twisted_path', required=False),
build.Option('--nevow-path', type='string', dest='nevow_path', required=False),
build.Option('--formal-path', type='string', dest='formal_path', required=False),
build.Option('--rrd-path', type='string', dest='rrd_path', required=False),
build.Option('--ppp-path', type='string', dest='ppp_path', required=False),
build.Option('--casper-path', type='string', dest='casper_path', required=False),
build.Option('--libnfnetlink-path', type='string', dest='libnfnetlink_path', required=False),
build.Option('--libnetfilter-conntrack-path', type='string', dest='libnetfilter_conntrack_path', required=False),
build.Option('--conntrack-path', type='string', dest='conntrack_path', required=False),
build.Option('--iptables-path', type='string', dest='iptables_path', required=False),
build.Option('--usplash-path', type='string', dest='usplash_path', required=False),
build.Option('--sqlalchemy-path', type='string', dest='sqlalchemy_path', required=False),
build.Option('--matplotlib-path', type='string', dest='matplotlib_path', required=False),
build.Option('--pythonapsw-path', type='string', dest='pythonapsw_path', required=False),
build.Option('--freeradius-path', type='string', dest='freeradius_path', required=False),
build.Option('--radiusclientng-path', type='string', dest='radiusclientng_path', required=False),
build.Option('--syslog-path', type='string', dest='syslog_path', required=False),
build.Option('--firefox-path', type='string', dest='firefox_path', required=False)]
defaults = {
'module_search_path': '_build_temp',
'major': '1',
'minor': '2',
'vpnease_repokey': '5D31534A',
'ubuntu_repokey': '5D31534A'}
def init(self, b):
build.Build.init(self, b)
self.write_default_buildinfo(b)
def run(self, b):
bd = b.get_cwd(self.builddir)
b.info('Building repository:')
kernels = [{'name': KernelBuild.get_name(), 'option': 'kernel_path'}]
modules = [
{'name': OpenswanBuild.get_name(), 'option': 'openswan_path'},
{'name': EzipupdateBuild.get_name(), 'option': 'ezipupdate_path'},
{'name': BasefilesBuild.get_name(), 'option': 'basefiles_path'},
{'name': MonitBuild.get_name(), 'option': 'monit_path'},
{'name': IppoolBuild.get_name(), 'option': 'ippool_path'},
{'name': OpenL2tpBuild.get_name(), 'option': 'openl2tp_path'},
{'name': TwistedBuild.get_name(), 'option': 'twisted_path'},
{'name': NevowBuild.get_name(), 'option': 'nevow_path'},
{'name': FormalBuild.get_name(), 'option': 'formal_path'},
{'name': RrdBuild.get_name(), 'option': 'rrd_path'},
{'name': PppBuild.get_name(), 'option': 'ppp_path'},
{'name': CasperBuild.get_name(), 'option': 'casper_path'},
{'name': LibNfNetlinkBuild.get_name(), 'option': 'libnfnetlink_path'},
{'name': LibNetFilterConntrackBuild.get_name(), 'option': 'libnetfilter_conntrack_path'},
{'name': ConntrackBuild.get_name(), 'option': 'conntrack_path'},
{'name': IptablesBuild.get_name(), 'option': 'iptables_path'},
{'name': L2tpgwBuild.get_name(), 'option': 'l2tpgw_path'},
{'name': UsplashBuild.get_name(), 'option': 'usplash_path'},
{'name': SqlalchemyBuild.get_name(), 'option': 'sqlalchemy_path'},
{'name': MatplotlibBuild.get_name(), 'option': 'matplotlib_path'},
{'name': PythonApswBuild.get_name(), 'option': 'pythonapsw_path'},
{'name': FreeradiusBuild.get_name(), 'option': 'freeradius_path'},
{'name': RadiusclientNgBuild.get_name(), 'option': 'radiusclientng_path'},
{'name': FirefoxBuild.get_name(), 'option': 'firefox_path'},
{'name': SyslogBuild.get_name(), 'option': 'syslog_path'},
{'name': SnmpdBuild.get_name(), 'option': 'syslog_path'}]
extra = [
]
all_depends = kernels + modules
b.info('Previously built modules included:')
module_info = ''
re_name = re.compile(r'buildname: (.*?)$')
re_version = re.compile(r'revision: (.*?)$')
re_target = re.compile(r'targets: (.*?)$')
all_targets = []
extra_targets = []
for m in all_depends + extra:
m['revision'] = 'unknown'
m['targets'] = []
opt = getattr(self.options, m['option'])
if opt is None:
m['path'] = os.path.join(self.srcdir, os.path.join(self.options.module_search_path, m['name']))
else:
m['path'] = os.path.join(self.srcdir, opt)
info_file = os.path.join(m['path'], 'buildinfo.txt')
if not os.path.exists(info_file):
raise build.BuildError('missing buildinfo: %s' % info_file)
f = open(info_file)
targets = []
for l in f.read().split('\n'):
r = re_name.match(l)
if r is not None:
if m['name'] != r.groups(1)[0]:
raise build.BuildError('Found module name: %s, expecting: %s' % (r.groups(1), m['name']))
continue
r = re_version.match(l)
if r is not None:
m['revision'] = r.groups(1)[0]
continue
r = re_target.match(l)
if r is not None:
a = r.groups(1)[0]
for t in a[2:len(a)-2].split('], ['):
target = []
for i in t.split(', '):
target.append(i.strip('\'').rstrip('\''))
if len(target) != 3:
raise build.BuildError(Exception('Module buildinfo.txt broken: %s' % target))
targets.append(target)
if m not in extra:
all_targets.append(target)
m['targets'] = []
for t in targets:
path = os.path.join(m['path'], t[0])
if not os.path.exists(path):
raise build.BuildError('path does not exist: %s' % path)
m['targets'].append([path] + t[1:])
module_info += textwrap.dedent("""\
[included module]
name: %s
revision: %s
targets: %s
""") % (m['name'], m['revision'], m['targets'])
b.info(' %s, %s, %s' % (m['name'], m['revision'], m['targets']))
# Update buildinfo.txt
self.write_buildinfo(b, module_info, append=True)
b.info(' all targets: %s' % str(all_targets))
v = VpnEaseHelper(b)
vpnease_targets = v.build(b, bd, all_targets, self.revision, self.srcdir)
b.info(' Creating repository:')
confdir = os.path.join(self.repository_path, 'conf')
b.makedirs(confdir)
helpers.write_file(os.path.join(confdir, 'distributions'), textwrap.dedent("""\
Label: VPNease
Suite: dapper
Codename: dapper
Version: %s.%s
Architectures: i386
Components: main
Description: VPNease packages
SignWith: %s
""" % (self.options.major, self.options.minor, self.options.vpnease_repokey)))
myenv = os.environ
myenv['GNUPGHOME'] = os.path.join(b.srcdir, 'gnupg')
b.ex('reprepro', '-b', self.repository_path, 'check', env=myenv)
b.info(' Adding packages to repository:')
debs = vpnease_targets
for m in modules:
b.info(' Installing packages: %s' % m['targets'])
for t in m['targets']:
if t[0].endswith('.deb'):
debs.append(t)
else:
raise build.BuildError('Unknown target file.')
def _add_package_to_repository(package):
b.ex('reprepro', '-b', self.repository_path, 'includedeb', 'dapper', package)
for i in debs:
_add_package_to_repository(i[0])
for k in kernels:
b.info(' Installing patched kernel packages: %s' % k['targets'])
for i in k['targets']:
_add_package_to_repository(i[0])
for e in extra:
b.info(' Installing extra packages: %s' % e['targets'])
for i in e['targets']:
_add_package_to_repository(i[0])
b.info('New vpnease repository built in %s, copy it to ode:/var/local/data/repositories/vpnease/. If building live-cd, also remember update symlinks in ode or alternatively give a direct path to repository for repositorylivecdbuild' % self.repository_path)
class AutorunHelper:
""" $ cd l2tp-dev/src/python/webui-pages
$ PYTHONPATH=:../ python ../codebay/l2tpserver/autorun/renderpages.py
$ cp generated/autorun-installed.zip autorun-installed-files.zip
$ cp generated/autorun-livecd.zip autorun-livecd-files.zip
"""
def __init__(self, i):
self.interface = i
self.tmpdir = None
def build(self, srcdir):
self.tmpdir = '_autorun_helper'
self.cleanup()
self.interface.mkdir(self.tmpdir)
bi = self.interface.get_cwd(os.path.join(self.interface.env.path, self.tmpdir))
bi.ex('/bin/cp', '-ar', os.path.join(srcdir, 'src', 'python', 'codebay'), os.path.join(srcdir, 'src', 'python', 'webui-pages'), '.')
myenv = dict(os.environ)
myenv['PYTHONPATH'] = '../'
bw = bi.get_cwd('webui-pages')
bw.ex('/usr/bin/python', '../codebay/l2tpserver/autorun/renderpages.py', env=myenv)
bi.ex('/bin/cp', os.path.join('webui-pages', 'generated', 'autorun-installed.zip'), 'autorun-installed-files.zip')
bi.ex('/bin/cp', os.path.join('webui-pages', 'generated', 'autorun-livecd.zip'), 'autorun-livecd-files.zip')
# FIXME: this is fragile: all the paths in build environments
# up to our environment must be absolute for this to work.
return [os.path.join(bi.env.path, 'autorun-installed-files.zip'), os.path.join(bi.env.path, 'autorun-livecd-files.zip')]
def cleanup(self):
if self.tmpdir is not None:
self.interface.rmrf(self.tmpdir)
class IsolinuxHelper:
def __init__(self, bi):
self.bi = bi # Build interface
# XXX: isolinux background is not used, so this should not be called
def modify_isolinux_background(self):
"""
# XXX: 14 or 15 colors? (indexed)
background_file = os.path.join(self.srcdir, 'src/python/data/isolinux-background.png')
tmpfile = os.path.join(self.builddir, 'temp_background.ppm') # no need to cleanup
targetdir = os.path.join(bi.env.path, 'isolinux')
# cleanup old crud..
splash_re = re.compile('splash\..+')
for i in os.listdir(targetdir):
if splash_re.match(i) is not None:
self.bi.ex('/bin/rm', os.path.join(targetdir, i))
self.bi.ex('/usr/bin/convert', background_file, tmpfile)
# BN: color index 7 is used for text color, index 0 is used for background
# XXX: the color used here must exist in image palette: the assigment below has no effect for now..
self.bi.sh("/usr/bin/ppmtolss16 '#ffffff=7' < %s > %s" % (tmpfile, 'isolinux/vpnease.rle'))
self.bi.ex('cp', os.path.join(self.srcdir, 'src/python/data/isolinux-background.pcx'), 'isolinux/vpnease.pcx')
"""
raise build.BuildError('do not use, not working')
def modify_isolinux_config(self):
"""Customize Ubuntu isolinux config."""
# XXX: could use some suitable color for gfxboot background, but this does not seem to work well..
# GFXBOOT-BACKGROUND 0xB6875A
configs = {}
configs['isolinux.cfg'] = """\
DEFAULT /casper/vmlinuz
GFXBOOT bootlogo
APPEND boot=casper xforcevesa vga=785 initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL xforcevesa
menu label Install VPNease in safe ^graphics mode
kernel /casper/vmlinuz
append boot=casper xforcevesa vga=785 initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL install
menu label ^Install VPNease in native graphics mode
kernel /casper/vmlinuz
append boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL check
menu label ^Check CD for defects
kernel /casper/vmlinuz
append boot=casper integrity-check initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL memtest
menu label ^Memory test
kernel /install/mt86plus
append -
DISPLAY isolinux.txt
TIMEOUT 0
PROMPT 1
F1 f1.txt
F2 f2.txt
"""
""" 78 characters
----------------------------------------------------------------------
"""
intro = """\
VPNease is a clientless VPN product which uses the built-in client of
your operating system for IPsec-protected remote access. VPNease also
provides site-to-site connectivity and an easy-to-use web UI.
For more information, please see the product web site:
http://www.vpnease.com/
NOTE! You must accept the License Agreement and the Privacy Policy,
available at the product web site, before using the product."""
# XXX: all-in-one help file is different from those below.. not possible to merge.
configs['en.hlp'] = """\
\x04\x12F1\x14HELP\x10\x11VPNease Live CD\x10
%(intro)s
Press Escape to exit help.\x00
""" % {'intro': intro}
def _indent(indent, text):
res = ''
for l in text.split('\n'):
res += '%s%s\n' % (indent, l)
return res
# XXX: add version information
configs['f1.txt'] = """\
\x19\x0c\x0f0fHELP INDEX\x0f07 \x0f09F1\x0f07
\x0f0fThis is an install CD-ROM for VPNease.\x0f07
%(intro)s
\x0f0fKEY TOPIC\x0f07
<\x0f09F1\x0f07> This page, the help index
<\x0f09F2\x0f07> Boot methods for special ways of using this CD-ROM
Press F2 for boot details, or ENTER to """ % {'intro': _indent(' ', textwrap.dedent(intro))}
configs['f2.txt'] = """\
\x19\x0c\x0f0fBOOT METHODS\x0f07 \x0f09F2\x0f07
\x0f0fAvailable boot methods:\x0f07
\x0f0fxforcevesa\x0f07
Install VPNease in safe graphics mode (default).
\x0f0finstall\x0f07
Install VPNease in native graphics mode.
\x0f0fcheck\x0f07
Check CD for defects.
\x0f0fmemtest\x0f07
Memory test.
To use one of these boot methods, type it at the prompt, optionally
followed by any boot parameters. For example:
boot: install acpi=off
Press F1 for the help index, or ENTER to """
# NB: no help other than F1 and F2
for i in range(3, 11):
configs['f%s.txt' % str(i)] = None
""" From syslinux manpage:
<SI><bg><fg> <SI> = <Ctrl-O> = ASCII 15
Set the display colors to the specified background and
foreground colors, where <bg> and <fg> are hex digits,
corresponding to the standard PC display attributes:
0 = black 8 = dark grey
1 = dark blue 9 = bright blue
2 = dark green a = bright green
3 = dark cyan b = bright cyan
4 = dark red c = bright red
5 = dark purple d = bright purple
6 = brown e = yellow
7 = light grey f = white
Picking a bright color (8-f) for the background results in the
corresponding dark color (0-7), with the foreground flashing.
\x0c -> clear screen
\x18 -> add splash
"""
# XXX: this is not used now, text mode is without splash image
# XXX: version info not available
# \x18vpnease.rle
configs['isolinux.txt'] = """\
\x0c
\x0f0f
VPNease Live CD
\x0f07
Press <F1> for help and advanced options
or just press ENTER to """
for filename, contents in configs.iteritems():
filepath = os.path.join('isolinux', filename)
self.bi.ex('/bin/rm', filepath)
if contents is not None:
self.bi.write(filepath, textwrap.dedent(contents), perms=0644)
class LiveCDBuild(build.Build):
name = 'livecdbuild'
description = 'Ubuntu Live CD image with modifications'
option_list = [build.Option('--ubuntu-image', type='string', dest='ubuntu_image', required=True),
build.Option('--repository-server', type='string', dest='repository_server', required=True),
build.Option('--major', type='string', dest='major', required=True),
build.Option('--minor', type='string', dest='minor', required=True),
build.Option('--vpnease-repokey', type='string', dest='vpnease_repokey', required=False),
build.Option('--ubuntu-repokey', type='string', dest='ubuntu_repokey', required=False)]
defaults = {'repository_server': 'ode.intra.codebay.fi/data/repositories',
'major': '1',
'minor': '2',
'vpnease_repokey': '5D31534A',
'ubuntu_repokey': '5D31534A'}
def get_targets(self):
return [] # FIXME:
def init(self, b):
build.Build.init(self, b)
if self.revision is None:
if self.options.revision is None:
raise build.BuildError('Build revision missing.')
else:
self.revision = self.options.revision
try:
self.revision.index(':')
raise build.BuildError('Cannot build from mixed-version source-tree (%s), please update.' % self.revision)
except ValueError:
pass
vinfos = VpnEaseHelper(b).get_version_history(self.revision)
vinfo = vinfos[len(vinfos) - 1]
self.target = os.path.join(self.builddir, 'vpnease_%s-%s-%s.iso' % (vinfo[0], vinfo[1], vinfo[2]))
self.write_default_buildinfo(b)
def install_startup_scripts(self, bi):
# Note: other startup scritps are updated/installed in l2tpgw
# package postinstall script, update script is the only
# permanent script required to be present always.
bi.ex('/usr/sbin/update-rc.d', 'vpnease-update',
'stop', '99', '0', '1', '6', '.',
'start', '12', '2', '3', '4', '5', '.')
def modify_distro_startup_scripts(self, bi):
# Note: most of the diversion of startup, etc. is done now in
# system startup.
# These are required so that in first live-cd boot the gdm
# does not start too early and sysklogd is disabled
# (l2tpgw.postinst tries to do the same thing)
bi.ex('/usr/sbin/update-rc.d', '-f', 'sysklogd', 'remove')
bi.ex('/usr/sbin/update-rc.d', '-f', 'gdm', 'remove')
bi.ex('/usr/sbin/update-rc.d', 'gdm', 'stop', '01', '0', '1', '6', '.',
'start', '26', '2', '3', '4', '5', '.')
bi.ex('/usr/sbin/update-rc.d', '-f', 'ssh', 'remove')
bi.ex('/usr/sbin/update-rc.d', 'ssh', 'stop', '20', '0', '1', '6', '.',
'start', '27', '2', '3', '4', '5', '.')
def modify_default_config(self, bi):
# Note: not actually required anymore because we start portmap
# ourselves now, but keep this to be safe..
# Portmapper should bind only to local interface
bi.write('/etc/default/portmap', '\nOPTIONS="-i 127.0.0.1"\n', append=True, perms=0644)
# Change default fsck behaviour so that filesystem fixes are
# done automatically
bi.write('/etc/default/rcS', '\n# Fix errors automatically\nFSCKFIX=yes\n', append=True, perms=0644)
# FIXME: rotating logs.
# - Update /etc/syslog.conf ?
# - Update/divert /etc/cron.daily/sysklogd ?
# Remove ssh host keys
for filename in ['ssh_host_dsa_key.pub', 'ssh_host_dsa_key',
'ssh_host_rsa_key.pub', 'ssh_host_rsa_key']:
bi.ex('/bin/rm', '-f', filename)
def run(self, b):
bd = b.get_cwd(self.builddir)
b.info('Building live-cd image:')
# Check parameters
if not os.path.exists(self.options.ubuntu_image):
raise build.BuildError('Cannot find file: %s' % self.options.ubuntu_image)
# Update buildinfo.txt
module_info = '' # XXX: not used for anything.
self.write_buildinfo(b, module_info, append=True)
# Start build
cdlabel = 'VPNease Live CD' # XXX: version info
targetdir = 'live-cd-target'
workdir = 'workdir'
ubuntu_repo = [{'method': 'http', 'server': '%s/ubuntu/%s.%s' % (self.options.repository_server, self.options.major, self.options.minor), 'suite': 'dapper', 'components': 'main restricted'}]
vpnease_repo = [{'method': 'http', 'server': '%s/vpnease/%s.%s' % (self.options.repository_server, self.options.major, self.options.minor), 'suite': 'dapper', 'components': 'main'}]
bd_target = bd.get_cwd(os.path.join(self.builddir, targetdir))
bd_target_chroot = bd.get_chroot(os.path.join(self.builddir, targetdir))
bd_work = bd.get_cwd(os.path.join(self.builddir, workdir))
bd_work_chroot = bd.get_chroot(os.path.join(self.builddir, workdir))
# Extract livecd
bd.extract_livecd(os.path.join(self.srcdir, self.options.ubuntu_image))
# Setup apt-key
p = bd_work.debian_packages()
p.remove_packages(['ubuntu-keyring'])
p.unprepare()
# Prepare install-time apt keys
bd.delete_apt_keys(bd_work_chroot)
bd.setup_apt_keys(os.path.join(self.srcdir, 'gnupg'), bd_work_chroot, [self.options.vpnease_repokey, self.options.ubuntu_repokey])
# Note: repository order is important!
bd.prepare_extracted_livecd(sources=vpnease_repo + ubuntu_repo)
# Autorun setup - see wiki L2tpAutorun
ah = AutorunHelper(bd)
[_, autorun_livecd_zip] = ah.build(self.srcdir)
bd_target.ex('/usr/bin/unzip', autorun_livecd_zip)
# Note: kernel install options seem to be reasonably correct.
kernels_to_purge = ['2.6.15-26', '2.6.15-25', '2.6.15-23']
b.info('Modify filesystem:')
# Install debs
p = bd_work.debian_packages()
vpnease_package_list = ['vpnease', 'casper', 'ubiquity-casper']
b.info(' Installing packages from Ubuntu and VPNease repositories: %s' % vpnease_package_list)
# Note: repository order is important!
p.install_packages(vpnease_package_list, vpnease_repo + ubuntu_repo)
b.info(' Removing old kernel packages: %s' % kernels_to_purge)
for i in kernels_to_purge:
p.remove_packages(['linux-image-' + i + '-386'])
p.unprepare()
# Set default apt sources.list
# FIXME: get these from constants? (duplicates)
package_server = 'packages.vpnease.com'
default_ubuntu_path = '%s/ubuntu/%s.%s' % (package_server, self.options.major, self.options.minor)
default_vpnease_path = '%s/vpnease/%s.%s' % (package_server, self.options.major, self.options.minor)
# FIXME: hardcoded components and suite!
default_sources = [{'method': 'http', 'server': default_ubuntu_path, 'suite': 'dapper', 'components': 'main restricted'},
{'method': 'http', 'server': default_vpnease_path, 'suite': 'dapper', 'components': 'main'}]
p.set_apt_sources_list(default_sources)
# Boot stuff
b.info(' Updating boot-time kernel and initrd')
# Note: only one kernel image should be installed, find it and copy to casper dir
kernel_paths = [None, os.path.join(targetdir, 'casper/vmlinuz')]
initrd_paths = [None, os.path.join(targetdir, 'casper/initrd.gz')]
for r, d, f in bd.walk(os.path.join(workdir, 'boot')):
for i in f:
if i.startswith('vmlinuz-'):
kernel_paths[0] = os.path.join(r, i)
if i.startswith('initrd.img-'):
initrd_paths[0] = os.path.join(r, i)
break
for i in [kernel_paths, initrd_paths]:
if i[0] is None:
raise build.BuildError('Missing source file for destination: %s' % i[1])
bd.ex('cp', '-f', i[0], i[1])
# Helpers scripts (not required)
# b.info(' Installing helper scripts')
# bd_work_chroot.install_graphics_scripts()
# Graphics customizations
ih = IsolinuxHelper(bd_target)
ih.modify_isolinux_config()
# XXX: refactor with above..
bd.ex('cp', '-ar', os.path.join(self.srcdir, 'gfxboot-theme-ubuntu-0.1.27+codebay'), '.')
bg = bd.get_cwd('gfxboot-theme-ubuntu-0.1.27+codebay')
bg.ex('make')
bg.ex('cp', 'splash.jpg', 'install/back.jpg', 'install/bootlogo', 'install/16x16.fnt', os.path.join(bd_target.env.path, 'isolinux'))
# Modify system default configuration
b.info(' Modify default config')
self.modify_default_config(bd_work_chroot)
# Distro startup modifs
b.info(' Distro startup modifications')
self.modify_distro_startup_scripts(bd_work_chroot)
# FIMXE: this part could be made by the post-install script of the naftalin-update package
# Files required for product update are copied to permanent storage
update_tmp = 'update-tmp'
backup_store = 'var/lib/l2tpgw-permanent'
bd.ex('mkdir', '-p', update_tmp)
bd_work.ex('mkdir', '-p', backup_store)
bd_work.ex('chmod', '0755', backup_store)
ud = bd.get_cwd(update_tmp)
# Copy permanent scripts and files into place (NOTE: we want these from the *fixed* repo version!)
for s, d in [ ['src/python/postupdate/backup-files/update-files.zip', '%s/update-files.zip' % backup_store],
['src/python/postupdate/backup-files/vpnease-init', 'etc/init.d/vpnease-init'],
['src/python/postupdate/backup-files/vpnease-update', 'etc/init.d/vpnease-update'] ]:
bd.ex('cp', os.path.join(self.srcdir, s), os.path.join(bd_work.env.path, d))