Makefile: Use template.

This commit is contained in:
Ole Tange 2016-05-23 00:55:10 +02:00
parent 3320b47c91
commit 96f2c1c2cb
7 changed files with 427 additions and 236 deletions

View file

@ -1,31 +1,10 @@
all: blink/blink.1 histogram/histogram.1 upsidedown/upsidedown.1 tracefile/tracefile.1 timestamp/timestamp.1 rand/rand.1 rrm/rrm.1 goodpasswd/goodpasswd.1
CMD = blink histogram upsidedown tracefile timestamp rand rrm goodpasswd
blink/blink.1: blink/blink
pod2man blink/blink > blink/blink.1
all: blink/blink.1 goodpasswd/goodpasswd.1 histogram/histogram.1 rand/rand.1 rrm/rrm.1 timestamp/timestamp.1 tracefile/tracefile.1 upsidedown/upsidedown.1 wssh/wssh.1
goodpasswd/goodpasswd.1: goodpasswd/goodpasswd
pod2man goodpasswd/goodpasswd > goodpasswd/goodpasswd.1
%.1: %
pod2man $< > $@
histogram/histogram.1: histogram/histogram
pod2man histogram/histogram > histogram/histogram.1
rand/rand.1: rand/rand
pod2man rand/rand > rand/rand.1
rrm/rrm.1: rrm/rrm
pod2man rrm/rrm > rrm/rrm.1
timestamp/timestamp.1: timestamp/timestamp
pod2man timestamp/timestamp > timestamp/timestamp.1
tracefile/tracefile.1: tracefile/tracefile.pod
pod2man tracefile/tracefile.pod > tracefile/tracefile.1
upsidedown/upsidedown.1: upsidedown/upsidedown
pod2man upsidedown/upsidedown > upsidedown/upsidedown.1
wssh/wssh.1: wssh/wssh
#pod2man wssh/wssh > wssh/wssh.1
install:
mkdir -p /usr/local/bin

57
rrm/rclean Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/perl
use Digest::MD5::File qw(dir_md5_hex file_md5_hex url_md5_hex);
my $dir = shift || ".";
chdir $dir;
# Table of which files have a given size
open(IN,"-|",'find "`pwd`" -type f -printf "%s\t%p\0"') || die;
$/="\0";
my %size;
while(<IN>) {
chop; # Remove \0
my($s,$f) = split /\t/,$_;
push @{$size{$s}}, $f;
}
close IN;
# Read md5sum of removed files of a given size
my %rrm;
my $rrmfile = find_rrm_file(".") || ".rrm";
open(RRM,"<",$rrmfile) || die;
while(<RRM>) {
my($size,$md5,$file) = split /\t/,$_;
$rrm{0+$size}{$md5}++;
}
close RRM;
# Which existing files are the same size as some of the removed files?
for my $size (keys %rrm) {
for my $file (@{$size{$size}}) {
if(-e $file) {
my $md5 = Digest::MD5->new;
$md5->addpath($file);
# Do they have the same md5sum?
if($rrm{$size}{$md5->hexdigest}) {
# remove this
print "$file\n";
}
}
}
}
sub find_rrm_file {
my $dir = shift;
if(-r "$dir/.rrm") {
return "$dir/.rrm";
}
if(join(" ",stat $dir) eq join(" ",stat "$dir/..")) {
# root
return undef;
} else {
return find_rrm_file("$dir/..");
}
}

84
rrm/rrm Executable file
View file

@ -0,0 +1,84 @@
#!/usr/bin/perl
=encoding utf8
=head1 NAME
rrm - record and remove file
=head1 SYNOPSIS
B<rrm> I<file>
=head1 DESCRIPTION
B<rrm> records a file's MD5sum before removing it. It makes it
possible to automatically remove the file again should it ever
reappear.
This is useful for cleaning up photos where other partial backups of
the photos are later added: Photos removed once can easily be
identified and removed automatically if added by the backup.
=head1 EXAMPLE
B<rrm> IMG_2035.JPG
Restore a backup containing I<IMG_2035.JPG>.
B<rclean>
B<rclean> will find B<IMG_2035.JPG> as it has the same size and MD5sum
as an already removed file.
=head1 FILES
The file B<.rrm> contains the database of size, md5sum, and names of
the files. It is created in current directory if it cannot be found in
any of the (grand*)parent directories.
=head1 SEE ALSO
B<rclean>(1), B<rm>(1), B<md5sum>(1)
=cut
use Digest::MD5::File qw(dir_md5_hex file_md5_hex url_md5_hex);
my %size;
my %md5;
for my $file (@ARGV) {
if(-s $file > 0) {
$size{$file} = -s $file;
my $md5 = Digest::MD5->new;
$md5->addpath($file);
$md5{$file} = $md5->hexdigest;
}
}
$rrmfile = find_rrm_file(".") || ".rrm";
open(RRM,">>",$rrmfile) || die("Cannot write to $rrmfile.");
print RRM map { $size{$_}."\t".$md5{$_}."\t".$_."\0\n" } @ARGV;
close RRM;
unlink @ARGV;
sub find_rrm_file {
my $dir = shift;
if(-r "$dir/.rrm") {
return "$dir/.rrm";
}
if(join(" ",stat $dir) eq join(" ",stat "../$dir")) {
# We have reached root dir (.. = .)
return undef;
} else {
return find_rrm_file("../$dir");
}
}

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16)
.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
@ -38,6 +38,8 @@
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
@ -48,17 +50,24 @@
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
. if \nF \{
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
@ -124,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "TIMESTAMP 1"
.TH TIMESTAMP 1 "2014-02-14" "perl v5.14.2" "User Contributed Perl Documentation"
.TH TIMESTAMP 1 "2016-05-23" "perl v5.18.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@ -145,10 +154,10 @@ and now.
If \fB\-\-delta\fR is repeated: The time spent between each line.
.IP "\fB\-\-rfc\fR" 9
.IX Item "--rfc"
Output time format in \s-1RFC822\s0 (E.g. Wed, 30 Jan 2013 13:57:58 \s-1GMT\s0).
Output time format in \s-1RFC822 \s0(E.g. Wed, 30 Jan 2013 13:57:58 \s-1GMT\s0).
.IP "\fB\-\-iso\fR" 9
.IX Item "--iso"
Output time format in \s-1ISO8601\s0 (E.g. 2013\-01\-30T13:57:58.322).
Output time format in \s-1ISO8601 \s0(E.g. 2013\-01\-30T13:57:58.322).
.IP "\fB\-\-iso\-time\fR" 9
.IX Item "--iso-time"
Output time format in ISO8601/time only (E.g. 13:57:58.322).
@ -179,8 +188,8 @@ the Free Software Foundation; either version 3 of the License, or
at your option any later version.
.PP
This program is distributed in the hope that it will be useful,
but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of
\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the
but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of
\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE. \s0 See the
\&\s-1GNU\s0 General Public License for more details.
.PP
You should have received a copy of the \s-1GNU\s0 General Public License

View file

@ -1,5 +1,200 @@
#!/usr/bin/perl
=head1 NAME
tracefile - list files being accessed
=head1 SYNOPSIS
B<tracefile> [-aenu] I<command>
B<tracefile> [-aenu] -p I<pid>
=head1 DESCRIPTION
B<tracefile> will print the files being accessed by the command.
=head1 OPTIONS
=over 9
=item I<command>
Command to run.
=item B<-a>
List all files.
=item B<-e>
List only existing files.
=item B<-n>
List only non-existing files.
=item B<-p> I<pid>
Trace process id.
=item B<-u>
List only files once.
=back
=head1 EXAMPLES
=head2 EXAMPLE: Find the missing package
Assume you have a program B<foo>. When it runs it fails with: I<foo:
error: missing library>. It does not say with file is missing, but you
have a hunch that you just need to install a package - you just do not
know which one.
tracefile -n -u foo | apt-file -f search -
Here B<ls> tries to find B</usr/include/shisa.h>. If it fails,
B<apt-file> will search for which package it is in:
tracefile -n -u ls /usr/include/shisa.h | apt-file -f search -
=head1 REPORTING BUGS
Report bugs to <tange@gnu.org>.
=head1 AUTHOR
Copyright (C) 2012 Ole Tange, http://ole.tange.dk and Free
Software Foundation, Inc.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
=head2 Documentation license I
Permission is granted to copy, distribute and/or modify this documentation
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the file fdl.txt.
=head2 Documentation license II
You are free:
=over 9
=item B<to Share>
to copy, distribute and transmit the work
=item B<to Remix>
to adapt the work
=back
Under the following conditions:
=over 9
=item B<Attribution>
You must attribute the work in the manner specified by the author or
licensor (but not in any way that suggests that they endorse you or
your use of the work).
=item B<Share Alike>
If you alter, transform, or build upon this work, you may distribute
the resulting work only under the same, similar or a compatible
license.
=back
With the understanding that:
=over 9
=item B<Waiver>
Any of the above conditions can be waived if you get permission from
the copyright holder.
=item B<Public Domain>
Where the work or any of its elements is in the public domain under
applicable law, that status is in no way affected by the license.
=item B<Other Rights>
In no way are any of the following rights affected by the license:
=over 2
=item *
Your fair dealing or fair use rights, or other applicable
copyright exceptions and limitations;
=item *
The author's moral rights;
=item *
Rights other persons may have either in the work itself or in
how the work is used, such as publicity or privacy rights.
=back
=back
=over 9
=item B<Notice>
For any reuse or distribution, you must make clear to others the
license terms of this work.
=back
A copy of the full license is included in the file as cc-by-sa.txt.
=head1 DEPENDENCIES
B<tracefile> uses Perl, and B<strace>.
=head1 SEE ALSO
B<strace>(1)
=cut
use Getopt::Long;
$Global::progname = "tracefile";

View file

@ -1,197 +0,0 @@
#!/usr/bin/perl
=head1 NAME
tracefile - list files being accessed
=head1 SYNOPSIS
B<tracefile> [-aenu] I<command>
B<tracefile> [-aenu] -p I<pid>
=head1 DESCRIPTION
B<tracefile> will print the files being accessed by the command.
=head1 OPTIONS
=over 9
=item I<command>
Command to run.
=item B<-a>
List all files.
=item B<-e>
List only existing files.
=item B<-n>
List only non-existing files.
=item B<-p> I<pid>
Trace process id.
=item B<-u>
List only files once.
=back
=head1 EXAMPLES
=head2 EXAMPLE: Find the missing package
Assume you have a program B<foo>. When it runs it fails with: I<foo:
error: missing library>. It does not say with file is missing, but you
have a hunch that you just need to install a package - you just do not
know which one.
tracefile -n -u foo | apt-file -f search -
Here B<ls> tries to find B</usr/include/shisa.h>. If it fails,
B<apt-file> will search for which package it is in:
tracefile -n -u ls /usr/include/shisa.h | apt-file -f search -
=head1 REPORTING BUGS
Report bugs to <tange@gnu.org>.
=head1 AUTHOR
Copyright (C) 2012 Ole Tange, http://ole.tange.dk and Free
Software Foundation, Inc.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
=head2 Documentation license I
Permission is granted to copy, distribute and/or modify this documentation
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the file fdl.txt.
=head2 Documentation license II
You are free:
=over 9
=item B<to Share>
to copy, distribute and transmit the work
=item B<to Remix>
to adapt the work
=back
Under the following conditions:
=over 9
=item B<Attribution>
You must attribute the work in the manner specified by the author or
licensor (but not in any way that suggests that they endorse you or
your use of the work).
=item B<Share Alike>
If you alter, transform, or build upon this work, you may distribute
the resulting work only under the same, similar or a compatible
license.
=back
With the understanding that:
=over 9
=item B<Waiver>
Any of the above conditions can be waived if you get permission from
the copyright holder.
=item B<Public Domain>
Where the work or any of its elements is in the public domain under
applicable law, that status is in no way affected by the license.
=item B<Other Rights>
In no way are any of the following rights affected by the license:
=over 2
=item *
Your fair dealing or fair use rights, or other applicable
copyright exceptions and limitations;
=item *
The author's moral rights;
=item *
Rights other persons may have either in the work itself or in
how the work is used, such as publicity or privacy rights.
=back
=back
=over 9
=item B<Notice>
For any reuse or distribution, you must make clear to others the
license terms of this work.
=back
A copy of the full license is included in the file as cc-by-sa.txt.
=head1 DEPENDENCIES
B<tracefile> uses Perl, and B<strace>.
=head1 SEE ALSO
B<strace>(1)
=cut

View file

@ -1,5 +1,69 @@
#!/usr/bin/perl
=head1 NAME
wssh - wait for ssh port to open and then ssh
=head1 SYNOPSIS
B<wssh> [sshoptions] I<host>
=head1 DESCRIPTION
B<wssh> waits for port 22 to open and then B<ssh>s to the given I<host>.
=head1 EXAMPLE
B<wssh example.com>
=head1 EXIT STATUS
Returns the same as B<ssh>.
=head1 REPORTING BUGS
Contact Ole Tange <ole@tange.dk>.
=head1 AUTHOR
Copyright (C) 2012 Ole Tange <ole@tange.dk>.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<wssh> uses Perl, and B<w4it-for-port-open>.
=head1 SEE ALSO
B<ssh>(1)
=cut
use Getopt::Long;
my @argv = @ARGV;