]> git.hungrycats.org Git - linux/commitdiff
Import these utility wrappers into git, since I've been maintaining
authorZygo Blaxell <zblaxell@dos.hungrycats.org>
Thu, 20 Nov 2008 20:49:28 +0000 (15:49 -0500)
committerZygo Blaxell <zblaxell@faye.furryterror.org>
Fri, 30 Jan 2009 21:08:31 +0000 (16:08 -0500)
them ad-hoc for years.  Also give them a much-needed update and some
error detection.

zygo/do [new file with mode: 0755]
zygo/make-kernel [new file with mode: 0755]
zygo/new-kernel [new file with mode: 0755]
zygo/rename-kernel [new file with mode: 0755]
zygo/trash [new file with mode: 0755]

diff --git a/zygo/do b/zygo/do
new file mode 100755 (executable)
index 0000000..0612790
--- /dev/null
+++ b/zygo/do
@@ -0,0 +1,23 @@
+#!/bin/bash
+set -axP
+CONCURRENCY_LEVEL="${CONCURRENCY_LEVEL-40}"
+PATH="$PWD/zygo:$PATH"
+
+# Rename the kernel directory
+rename-kernel
+
+# Reread $PWD
+cd .
+
+# trash ../modules/linux-wlan-ng*
+
+trash debian
+
+new-kernel
+
+# (cd ../modules && apt-get source linux-wlan-ng)
+
+make oldconfig
+yes '' | fakeroot make-kernel "$@"
+
+mv -vi ../modules/*.deb ../
diff --git a/zygo/make-kernel b/zygo/make-kernel
new file mode 100755 (executable)
index 0000000..289e937
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -xP
+rev=zb${PWD##*-zb}
+
+# Reread $PWD
+cd .
+
+(
+       set -a
+       MODULE_LOC=$PWD/../modules 
+       set +a
+       make-kpkg modules_clean clean
+       make-kpkg --revision $rev binary && make-kpkg modules_image
+) 2>&1 | tee make.log
diff --git a/zygo/new-kernel b/zygo/new-kernel
new file mode 100755 (executable)
index 0000000..775b2d0
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+set -xP
+cd ../modules || exit 1
+
+# Exception to naming convention
+trash drbd
+tar xjf /usr/src/drbd8.tar.bz2
+
+for x in *; do
+       if [ -d /usr/src/modules/"$x" ]; then
+               rsync -avx --delete /usr/src/modules/"$x"/. "$x"
+       elif [ -s /usr/src/"$x".tar.bz2 ]; then
+               trash "$x"
+               (cd .. && tar xjf /usr/src/"$x".tar.bz2)
+       elif [ -s /usr/src/"$x"-source.tar.bz2 ]; then
+               trash "$x"
+               (cd .. && tar xjf /usr/src/"$x"-source.tar.bz2)
+       elif [ -s /usr/src/"$x".tar.gz ]; then
+               trash "$x"
+               (cd .. && tar xzf /usr/src/"$x".tar.gz)
+       elif [ -s /usr/src/"$x"-source.tar.gz ]; then
+               trash "$x"
+               (cd .. && tar xzf /usr/src/"$x"-source.tar.gz)
+       else
+               echo "Can't figure out where module '$x' came from"
+       fi
+done
diff --git a/zygo/rename-kernel b/zygo/rename-kernel
new file mode 100755 (executable)
index 0000000..f12ea0b
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash -x
+set -aP
+
+# Reread $PWD
+cd .
+
+for x in ../linux-source*/; do
+       [ -d "$x" ] || continue
+
+       x="${x%/}";
+       eval "$(
+               egrep '^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)' "$x"/Makefile | sed -e 's/[: ()]//g'
+       )"
+
+       [ -z "$EXTRAVERSION" ] && EXTRAVERSION="$1"
+       [ -z "$EXTRAVERSION" ] && exit 1
+
+       kname="linux-source-$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION-zb`date +%Y%m%d%H`"
+       mv -vi "$x" "../$kname"
+       ln -sfnv "$kname" ../LS
+done
+
diff --git a/zygo/trash b/zygo/trash
new file mode 100755 (executable)
index 0000000..d84ef39
--- /dev/null
@@ -0,0 +1,194 @@
+#!/usr/bin/perl
+# $Id: trash,v 1.1 1997/08/05 02:23:55 cvsconf Exp $
+
+# Trash utility suite
+# Zygo Blaxell, 96/05/29
+# Version 1.3
+# 'mkdir' command deals with symlinks correctly, and renames non-directories
+# aside.
+
+# Version 1.2
+# Fixed problems with exit status in 'trash' modes.
+
+# Version 1.1, 96/05/03
+# Fixed so it works on Solaris and Perl4
+
+# Version 1.0
+# Finally released...
+
+# Usage:  Name this file one of the following:
+
+# trash                - 'trash file' moves 'file' into a trash directory.
+# sneaky-trash - trashes file, then creates a symlink to it.
+# placebo-trash - trashes file, then creates a 0-length file with the
+#                same permissions.
+# untrash      - attempt to recover a file from trash directory.
+#                 note that if you trash a file with the same name
+#                twice, this may not work.
+# lstrash      - 'lstrash -RFC' lists contents of all existing trash 
+#                directories using 'ls -RFC' (or your own flags).
+
+# Environment variables:
+# TRASH_NO_AUTOCONFIG - don't try to use 'df' to find a good place to
+#                       make trash directories if this is set.
+# TRASH_PREFER - format: directory=value:directory=value:...
+#                example: /home/you/.trash=2:/tmp=-2:.trash=-1
+#                Sets preference values for directories.
+#                Autoconfigured preference values range from 0 to 1.
+#                Higher preference values will be used first.
+#                A preference value that is non-numeric (such as "off")
+#                will prevent the directory from ever being used.
+# TRASH_UMASK - override the default umask for the trashcan directory.
+#               The default umask is 077.
+
+# A 'trash directory' is a directory that holds the trash
+# files.  This software assumes that you have some other software that
+# will empty this trash directory.  If you don't, simply use 'rm -rf'
+# on the trash directory itself.  If you want software that deletes
+# the oldest files in a directory hierarchy when disk space drops below
+# a minimum threshold, try my program 'filereaper'.
+
+# CONFIGURATION
+# Edit the 'df' command between `` characters below to be the fastest
+# possible invocation for your system.  'df --no-sync -xnfs' for GNU df.
+
+# Trashcan directory privacy settings - use '077' to deny all access,
+#                                           '027' allow group read access
+#                                           '022' allow world read access
+
+$umask=umask($ENV{'TRASH_UMASK'} || 077);
+
+for $component (split(/\:+/o,$ENV{'TRASH_PREFER'})) {
+       ($dir,$pref)=($component =~ m:^([^=]+)=([^=]+)$:oi);
+       $dir =~ s:/+:/:go;
+       if (defined($pref)) {
+               if (!(-d $dir)) {
+                       print STDERR "Warning:  TRASH_PREFER refers to $dir, which is not a directory\n";
+                       $pref='no';
+               }
+               $free{$dir}=$pref;
+       } else {
+               print STDERR "Warning:  Couldn't grok $component in TRASH_PREFER variable\n";
+       }
+}
+
+$userid=getpwuid("$<") || ":$<:";
+$trashdir=".trash.$userid";
+
+# Automatic configuration - comment this out if you don't want it.
+unless ($ENV{'TRASH_NO_AUTOCONFIG'}) {
+       @df=split(/\n/o,`df -k`);
+       for (@df) {
+               ($fs,$blocks,$used,$avail,$cap,$mp)=split(' ',$_);
+               ($dir="$mp/tmp/$trashdir") =~ s:/+:/:go;
+               next if defined($free{$dir});
+               next unless $blocks =~ /^\d+$/o;
+                $created{$dir}=mkdir($dir,0755);
+                next if (-l $dir);
+                next if !(-d _);
+                next if !(-O _);
+               $free{$dir}=$avail;
+       }
+}
+
+foreach (keys(%free)) {
+       delete $free{$_} if ($free{$_} =~ m/^[^\d]*$/o);
+}
+
+@filesystems=sort { $free{$b} <=> $free{$a} } (keys(%free));
+print STDERR "Trash directories in preference order: @filesystems\n";
+
+($curdir=`pwd`) =~ s/\n$//o;
+$curdir='.' unless $curdir =~ m:^/:o;
+
+$attempts=0;
+$successes=0;
+if ($0 =~ /untrash$/oi) {
+       for $arg (@ARGV) {
+               $attempts++;
+               $arg="$curdir/$arg" unless $arg =~ m:^/:o;
+               $arg =~ s:/+$::o;
+               for $fs (@filesystems) {
+                       eval {
+                               $trasharg="$fs/$arg";
+                               $trasharg =~ s:/+:/:go;
+                               next unless ((-l $trasharg) || (-e _));
+                               print STDERR "$trasharg -> $arg\n";
+                               rename($trasharg,$arg) || (system("mv",$trasharg,$arg) && die "mv: exit status $?");
+                               $successes++;
+                               last;
+                       };
+                       print STDERR $@ if $@;
+                       last unless $@;
+               }
+       }
+} elsif ($0 =~ /lstrash$/io) {
+       exec("ls",@ARGV,@filesystems);
+} else {
+       for $arg (@ARGV) {
+               $attempts++;
+               unless ((-l $arg) || (-e _)) {
+                       print STDERR "$arg: not found: $!\n";
+                       next;
+               }
+               ($dev,$ino,$mode)=lstat(_);
+               $arg="$curdir/$arg" unless $arg =~ m:^/:o;
+               $arg =~ s:/+$::o;
+               for $fs (@filesystems) {
+                       eval {
+                               @argcomp=split(m:/+:o,$arg);
+                               pop(@argcomp) while $#argcomp>=0 && !length($argcomp[$#argcomp]);
+                               $argfile=pop(@argcomp);
+                               $argdir=join("/",@argcomp);
+                               $trashargdir="$fs/$argdir";
+                               $trasharg="$fs/$arg";
+                               $trasharg =~ s:/+:/:go;
+                               $trashargdir =~ s:/+:/:go;
+                               $trashnewarg=$trasharg;
+                               $trashnewarg =~ s/(\.(\d+))?$/".".($2+1)/oe while ((-l $trashnewarg) || (-e _));
+                               if ($trashnewarg ne $trasharg) {
+                                       print STDERR "$trasharg -> $trashnewarg\n";
+                                       rename($trasharg,$trashnewarg) || warn "rename: $trasharg -> $trashnewarg: $!";
+                               }
+                               eval {
+                                       unless (! (-l "$trashargdir") && (-d _)) {
+                                               $path_so_far=($fs =~ m:^/:o) ? '' : '.';
+                                               for (split(/\/+/o,$trashargdir)) {
+                                                       ($newdir="$path_so_far/$_") =~ s:/+:/:go;
+                                                       $path_so_far=$newdir;
+                                                       next if (! (-l $path_so_far) && (-d _));
+                                                       $trashnewpath=$path_so_far;
+                                                       $trashnewpath =~ s/(\.(\d+))?$/".".($2+1)/oe while ((-l $trashnewarg) || (-e _));
+                                                       if ($trashnewpath ne $path_so_far) {
+                                                               print STDERR "$path_so_far -> $trashnewpath\n";
+                                                               rename($path_so_far,$trashnewpath) || warn "rename: $path_so_far -> $trashnewpath: $!";
+                                                       }
+                                                       print STDERR "mkdir $newdir\n";
+                                                       mkdir($newdir,0700) || die "mkdir $newdir: $!" unless (-d "$newdir/");
+                                               }
+                                       }
+                               }; 
+                               print STDERR $@ if $@;
+                               next if $@;
+                               print STDERR "$arg -> $trasharg\n";
+                               rename($arg,$trasharg) || (system("mv",$arg,$trasharg) && die "mv: exit status $?");
+                               if ($0 =~ /sneaky-trash$/oi) {
+                                       print STDERR "$arg <- $trasharg\n";
+                                       symlink($trasharg,$arg) || die "symlink $trasharg <- $arg: $!";
+                               } elsif ($0 =~ /placebo-trash$/oi) {
+                                       print STDERR "touch $arg\n";
+                                       open(PLACEBO,">>$arg") || die "open $arg: $!";
+                                       close(PLACEBO);
+                                       chmod($mode,$arg) || die "chmod $arg: $!";
+                               }
+                               $successes++;
+                               last;
+                       };
+                       print STDERR $@ if $@;
+                       last unless $@;
+               }
+       }
+}
+
+exit(1) if $successes != $attempts;
+exit(0);