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
|
#!/usr/bin/perl
#
# uversion.pl
# Copyright (C) 2006 Jonathan Zarate
#
# - update the build number for Tomato
#
use POSIX qw(strftime);
sub error
{
print "\nuversion error: $@\n";
exit(1);
}
sub help
{
print "Usage: uversion --bump|--gen\n";
exit(1);
}
#
#
if ($#ARGV != 0) {
help();
}
$path = "router/shared";
$major = 0;
$minor = 0;
$build = 0;
open(F, "$path/tomato_version") || error("opening tomato_version: $!");
$_ = <F>;
if (!(($major, $minor, $build) = /^(\d+)\.(\d+)\.(\d+)$/)) {
error("Invalid version: '$_'");
}
close(F);
if ($ARGV[0] eq "--bump") {
++$build;
open(F, ">$path/tomato_version.~") || error("creating temp file: $!");
printf F "%d.%02d.%04d", $major, $minor, $build;
close(F);
rename("$path/tomato_version.~", "$path/tomato_version") || error("renaming: $!");
exit(0);
}
if ($ARGV[0] ne "--gen") {
help();
}
$time = strftime("%a, %d %b %Y %H:%M:%S %z", localtime());
$minor = sprintf("%02d", $minor);
$build = sprintf("%04d", $build);
open(F, ">$path/tomato_version.h~") || error("creating temp file: $!");
print F <<"END";
#ifndef __TOMATO_VERSION_H__
#define __TOMATO_VERSION_H__
#define TOMATO_MAJOR "$major"
#define TOMATO_MINOR "$minor"
#define TOMATO_BUILD "$build"
#define TOMATO_BUILDTIME "$time"
#define TOMATO_VERSION "$major.$minor.$build"
#endif
END
close(F);
rename("$path/tomato_version.h~", "$path/tomato_version.h") || error("renaming: $!");
print "Version: $major.$minor.$build ($time)\n";
exit(0);
|