From 28c409ef063bcd7161227dd4985e1df0c5cb8359 Mon Sep 17 00:00:00 2001 From: Damir Dzeko Date: Sun, 20 Mar 2005 17:24:50 +0000 Subject: [PATCH] r1: [svn-inject] Installing original source of carnet-tools-cn --- README.CARNet | 54 +++++++ changelog.CARNet | 24 +++ cp-update | 231 ++++++++++++++++++++++++++++ cp-update.new | 410 ++++++++++++++++++++++++++++++++++++++++++++++++++ cp-update.old | 231 ++++++++++++++++++++++++++++ debian/changelog | 1 + debian/compat | 1 + debian/control | 14 ++ debian/dirs | 2 + debian/docs | 2 + debian/install | 2 + debian/rules | 87 +++++++++++ functions.sh | 134 +++++++++++++++++ test/Makefile | 90 +++++++++++ test/README | 4 + test/test-file | 29 ++++ test/test-file.start | 29 ++++ test/test1.ok | 32 ++++ test/test2.ok | 35 +++++ test/test3.ok | 38 +++++ test/test4.ok | 41 +++++ test/test5.ok | 48 ++++++ test/test6.ok | 29 ++++ 23 files changed, 1568 insertions(+) create mode 100644 README.CARNet create mode 100644 changelog.CARNet create mode 100755 cp-update create mode 100755 cp-update.new create mode 100755 cp-update.old create mode 120000 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/dirs create mode 100644 debian/docs create mode 100644 debian/install create mode 100755 debian/rules create mode 100644 functions.sh create mode 100644 test/Makefile create mode 100644 test/README create mode 100644 test/test-file create mode 100644 test/test-file.start create mode 100644 test/test1.ok create mode 100644 test/test2.ok create mode 100644 test/test3.ok create mode 100644 test/test4.ok create mode 100644 test/test5.ok create mode 100644 test/test6.ok diff --git a/README.CARNet b/README.CARNet new file mode 100644 index 0000000..e8f8179 --- /dev/null +++ b/README.CARNet @@ -0,0 +1,54 @@ +carnet-tools-cn +~~~~~~~~~~~~~~~ + +Paket carnet-tools-cn sadrzi skripte i shell funkcije koje se cesto +koriste u CARNetovim paketima. + +Trenutna verzija sadrzi: + + - cp-update skriptu, koja se koristi u instalacijskim skriptama CARNet + paketa za dodavanje blokova teksta u konfiguracijske datoteke. + + - /usr/share/carnet-tools/functions.sh datoteku koja sadrzi sljedece + shell funkcije: + +cp_get_ifaddr + + Funkcija vraca IP adresu mreznog sucelja. U slucaju da nije + naveden kao argument, vraca IP adresu od loopback sucelja (lo). + +cp_get_ifmask + + Funkcija vraca IP netmask mreznog sucelja. U slucaju da nije + naveden kao argument, vraca IP netmask od loopback sucelja (lo). + +cp_get_cidr + + Funkcija vraca CIDR mreznog sucelja. U slucaju da nije + naveden kao argument, vraca CIDR od loopback sucelja (lo). + +cp_backup_conffile + + Funkcija backupira datoteku u /var/backups/ direktorij. Po + potrebi rotira, ako postoje neke razlike. + +cp_check_and_sed [ ...] + + Funkcija trazi regularni izraz u datotekama, te ako + postoji, izvrsi sed program nad tim datotekama. Najcesce se + koristi za zamjenu stare vrijednosti postavke novom. + + + +Svaka funkcija vraca argument u varijabli $RET, dok se prije startanja bilo +koje funkcije mogu definirati varijable: + +$CP_SCRIPT_DEBUG + + Ukljucuje debugiranje (set -vx). + +$CP_ECHO_RETURN + + Vracanje rezultata na STDIN i u varijabli $RET. + +-- Ivan 'ico' Rako Wed, 16 Mar 2005 14:25:14 +0100 diff --git a/changelog.CARNet b/changelog.CARNet new file mode 100644 index 0000000..1a33460 --- /dev/null +++ b/changelog.CARNet @@ -0,0 +1,24 @@ +carnet-tools-cn (2.00) testing; urgency=low + + * /usr/local/doc -> /usr/share/doc + * dodane funkcije: + - cp_get_ifaddr + - cp_get_ifmask + - cp_get_cidr + - cp_backup_conffile + - cp_check_and_sed + + -- Ivan 'ico' Rako Wed, 16 Mar 2005 14:27:46 +0100 + +carnet-tools (1.2) unstable; urgency=low + + * Dodana nova verzija cp-update (v2.2) + + -- Nikola Pavkovic Wed, 25 Feb 2004 21:26:58 +0100 + +carnet-tools (1.1-5) unstable; urgency=low + + * Prvo izdanje za Sarge + + -- Nikola Pavkovic Sun, 22 Feb 2004 20:44:52 +0100 + diff --git a/cp-update b/cp-update new file mode 100755 index 0000000..fdbfaf9 --- /dev/null +++ b/cp-update @@ -0,0 +1,231 @@ +#! /usr/bin/perl -w + +## Copyright (C) 1998 Hrvoje Niksic +## Modification by Zeljko Boros (block entries, removing old entries) +## More options and use strict by Zoran Dzelajlija on 2004-02-24 +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +## $Id: cp-update,v 2.2 2004/02/24 jelly Exp $ + +use strict; + +my ($name, $usage); + +($name = $0) =~ s%.*/%%; # Looks nicer without the slashes +$usage = "Usage:\n"; +$usage .= "$name [-r] [-m] [-i AFTER|-t] [-b START -e STOP] [-c CHAR] PACKAGE FILE\n"; +$usage .= " -r Remove entry PACKAGE from FILE\n"; +$usage .= " Default is to add lines from stdin.\n"; +$usage .= " -m Allow multiple blocks of the same type\n"; +$usage .= " By default, old blocks are replaced with the new one.\n"; +$usage .= "\n"; +$usage .= " Special placement of config blocks:\n"; +$usage .= " -i Insert after this line\n"; +$usage .= " -t Insert on top\n"; +$usage .= " The default is to append at the bottom.\n"; +$usage .= "\n"; +$usage .= " Manipulating block marks:\n"; +$usage .= " -c Use alternative comment character (default: #)\n"; +$usage .= " Alternative block marks:\n"; +$usage .= " -b Start mark (ie 'service ftp')\n"; +$usage .= " -e Stop mark (ie. '}')\n"; +$usage .= " These will delete to the end of the file if no end mark\n"; +$usage .= " is found. The deletion is otherwise not greedy and\n"; +$usage .= " stops at the first end mark found. You can use\n"; +$usage .= " %P to insert the PACKAGE argument, and\n"; +$usage .= " %% to insert a literal % sign into the mark.\n"; + + + + +my ($begin, $end, $trailer); +my ($parambegin, $paramend, $insert); +my ($pkg, $file); +my ($block, $multi, $addafter, $addontop); + +my $add = 1; +my $comment = "#"; +my $SEEK_END = 2; + +while (@ARGV) +{ + $_ = shift; + if (/^-c$/ || /^--comment$/) + { + defined ($comment = shift) + || die "$name: `-c' must be followed by an argument\n"; + } + elsif (/^-r$/ || /^--remove$/) + { + $add = 0; + } + elsif (/^-m$/ || /^--allow-multiple$/) + { + $multi = 1; + } + elsif (/^-b$/ || /^--begin$/) + { + defined ($parambegin = shift) + || die "$name: '-b' must be followed by an argument\n"; + $block = 1; + } + elsif (/^-e$/ || /^--end$/) + { + defined ($paramend = shift) + || die "$name: '-e' must be followed by an argument\n"; + $block = 1; + } + elsif (/^-i$/ || /^--insert-after$/) + { + defined($insert = shift) + || die "$name: '-i' must be followed by an anrgument\n"; + #$multi = 1; # uncomment for -i backward compatibility + $addafter = 1; + } + elsif (/^-t$/ || /^--insert-on-top$/) + { + $insert = ""; + $addafter = 1; + } + elsif (/^-/) + { + die "$name: Unrecognized option \`$_'\n"; + } + else + { + unshift(@ARGV, $_); + last; + } +} + +($pkg = shift) || die $usage; +($file = shift) || die $usage; +(! $block || ($parambegin && $paramend)) + || die ("$name: must provide both begin and end marks.\n"); + +if ($block) +{ + $parambegin =~ s,%P,$pkg,g; + $parambegin =~ s,%%,%,g; + $paramend =~ s,%P,$pkg,g; + $paramend =~ s,%%,%,g; + $begin = $parambegin; + $end = $paramend; + $trailer = ""; +} +else +{ + $begin = "$comment Begin update by CARNet package $pkg"; + $end = "$comment End update by CARNet package $pkg"; + $trailer = " -- DO NOT DELETE THIS LINE!"; +} + +if ($add) +{ + if (! $multi) + { + &del; + } + &add; +} +else +{ + &del; +} + +sub add() { + $trailer .= "\n"; + $begin .= $trailer; + $end .= $trailer; + my $byte = ""; # @#$@#$@#$$@#$@#$#@$! -w + my $prefix = ""; + + open (HANDLE, "<$file") || die "$file: $!\n"; + + # Need to load it all into memory if we want to write it + # out to the same file. + my @lines = if ($addafter); + + # If FILE does not have a trailing newline, be suire to add it + # before appending anything else. + + # Unless it is size 0! + if ((-s $file)) + { + seek HANDLE, -1, $SEEK_END; + defined (read HANDLE, $byte, 1) && ($byte ne "\n") && ($prefix = "\n"); + close HANDLE; + } + + if(!$addafter) + { + # The actual work is in the following three lines: + open (HANDLE, ">>$file") || die "$file: $!\n"; + print HANDLE $prefix . $begin . join('', ) . $end; + close HANDLE; + } + else + { + # Overwrite it + open (HANDLE, ">$file") || die "$file: $!\n"; + my $added = 0; + foreach (@lines) + { + if (! $added && /^$insert/o) + { + print HANDLE if ($insert ne ""); + print HANDLE $begin . join('', ) . $end; + print HANDLE if ($insert eq ""); + $added = 1; + } + else + { + print HANDLE; + } + } + if(! $added) + { + print HANDLE $prefix . $begin . join('', ) . $end; + } + close HANDLE; + } +} + +sub del() { + # saving vars for &add function... + my ($mybegin, $myend, $mytrailer); + + $mybegin = $begin; + $myend = $end; + $mytrailer = $trailer; + + # Make the strings regexp-friendly by quoting non-word chars. + $mybegin =~ s/\W/\\$&/g; + $myend =~ s/\W/\\$&/g; + $mytrailer =~ s/\W/\\$&/g; + open (HANDLE, "<$file") || die "$file: $!\n"; + # Need to load it all into memory, because we'll want to write it + # out to the same file. + my @lines = ; + close HANDLE; + open (HANDLE, ">$file") || die "$file: $!\n"; + foreach (@lines) + { + print HANDLE unless (/^$mybegin(?:$mytrailer)?$/o + .. /^$myend(?:$mytrailer)?$/o); + } + close HANDLE; +} diff --git a/cp-update.new b/cp-update.new new file mode 100755 index 0000000..56517a0 --- /dev/null +++ b/cp-update.new @@ -0,0 +1,410 @@ +#! /usr/bin/perl -w + +## Copyright (C) 1998 Hrvoje Niksic +## Modification by Zeljko Boros (block entries, removing old entries) +## More options and use strict by Zoran Dzelajlija on 2004-02-24 +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +## altered by ddzeko, 2005-03-18 +## -> reformated code, introduced coding conventions +## -> increased reliability through atomic actualization +## -> everything is done in the memory - more mem, less i/o +## -> removed append mode - in-place editing considered harmfull +## -> added in-place mode as option + +use strict; +use Fcntl qw(:DEFAULT :flock :seek); + +sub DEBUG () { 0 }; + +# coding convention: CamelCase vars are global here +# +my ($ProgramName, $UsageLong, $UsageShort); + +# Looks nicer without the slashes and dots +($ProgramName = $0) =~ s!.*/!!; # strip dir +$ProgramName =~ s!\.[^.]+$!!; # strip last ext + +# 34567890 34567890 34567890 34567890 34567890 34567890 34567890 345678 + +$UsageLong = " + $ProgramName -- versatile line-based file updating tool + usually used by package configuration scripts + + Usage: $ProgramName [options] PACKAGE FILE < stdin-content + + + - General options: + + -r | --remove Remove entry PACKAGE from FILE. + Default is to add lines from stdin. + + -m | --allow-multiple Allow multiple blocks of the same type. + By default, old blocks are replaced with + the new one. + + -h | --help Print this message. + + - Placement control: + + -t | --insert-on-top Insert stdin-content block on top. + The default is to add it at the bottom. + + -i | --insert-after x Insert after this/matching line. + -f | --insert-before x Insert before this/matching line. + -R | --regexp-match Use regexp mode for line matching. + + - Manipulating block marks: + + -c | --comment x Use alternative comment char/string. + The default is shell-style \#-sign. + + --comment-end x Use this marker for comment ending. + The default is none. Ie. '-->', '*/'. + + -b | --begin-mark x Block starting mark (ie. 'service ftp') + -e | --end-mark x Block ending mark (ie. '}') + + These will delete to the end of the file if no end mark + is found. The deletion is otherwise not greedy and stops + at the first end mark found. You can use \%P to insert + the PACKAGE argument, and \%\% to insert a literal \% sign + into the mark. + + - File handling options: + + -p | --in-place Try to preserve original inode. + -n | --no-close Do not close and reopen file when + editing it in place. + + Options marked with 'x' take single argument. Others do not. + +\n"; + +$UsageShort = "$ProgramName -- versatile line-based file updating tool\n"; +$UsageShort .= " Options: [-r] [-m] [-i AFTER|-f BEFORE|-t] [-b START -e STOP] [-c CHAR] PACKAGE FILE\n"; +$UsageShort .= " or type $ProgramName --help to be choked with help.\n"; + +my ($MarkBegin, $MarkEnd, $Trailer, $ParamBegin, $ParamEnd, $Placement, + $Package, $File, $Block, $Multi, $InsertRemove, $Comment, $CommentEnd, + $MatchLine, $RegexpMatch, $StdinContent, $NewContent, $InPlace, + $NoClose, $FileHandle, @Lines); + +# Placement modes +use constant APPEND_AT_END => 0; +use constant INSERT_BEFORE => 1; +use constant INSERT_AFTER => 2; +use constant INSERT_ON_TOP => 3; + +# InsertRemove modes +use constant DO_REMOVE => 0; +use constant DO_INSERT => 1; + +# Operation defaults +$InsertRemove = DO_INSERT; +$Placement = APPEND_AT_END; +$Comment = '#'; +$CommentEnd = ''; +$MatchLine = ''; +$InPlace = 0; +$NoClose = 0; + +while (@ARGV) { + $_ = shift; + if (/^-c$/ || /^--comment$/) { + defined ($Comment = shift) + || die "$ProgramName: `-c|--comment' must be followed by an argument\n"; + } + elsif (/^--comment-end$/) { + defined ($CommentEnd = shift) + || die "$ProgramName: `--comment-end' must be followed by an argument\n"; + } + elsif (/^-r$/ || /^--remove$/) { + $InsertRemove = DO_REMOVE; + } + elsif (/^-m$/ || /^--allow-multi(?:ple)?$/) { + $Multi = 1; + } + elsif (/^-b$/ || /^--begin(?:-mark)?$/) { + defined ($ParamBegin = shift) + || die "$ProgramName: '-b|--begin-mark' must be followed by an argument\n"; + $Block = 1; + } + elsif (/^-e$/ || /^--end(?:-mark)?$/) { + defined ($ParamEnd = shift) + || die "$ProgramName: '-e|--end-mark' must be followed by an argument\n"; + $Block = 1; + } + elsif (/^-i$/ || /^--insert-after$/) { + defined($MatchLine = shift) + || die "$ProgramName: '-i|--insert-after' must be followed by an argument\n"; + $Placement = INSERT_AFTER; + } + elsif (/^-f$/ || /^--insert-before$/) { + defined($MatchLine = shift) + || die "$ProgramName: '-f|--insert-before' must be followed by an argument\n"; + $Placement = INSERT_BEFORE; + } + elsif (/^-t$/ || /^--insert-on-top$/) { + $Placement = INSERT_ON_TOP; + } + elsif (/^-R$/ || /^--regexp(?:-match|-mode)?$/) { + $RegexpMatch = 1; + } + elsif (/^-h$/ || /^--help$/) { + die $UsageLong; + } + elsif (/^-p$/ || /^--in-place$/) { + $InPlace = 1; + } + elsif (/^-n$/ || /^--no-close$/) { + $NoClose = 1; + } + elsif (/^-/) { + die "$ProgramName: Unrecognized option \`$_'\n"; + } + else { + unshift(@ARGV, $_); + last; + } +} + +$Package = shift or die $UsageShort; +$File = shift or die $UsageShort; + +# prepare block begin and end marks +# +(! $Block || ($ParamBegin && $ParamEnd)) + or die ("$ProgramName: must provide both begin and end marks.\n"); +# +if ($Block) { + $ParamBegin =~ s, %P , $Package ,gx; + $ParamBegin =~ s, %% , % ,gx; + $ParamEnd =~ s, %P , $Package ,gx; + $ParamEnd =~ s, %% , % ,gx; + $MarkBegin = $ParamBegin; + $MarkEnd = $ParamEnd; + $Trailer = ''; +} else { + $MarkBegin = "$Comment Begin update by CARNet package $Package"; + $MarkEnd = "$Comment End update by CARNet package $Package"; + $Trailer = " -- DO NOT DELETE THIS LINE!".$CommentEnd; +} + +DEBUG and print STDERR "MarkBegin='$MarkBegin'\nMarkEnd='$MarkEnd'\nTrailer='$Trailer'\n"; + +# compile regexp if provided +# +if ($RegexpMatch) { + # compile user's regexp + eval { $MatchLine = qr<$MatchLine> }; +} +else { + # we'll do regexp matching anyway :) + # just not with user's specials interfering + eval { $MatchLine = qr<^\Q$MatchLine\E>o; }; +} +if ($@) { + die "$ProgramName: regexp compilation failed: $@ ($!)\n"; +} + +do_it() and exit(0); + + +# main procedure +# -------------- + +sub do_it { + slurp(); + if (DO_INSERT == $InsertRemove) { + $StdinContent = &stdin_content; + del() unless $Multi; + add(); + } + else { + del(); + } + actualize(); +} + + +# subroutines +# ----------- + +sub slurp() { + sysopen($FileHandle, $File, O_RDWR) or die "$ProgramName: Cannot open $File: $!\n"; + @Lines = <$FileHandle>; # slurp the whole file as lines + close($FileHandle) unless ($InPlace && $NoClose); + + # If FILE does not have a trailing newline, be sure to add it + # before appending anything else. + + if (@Lines and $Lines[$#Lines] !~ m/\n$/s) { + $Lines[$#Lines] .= "\n"; + } +} + +sub add() { + if (APPEND_AT_END == $Placement) { + # append stuff at the end of the file + push(@Lines, $StdinContent); + } + elsif (INSERT_ON_TOP == $Placement) { + # throw the stuff on top of the file + unshift(@Lines, $StdinContent); + } + else { + # insert stuff where needed + my ($line, $lineNo, $added); + $lineNo = 0; + $added = 0; + foreach $line (@Lines) { + DEBUG and print STDERR "at: $line"; + if ($line =~ m/$MatchLine/) { + DEBUG and print STDERR " - MATCH\n"; + if (INSERT_AFTER == $Placement) { + DEBUG and print STDERR " - INSERT_AFTER\n"; + splice(@Lines, $lineNo + 1, 0, $StdinContent); + } + elsif (INSERT_BEFORE == $Placement) { + DEBUG and print STDERR " - INSERT_BEFORE\n"; + splice(@Lines, $lineNo, 0, $StdinContent); + } + # once added and we're done + $added = 1; + last; + } + ++ $lineNo; + } + if (! $added) { + warn "$ProgramName: Inserting lines at the end implicitly!\n"; + push(@Lines, $StdinContent); + } + } + return scalar(@Lines); # whatever +} + +sub del() { + my ($mytrailer, $mybegin, $myend) = + ($Trailer, $MarkBegin, $MarkEnd); + + # Make the strings regexp-friendly by quoting non-word chars. + $mybegin =~ s/\W/\\$&/g; + $myend =~ s/\W/\\$&/g; + $mytrailer =~ s/\W/\\$&/g; + + my (@filtered); + foreach (@Lines) { + push (@filtered, $_) + unless (/^$mybegin(?:$mytrailer)?$/o .. /^$myend(?:$mytrailer)?$/o); + } + DEBUG and print STDERR "Deleted ". (@Lines - @filtered) ." out of ".scalar(@Lines)." lines\n"; + @Lines = @filtered; + return scalar(@Lines); # whatever +} + +# written by ddzeko@srce.hr, 2005-03-18 +# to improve reliabilitah :) +# +sub actualize() { + # put it all thogether + my $newContent = join('', @Lines); + + unless (length($newContent)) { + # safety exit in last second :) + die "$ProgramName: New content empty -- aborting file alteration!\n"; + } + + if ($InPlace) { + # Provdided as means of changing the file content + # and keeping it's inode number still. + # ------------------------------------------------------- + # this is dangerous since it can leave file in bad state + # do not use this for highly critical files (ie. inittab) + # ------------------------------------------------------- + # (REVISIT: add File::Copy call to back-up the file so + # we can at least try undoing the file content change) + # backup_copy(); + unless (fileno($FileHandle)) { + sysopen($FileHandle, $File, O_WRONLY|O_TRUNC) + or die "$ProgramName: Failed to open file '$File' for writing ($!)\n"; + } + else { + sysseek(*$FileHandle, 0, SEEK_SET) + or die "$ProgramName: Failed to seek to the begining of file ($!)\n"; + } + my $wb = syswrite($FileHandle, $newContent); + if (! $wb or length($newContent) != $wb) { + # FIXME: try restoring backup copy + die "$ProgramName: Failed to write the content to '$File' ($!)\n"; + } + if ($NoClose) { + # this could be handy for files that had stuff appended + # at the end of the file + truncate($FileHandle, length($newContent)) + or die "$ProgramName: Failed to truncate the file ($!)\n"; + } + close($FileHandle); + } + else { + my ($file_new, $file_old) = ($File, $File); + $file_new .= '.cp-update.new'; # our .new file + $file_old .= '.cp-update.old'; # our .old file + # write content in new file in single write op + sysopen ($FileHandle, $file_new, O_CREAT|O_TRUNC|O_WRONLY) + or die "$ProgramName: Failed to open file '$File' for writing ($!)\n"; + my $wb = syswrite($FileHandle, $newContent); + if (! $wb or length($newContent) != $wb) { + unlink($file_new); + die "$ProgramName: Failed to write the content to '$File' ($!)\n"; + } + close($FileHandle); + # do the moving (should be atomic) + rename($File, $file_old) + or die "$ProgramName: Failed to rename file '$File' to '$file_old' ($!)\n"; + rename($file_new, $File) + or die "$ProgramName: Failed to rename file '$file_new' to '$File' ($!)\n"; + unlink($file_old) + or warn "$ProgramName: Failed to remove file '$file_old' ($!)\n"; + } +} + +# return content from standard input +sub stdin_content() { + my ($stdin_content) = join('', ); + unless (length($stdin_content)) { + die "$ProgramName: No stdin-content provided!\n"; + } + if ($stdin_content !~ m/\n$/s) { + # add trailing newline + $stdin_content .= "\n"; + } + + my ($mytrailer, $mybegin, $myend) = + ($Trailer, $MarkBegin, $MarkEnd); + + $mytrailer .= "\n"; + $mybegin .= $mytrailer; + $myend .= $mytrailer; + + $stdin_content = ($mybegin . $stdin_content . $myend); + return $stdin_content; +} + +# create backup copy of altered file +sub backup_copy() { + die "$ProgramName: backup_copy() not implemented"; +} diff --git a/cp-update.old b/cp-update.old new file mode 100755 index 0000000..fdbfaf9 --- /dev/null +++ b/cp-update.old @@ -0,0 +1,231 @@ +#! /usr/bin/perl -w + +## Copyright (C) 1998 Hrvoje Niksic +## Modification by Zeljko Boros (block entries, removing old entries) +## More options and use strict by Zoran Dzelajlija on 2004-02-24 +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +## $Id: cp-update,v 2.2 2004/02/24 jelly Exp $ + +use strict; + +my ($name, $usage); + +($name = $0) =~ s%.*/%%; # Looks nicer without the slashes +$usage = "Usage:\n"; +$usage .= "$name [-r] [-m] [-i AFTER|-t] [-b START -e STOP] [-c CHAR] PACKAGE FILE\n"; +$usage .= " -r Remove entry PACKAGE from FILE\n"; +$usage .= " Default is to add lines from stdin.\n"; +$usage .= " -m Allow multiple blocks of the same type\n"; +$usage .= " By default, old blocks are replaced with the new one.\n"; +$usage .= "\n"; +$usage .= " Special placement of config blocks:\n"; +$usage .= " -i Insert after this line\n"; +$usage .= " -t Insert on top\n"; +$usage .= " The default is to append at the bottom.\n"; +$usage .= "\n"; +$usage .= " Manipulating block marks:\n"; +$usage .= " -c Use alternative comment character (default: #)\n"; +$usage .= " Alternative block marks:\n"; +$usage .= " -b Start mark (ie 'service ftp')\n"; +$usage .= " -e Stop mark (ie. '}')\n"; +$usage .= " These will delete to the end of the file if no end mark\n"; +$usage .= " is found. The deletion is otherwise not greedy and\n"; +$usage .= " stops at the first end mark found. You can use\n"; +$usage .= " %P to insert the PACKAGE argument, and\n"; +$usage .= " %% to insert a literal % sign into the mark.\n"; + + + + +my ($begin, $end, $trailer); +my ($parambegin, $paramend, $insert); +my ($pkg, $file); +my ($block, $multi, $addafter, $addontop); + +my $add = 1; +my $comment = "#"; +my $SEEK_END = 2; + +while (@ARGV) +{ + $_ = shift; + if (/^-c$/ || /^--comment$/) + { + defined ($comment = shift) + || die "$name: `-c' must be followed by an argument\n"; + } + elsif (/^-r$/ || /^--remove$/) + { + $add = 0; + } + elsif (/^-m$/ || /^--allow-multiple$/) + { + $multi = 1; + } + elsif (/^-b$/ || /^--begin$/) + { + defined ($parambegin = shift) + || die "$name: '-b' must be followed by an argument\n"; + $block = 1; + } + elsif (/^-e$/ || /^--end$/) + { + defined ($paramend = shift) + || die "$name: '-e' must be followed by an argument\n"; + $block = 1; + } + elsif (/^-i$/ || /^--insert-after$/) + { + defined($insert = shift) + || die "$name: '-i' must be followed by an anrgument\n"; + #$multi = 1; # uncomment for -i backward compatibility + $addafter = 1; + } + elsif (/^-t$/ || /^--insert-on-top$/) + { + $insert = ""; + $addafter = 1; + } + elsif (/^-/) + { + die "$name: Unrecognized option \`$_'\n"; + } + else + { + unshift(@ARGV, $_); + last; + } +} + +($pkg = shift) || die $usage; +($file = shift) || die $usage; +(! $block || ($parambegin && $paramend)) + || die ("$name: must provide both begin and end marks.\n"); + +if ($block) +{ + $parambegin =~ s,%P,$pkg,g; + $parambegin =~ s,%%,%,g; + $paramend =~ s,%P,$pkg,g; + $paramend =~ s,%%,%,g; + $begin = $parambegin; + $end = $paramend; + $trailer = ""; +} +else +{ + $begin = "$comment Begin update by CARNet package $pkg"; + $end = "$comment End update by CARNet package $pkg"; + $trailer = " -- DO NOT DELETE THIS LINE!"; +} + +if ($add) +{ + if (! $multi) + { + &del; + } + &add; +} +else +{ + &del; +} + +sub add() { + $trailer .= "\n"; + $begin .= $trailer; + $end .= $trailer; + my $byte = ""; # @#$@#$@#$$@#$@#$#@$! -w + my $prefix = ""; + + open (HANDLE, "<$file") || die "$file: $!\n"; + + # Need to load it all into memory if we want to write it + # out to the same file. + my @lines = if ($addafter); + + # If FILE does not have a trailing newline, be suire to add it + # before appending anything else. + + # Unless it is size 0! + if ((-s $file)) + { + seek HANDLE, -1, $SEEK_END; + defined (read HANDLE, $byte, 1) && ($byte ne "\n") && ($prefix = "\n"); + close HANDLE; + } + + if(!$addafter) + { + # The actual work is in the following three lines: + open (HANDLE, ">>$file") || die "$file: $!\n"; + print HANDLE $prefix . $begin . join('', ) . $end; + close HANDLE; + } + else + { + # Overwrite it + open (HANDLE, ">$file") || die "$file: $!\n"; + my $added = 0; + foreach (@lines) + { + if (! $added && /^$insert/o) + { + print HANDLE if ($insert ne ""); + print HANDLE $begin . join('', ) . $end; + print HANDLE if ($insert eq ""); + $added = 1; + } + else + { + print HANDLE; + } + } + if(! $added) + { + print HANDLE $prefix . $begin . join('', ) . $end; + } + close HANDLE; + } +} + +sub del() { + # saving vars for &add function... + my ($mybegin, $myend, $mytrailer); + + $mybegin = $begin; + $myend = $end; + $mytrailer = $trailer; + + # Make the strings regexp-friendly by quoting non-word chars. + $mybegin =~ s/\W/\\$&/g; + $myend =~ s/\W/\\$&/g; + $mytrailer =~ s/\W/\\$&/g; + open (HANDLE, "<$file") || die "$file: $!\n"; + # Need to load it all into memory, because we'll want to write it + # out to the same file. + my @lines = ; + close HANDLE; + open (HANDLE, ">$file") || die "$file: $!\n"; + foreach (@lines) + { + print HANDLE unless (/^$mybegin(?:$mytrailer)?$/o + .. /^$myend(?:$mytrailer)?$/o); + } + close HANDLE; +} diff --git a/debian/changelog b/debian/changelog new file mode 120000 index 0000000..dbf0845 --- /dev/null +++ b/debian/changelog @@ -0,0 +1 @@ +../changelog.CARNet \ No newline at end of file diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +4 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..bb95368 --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: carnet-tools-cn +Section: utils +Priority: optional +Maintainer: Grupa za izradu paketa +Build-Depends: debhelper (>= 4.0.0) +Standards-Version: 3.6.1 + +Package: carnet-tools-cn +Architecture: all +Depends: perl, coreutils, debianutils, gawk, ipcalc, net-tools +Description: CARNet tools for Debian packaging + CARNet tools for Debian packaging. Include: + - functions.sh + - cp-update diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..5068b8e --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/sbin +usr/share/carnet-tools diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..d92e2d1 --- /dev/null +++ b/debian/docs @@ -0,0 +1,2 @@ +README.CARNet +changelog.CARNet diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..1cc8436 --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +functions.sh usr/share/carnet-tools +cp-update usr/sbin diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..551f097 --- /dev/null +++ b/debian/rules @@ -0,0 +1,87 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + # $(MAKE) + # pod2man debian/carnet-tools-cn/usr/sbin/cp-update > cp-update.1 + + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + # -$(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/carnet-tools-cn. + # $(MAKE) install DESTDIR=$(CURDIR)/debian/carnet-tools-cn + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot +# dh_installchangelogs -k + dh_installdocs +# dh_installexamples + dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman +# dh_link +# dh_strip +# dh_compress + dh_fixperms +# dh_perl +# dh_python +# dh_makeshlibs + dh_installdeb +# dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..805a066 --- /dev/null +++ b/functions.sh @@ -0,0 +1,134 @@ +# by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100 +cp_get_ifaddr() { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local ifaddr interface + + interface="$1" + [ -z "$interface" ] && interface=lo + + if ! ifconfig $interface 2> /dev/null >> /dev/null; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifaddr: $interface: No such interface" + return 1 + fi + + ifaddr="`/sbin/ifconfig $interface | awk '/inet/{ printf("%s\n",substr($2,index($2,":")+1)) }'`" + + if [ -z $ifaddr ]; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifaddr: $interface: No such ipaddress" + return 1 + fi + + RET="$ifaddr" + [ -z "$CP_ECHO_RETURN" ] || echo $RET +} + +# by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100 +cp_get_ifmask() { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local ifmask interface + + interface="$1" + [ -z "$interface" ] && interface=lo + + if ! ifconfig $interface 2> /dev/null >> /dev/null; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifmask: $interface: No such interface" + return 1 + fi + + ifmask="`/sbin/ifconfig $interface | awk '/Mask/{if($3~/Mask/)a=$3;else if ($4~/Mask/)a=$4;printf ("%s\n", substr(a,index(a,":")+1))}'`" + + if [ -z "$ifmask" ]; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifmask: $interface: No such netmask" + return 1 + fi + + RET="$ifmask" + [ -z "$CP_ECHO_RETURN" ] || echo $RET +} + + +# by ico, Tue, 15 Mar 2005 14:04:21 +0100 +cp_get_cidr() { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local netmask ipaddress interface cidr + + interface="$1" + if [ -z "$interface" ]; then + interface="`route | awk '/^default/{print $8}'`" + [ -z "$interface" ] && interface=lo + fi + + if ! ifconfig $interface 2> /dev/null >> /dev/null; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_cidr: $interface: No such interface" + return 1 + fi + + ipaddress="`get_ifaddr $interface`" + if [ -z $ipaddress ]; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_cidr: $interface: No such ipaddress" + return 1 + fi + netmask="`get_ifmask $interface`" + if [ -z $netmask ]; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_cidr: $interface: No such netmask" + return 1 + fi + + cidr="`ipcalc -n $ipaddress $netmask | grep Network: | awk '{print $2}'`" + + RET="$cidr" + [ -z "$CP_ECHO_RETURN" ] || echo $RET +} + +# by ico, Tue, 15 Mar 2005 14:04:21 +0100 +cp_backup_conffile() { + [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx + local file_bak + + if [ -z $1 ]; then + [ -z "$CP_ECHO_RETURN" ] || echo "Usage: cp_backup_conffile " + return 1 + fi + if [ ! -f $1 ]; then + [ -z "$CP_ECHO_RETURN" ] || echo "cp_backup_conffile: $1: No such file" + return 1 + fi + + file_bak="/var/backups/`basename $1`.bak" + + if [ ! -f $file_bak ]; then + cp -pf $1 $file_bak + else + if ! cmp -s $1 $file_bak; then + /usr/bin/savelog -p -c 7 $file_bak > /dev/null 2> /dev/null + cp -pf $1 $file_bak + fi + fi +} + +# by jelly, Tue, 15 Mar 2005 14:04:21 +0100 +cp_check_and_sed() { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local s sedcmd ret i + s="$1" + shift + sedcmd="$1" + shift + ret=2 + for i in $* + do + [ -e "$i" ] || continue + egrep -q "$s" "$i" || continue + [ -h "$i" ] && i=$(readlink -f "$i") + sed "$sedcmd" "$i" > "$i.dpkg-tmp" + chown --reference "$i" "$i.dpkg-tmp" + chmod --reference "$i" "$i.dpkg-tmp" + if ! cmp -s "$i" "$i.dpkg-tmp"; then + mv "$i.dpkg-tmp" "$i" + else + rm "$i.dpkg-tmp" + fi + ret=0 + done + return $ret +} diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..7286ccf --- /dev/null +++ b/test/Makefile @@ -0,0 +1,90 @@ +# -*- Makefile -*- +# for cp-update tests + +# Created by: ddzeko@srce.hr, 2005-03-20 + +# path to cp-update script +CPUPDATE=../cp-update + +tests: test0 test1 test2 test3 test4 test5 test6 + @echo "All tests completed successfully" + +clean: test0 test-file.start + rm -f test[0-9] test[0-9][0-9] test-file.[0-9]* + +# prepare everything for test sequence +test0: test-file.start + cmp test-file test-file.start >/dev/null 2>&1 || cp test-file.start test-file + +# test line matching +# - should match only from the beginning of line +# not in the middle of it, so this text should +# be added to the end of the file, also adding +# newline to it (it's missing from the test-file) +test1: + echo Block inserted by $@ | $(CPUPDATE) -i update $@ test-file + cp test-file test-new + cmp test-new $@.ok + mv test-new $@ + echo Succeeded $@ + +# test placement +# - insert something on top of the file +test2: + echo Block inserted by $@ | $(CPUPDATE) -t $@ test-file + cp test-file test-new + cmp test-new $@.ok + mv test-new $@ + echo Succeeded $@ + +# test placement +# - insert something right in the middle using --insert-after +test3: + echo Block inserted by $@ | $(CPUPDATE) --insert-after '' $@ test-file + cp test-file test-new + cmp test-new $@.ok + mv test-new $@ + echo Succeeded $@ + +# insert something at the end using --insert-after, due to +# failed match -- implicit placement at the end is used +test4: + echo Block inserted by $@ | $(CPUPDATE) --insert-after 'abracadabra' $@ test-file + cp test-file test-new + cmp test-new $@.ok + mv test-new $@ + echo Succeeded $@ + +# insert bigger blocks we can +# - also, using regexp match +# - also, alternative comment character +# - won't work with old cp-update (no -R) +test5: + perl -e 'print "test line $$_ by $$ARGV[0]\n" for 1..5;' $@ \ + | $(CPUPDATE) -R -c ';' --insert-after '[Jj]aneiro' $@ test-file + cp test-file test-new + cmp test-new $@.ok + mv test-new $@ + echo Succeeded $@ + +# now remove everything +test6: test1 test2 test3 test4 test5 + for i in test[1-4]; do $(CPUPDATE) -r $$i test-file; done + $(CPUPDATE) -r -c ';' test5 test-file + cp test-file.start $@.ok + echo >> $@.ok + cmp test-file $@.ok + cp test-file $@ + echo Succeeded $@ + +# more tests needed +# --insert-before +# --begin/end marks +# --in-place mode +# --no-close mode + +# more test on development roadmap: +# -- add file-locking - test concurrent updates + +.SILENT: +.PHONY: tests test0 clean diff --git a/test/README b/test/README new file mode 100644 index 0000000..b07cba4 --- /dev/null +++ b/test/README @@ -0,0 +1,4 @@ +This directory contains test scripts/procedures used for quality check +of utility scripts included in the package. + + -- Damir Dzeko Sun, 20 Mar 2005 08:52:16 +0100 diff --git a/test/test-file b/test/test-file new file mode 100644 index 0000000..be1b37b --- /dev/null +++ b/test/test-file @@ -0,0 +1,29 @@ +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n \ No newline at end of file diff --git a/test/test-file.start b/test/test-file.start new file mode 100644 index 0000000..be1b37b --- /dev/null +++ b/test/test-file.start @@ -0,0 +1,29 @@ +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n \ No newline at end of file diff --git a/test/test1.ok b/test/test1.ok new file mode 100644 index 0000000..9d5ab7a --- /dev/null +++ b/test/test1.ok @@ -0,0 +1,32 @@ +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n +# Begin update by CARNet package test1 -- DO NOT DELETE THIS LINE! +Block inserted by test1 +# End update by CARNet package test1 -- DO NOT DELETE THIS LINE! diff --git a/test/test2.ok b/test/test2.ok new file mode 100644 index 0000000..ebc464d --- /dev/null +++ b/test/test2.ok @@ -0,0 +1,35 @@ +# Begin update by CARNet package test2 -- DO NOT DELETE THIS LINE! +Block inserted by test2 +# End update by CARNet package test2 -- DO NOT DELETE THIS LINE! +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n +# Begin update by CARNet package test1 -- DO NOT DELETE THIS LINE! +Block inserted by test1 +# End update by CARNet package test1 -- DO NOT DELETE THIS LINE! diff --git a/test/test3.ok b/test/test3.ok new file mode 100644 index 0000000..5bd66d8 --- /dev/null +++ b/test/test3.ok @@ -0,0 +1,38 @@ +# Begin update by CARNet package test2 -- DO NOT DELETE THIS LINE! +Block inserted by test2 +# End update by CARNet package test2 -- DO NOT DELETE THIS LINE! +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + +# Begin update by CARNet package test3 -- DO NOT DELETE THIS LINE! +Block inserted by test3 +# End update by CARNet package test3 -- DO NOT DELETE THIS LINE! + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n +# Begin update by CARNet package test1 -- DO NOT DELETE THIS LINE! +Block inserted by test1 +# End update by CARNet package test1 -- DO NOT DELETE THIS LINE! diff --git a/test/test4.ok b/test/test4.ok new file mode 100644 index 0000000..91077ac --- /dev/null +++ b/test/test4.ok @@ -0,0 +1,41 @@ +# Begin update by CARNet package test2 -- DO NOT DELETE THIS LINE! +Block inserted by test2 +# End update by CARNet package test2 -- DO NOT DELETE THIS LINE! +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + +# Begin update by CARNet package test3 -- DO NOT DELETE THIS LINE! +Block inserted by test3 +# End update by CARNet package test3 -- DO NOT DELETE THIS LINE! + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n +# Begin update by CARNet package test1 -- DO NOT DELETE THIS LINE! +Block inserted by test1 +# End update by CARNet package test1 -- DO NOT DELETE THIS LINE! +# Begin update by CARNet package test4 -- DO NOT DELETE THIS LINE! +Block inserted by test4 +# End update by CARNet package test4 -- DO NOT DELETE THIS LINE! diff --git a/test/test5.ok b/test/test5.ok new file mode 100644 index 0000000..32192cd --- /dev/null +++ b/test/test5.ok @@ -0,0 +1,48 @@ +# Begin update by CARNet package test2 -- DO NOT DELETE THIS LINE! +Block inserted by test2 +# End update by CARNet package test2 -- DO NOT DELETE THIS LINE! +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro +; Begin update by CARNet package test5 -- DO NOT DELETE THIS LINE! +test line 1 by test5 +test line 2 by test5 +test line 3 by test5 +test line 4 by test5 +test line 5 by test5 +; End update by CARNet package test5 -- DO NOT DELETE THIS LINE! + + + mohican = the last + +# Begin update by CARNet package test3 -- DO NOT DELETE THIS LINE! +Block inserted by test3 +# End update by CARNet package test3 -- DO NOT DELETE THIS LINE! + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n +# Begin update by CARNet package test1 -- DO NOT DELETE THIS LINE! +Block inserted by test1 +# End update by CARNet package test1 -- DO NOT DELETE THIS LINE! +# Begin update by CARNet package test4 -- DO NOT DELETE THIS LINE! +Block inserted by test4 +# End update by CARNet package test4 -- DO NOT DELETE THIS LINE! diff --git a/test/test6.ok b/test/test6.ok new file mode 100644 index 0000000..1e6e4b7 --- /dev/null +++ b/test/test6.ok @@ -0,0 +1,29 @@ +This is the top of the test file for cp-update maintenance team +so they can check is everything ok with the script. Empty line: + +# Here we have a piece that looks like a comment +; following line says that you should not delete it: + -- DO NOT DELETE THIS LINE! + +[samba] + brasil = de Janeiro + + + mohican = the last + + +options { + something +more; +} + +# update this + +# Begin update by CARNet package broken +this is for compatibility with older version which did not add + -- DO NOT DELETE THIS LINE! +string after the package name +# End update by CARNet package broken + +# Begin update by CARNet package broken2 + +It's the end of the file and guess what? This line does not end with \n -- 1.7.10.4