Skip to content

Commit

Permalink
added more helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Oct 5, 2011
1 parent afd48a3 commit 3bcd452
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpanautoinstall
@@ -0,0 +1,3 @@
#!/usr/bin/perl
use CPAN;
CPAN::Shell->install(CPAN::Shell->r)
27 changes: 27 additions & 0 deletions diffbk
@@ -0,0 +1,27 @@
#!/bin/bash

function filediff {
BASE="`basename $FILE | sed -e 's,\(.bak\|.bk\|~\)$,,'`"
NEW="`dirname $FILE`/$BASE"
if [ "$FILE" = "$NEW" ]; then FILE=$(ls -t $FILE{~,.bak,.bak,.orig} 2>/dev/null | head -n1); fi
if [ -e "$FILE" -a -e "$NEW" ]; then
echo "$NEW" 1>&2
echo "diff -bu $FILE $NEW"
/usr/bin/diff -bu $FILE $NEW
fi
}

if [ "$#" -gt 1 -o -f "$1" ] # multiple args or a file: just these
then
for FILE in "$@"; do filediff; done
else
if [ "$#" -eq 0 ]
then APATH="." # no arg: recursively all origs
else APATH="$1" # or one arg: recursively all origs
fi
/usr/bin/find $APATH \( -name '*~' -o -name '*.ba?k' \) -print | sort | \
while read FILE
do
filediff
done
fi
29 changes: 29 additions & 0 deletions difforig
@@ -0,0 +1,29 @@
#!/bin/sh
b=
if [ "$1" = "-b" ]; then b="b"; shift; fi
echo "difforig $@"
echo ""
#/usr/bin/date +"%Y-%m-%d %H:%M:%S <rurban@x-ray.at>"
#echo ""
if [ "$#" -gt 1 -o -f "$1" ] # multiple args or a file: just these
then
for FILE in "$@"
do
ORIG="$FILE.orig"
echo "$FILE" 1>&2
echo "diff -u$b $ORIG $FILE"
/usr/bin/diff -u$b $ORIG $FILE
done
else
if [ "$#" -eq 0 ]
then APATH="." # no arg: recursively all origs
else APATH="$1" # or one arg: recursively all origs
fi
/usr/bin/find "$APATH" -name '*.orig' -print | /usr/bin/sort | while read FILE
do
NEW="`dirname $FILE`/`basename $FILE .orig`"
echo "$NEW" 1>&2
echo "diff -u$b $ORIG $FILE"
/usr/bin/diff -u$b $FILE $NEW
done
fi
62 changes: 62 additions & 0 deletions diffsize
@@ -0,0 +1,62 @@
#!/usr/bin/perl

use strict;
use vars;

sub usage {
print "ERROR: Missing argument\n";
print "diffsize [-n][-q] dir1 dir2\n";
print " print filenames with different filesizes in both directories\n";
print " -n \tignore not existing files in 2nd directory\n";
print " -q \tprint only filenames\n";
exit;
}

sub size {
my @s = stat(shift) or return -1;
return $s[7];
}

my $opt_n = 0;
my $opt_q = 0;
my $dir1 = shift || usage;
if ($dir1 eq '-n') {
$opt_n = 1;
$dir1 = shift || usage;
}
if ($dir1 eq '-q') {
$opt_q = 1;
$dir1 = shift || usage;
if ($dir1 eq '-n') {
$opt_n = 1;
$dir1 = shift || usage;
}
}
my $dir2 = shift || usage;

opendir(D1, $dir1) or die "cannot open $dir1: $!\n";
chdir $dir1;

while (my $f1 = readdir(D1)) {
next if -d $f1;
my $f2 = "$dir2/$f1";
my $s1 = size($f1);
my $s2 = size($f2);
if ($s2 < 0) {
if (! $opt_n) {
if ($opt_q) {
print $f1, "\n";
} else {
print "$f1\t$s1\t$s2\t$f2 does not exist\n";
}
}
} elsif ($s2 != $s1) {
if ($opt_q) {
print $f1, "\n";
} else {
print "$f1\t$s1\t$s2\t$f2\n";
}
}
}
closedir D1;
closedir D2;
3 changes: 3 additions & 0 deletions du-s
@@ -0,0 +1,3 @@
#!/bin/sh
# du sorted by size
perl -e '%h=map{/.\s/;7x(ord$&&10)+$`,$_}`du -h @ARGV`;print@h{sort%h}' $*

0 comments on commit 3bcd452

Please sign in to comment.