#!/usr/local/bin/perl ## Copyright (c) 2000 by Dmitry Kohmanyuk ## ## Permission to use, copy, modify, and distribute this software for any ## purpose with or without fee is hereby granted, provided that the above ## copyright notice and this permission notice appear in all copies. ## ## THE SOFTWARE IS PROVIDED "AS IS" AND DMITRY KOHMANYUK DISCLAIMS ## ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES ## OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE ## CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL ## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR ## PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ## SOFTWARE. # newserial - make new serial file # $Id: newserial,v 1.5 2000/11/17 22:31:20 dk Exp $ use Getopt::Std; getopts("nfv"); $notreally = $opt_n; $force = $opt_f; $verbose = $opt_v; unless (scalar @ARGV == 1) { die "usage: $0 [-n] [-f] [-v] serial-file -n do nothing -f force creation of new serial if old cannot be read -v verbose operation "; } $SERIAL = shift; if (open(SERIAL, "<$SERIAL")) { $_ = ; ($space, $serial) = /^(\s*)(\d+)\s/; } else { die "$0: cannot open $SERIAL for reading (use -f if needed): $!\n" unless $force; $serial = 0; } unless (defined $serial) { die "$0: invalid serial format (must be all digits)\n"; } print "got serial: $serial\n" if $verbose; @time = localtime; $base = sprintf "%04d%02d%02d%02d", 1900 + $time[5], 1 + $time[4], $time[3], 1; $new_serial = $base > $serial ? $base : $serial + 1; print "new serial: $new_serial\n" if $verbose; exit if ($notreally); open(SERIAL, ">$SERIAL") || do { die "$0: cannot reopen $SERIAL for writing: $!\n" }; print SERIAL "$space$new_serial\n"; close(SERIAL);