diff options
author | Jonas Smedegaard <dr@jones.dk> | 2002-02-28 14:09:04 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2002-02-28 14:09:04 +0000 |
commit | cafcd5d4368e57f162a641ed3f4835ecb5a6d391 (patch) | |
tree | 56166fbf16289d8b388cf0f1f9b51e28c3c4bdf9 |
Initial revision
-rwxr-xr-x | ccompile | 9 | ||||
-rwxr-xr-x | clcompile | 8 | ||||
-rwxr-xr-x | db-show | 14 | ||||
-rwxr-xr-x | deb-update.sh | 104 | ||||
-rwxr-xr-x | download | 3 | ||||
-rwxr-xr-x | download-force | 3 | ||||
-rwxr-xr-x | download-public | 37 | ||||
-rwxr-xr-x | download-test | 3 | ||||
-rwxr-xr-x | host-update | 29 | ||||
-rwxr-xr-x | kernellab | 510 | ||||
-rwxr-xr-x | lbxinit | 86 | ||||
-rwxr-xr-x | localezlanguage | 15 | ||||
-rwxr-xr-x | localsyncthis | 92 | ||||
-rwxr-xr-x | macusers | 52 | ||||
-rwxr-xr-x | make-suexec-for-home | 37 | ||||
-rwxr-xr-x | mksshauth | 23 | ||||
-rwxr-xr-x | navi | 38 | ||||
-rwxr-xr-x | papd2cups | 2 | ||||
-rwxr-xr-x | parselog | 217 | ||||
-rwxr-xr-x | sux | 312 | ||||
-rwxr-xr-x | upload | 3 | ||||
-rwxr-xr-x | upload-force | 3 | ||||
-rwxr-xr-x | upload-test | 3 | ||||
-rwxr-xr-x | user | 18 | ||||
-rwxr-xr-x | xmc | 13 | ||||
-rwxr-xr-x | xpine | 4 | ||||
-rwxr-xr-x | xsh | 137 |
27 files changed, 1775 insertions, 0 deletions
diff --git a/ccompile b/ccompile new file mode 100755 index 0000000..f5086ad --- /dev/null +++ b/ccompile @@ -0,0 +1,9 @@ +#!/bin/sh +# +# Wrapper around make, to colorize it's output and pipe through less. +# Jumps to the first gcc error that occurs during the build process. +# + +SIZE=`/bin/stty size` +$@ 2>&1 | /usr/bin/colormake.pl $SIZE +exit $? diff --git a/clcompile b/clcompile new file mode 100755 index 0000000..99dfd16 --- /dev/null +++ b/clcompile @@ -0,0 +1,8 @@ +#!/bin/sh +# +# Wrapper around make, to colorize it's output and pipe through less. +# Jumps to the first gcc error that occurs during the build process. +# + +SIZE=`/bin/stty size` +$@ 2>&1 | /usr/bin/colormake.pl $SIZE | /usr/bin/less -r -pError @@ -0,0 +1,14 @@ +#!/usr/bin/perl -w +use strict; +use DB_File; + +die "syntax: $0 filename.db [...]\n" unless @ARGV; + +file: for my $file (@ARGV) { + my %h; + dbmopen(%h, $file, 0) || do { + warn "$0: dbmopen($file): $!\n"; + next file; + }; + print "$_ -> $h{$_}\n" for keys %h; +} diff --git a/deb-update.sh b/deb-update.sh new file mode 100755 index 0000000..55c5d44 --- /dev/null +++ b/deb-update.sh @@ -0,0 +1,104 @@ +#! /bin/sh + +if [ $# -eq 0 ]; then + echo "Usage: $(basename $0) AREAS BRANCHES DISTS ARCHS" + echo " (multiple values must \"be quoted\" to look as one on the commandline)" + echo "Example: $(basename $0) misc \"default unstable source\" 'potato sid' i386" + exit 1 +fi + +BASE="/debian/local" + +AREAS=$1 + +BRANCHES="$2" + +DISTS="$3" + +ARCHS="$4" + +for ARCH in $ARCHS; do + for DIST in $DISTS; do + for BRANCH in $BRANCHES; do + for AREA in $AREAS; do + case $BRANCH in + default) + DIR="dists/$DIST/$AREA/binary-$ARCH" + ECHODIR="dists/DIST/AREA/binary-ARCH" + ;; + source) + DIR="dists/$DIST/$AREA/source" + ECHODIR="dists/DIST/AREA/source" + ;; + *-source) + DIR="dists/$DIST/$BRANCH/$AREA/source" + ECHODIR="dists/DIST/BRANCH/AREA/source" + ;; + *) + DIR="dists/$DIST/$BRANCH/$AREA/binary-$ARCH" + ECHODIR="dists/DIST/BRANCH/AREA/binary-ARCH" + ;; + esac + echo "Checking directories..." + if [ -d $BASE/$DIR ]; then + echo " $ECHODIR looks fine." + else + echo "$0: $BASE/$DIR is not a directory" + echo + echo "AREA must exist." + echo + echo "BRANCH can be either default or source, special ones like unstable or private," + echo "or space-delimited combinations. Default is \"default\"." + echo + echo "DIST can be \"potato\", \"potato woody\" or similar. Default is \"stable\"" + echo + echo "ARCH is \"i386\" or whatever you have. Default is \"i386\"." + echo + echo "The corresponding directory must exist: $BASE/$ECHODIR." + exit 1 + fi + done + done + done +done +for ARCH in $ARCHS; do + for DIST in $DISTS; do + for BRANCH in $BRANCHES; do + for AREA in $AREAS; do + SRC="" + case $BRANCH in + default) + DIR="dists/$DIST/$AREA/binary-$ARCH" + ;; + source) + DIR="dists/$DIST/$AREA/source" + SRC="1" + ;; + *-source) + DIR="dists/$DIST/$AREA/$BRANCH/source" + SRC="1" + ;; + *) + DIR="dists/$DIST/$BRANCH/$AREA/binary-$ARCH" + ;; + esac + echo "Scanning $DIR..." + if [ $SRC ]; then + (cd $BASE; \ + dpkg-scansources $DIR /dev/null > $DIR/Sources; \ + touch $DIR/Sources; \ + rm -f $DIR/Sources.gz; \ + gzip -c $DIR/Sources > $DIR/Sources.gz; \ + ) + else + (cd $BASE; \ + dpkg-scanpackages $DIR /dev/null > $DIR/Packages; \ + touch $DIR/Packages; \ + rm -f $DIR/Packages.gz; \ + gzip -c $DIR/Packages > $DIR/Packages.gz; \ + ) + fi + done + done + done +done diff --git a/download b/download new file mode 100755 index 0000000..c2a33b2 --- /dev/null +++ b/download @@ -0,0 +1,3 @@ +#!/bin/sh + +localsyncthis --download $@ diff --git a/download-force b/download-force new file mode 100755 index 0000000..238803e --- /dev/null +++ b/download-force @@ -0,0 +1,3 @@ +#!/bin/sh + +download --force $@ diff --git a/download-public b/download-public new file mode 100755 index 0000000..5f0d720 --- /dev/null +++ b/download-public @@ -0,0 +1,37 @@ +#!/bin/sh + +if [ "x$1" = "x" ]; then + echo "usage: $0 host" + exit 1 + fi +pwd=`pwd` +here="$pwd" +#there="$1:$pwd" +there="$1::$pwd" +#opt="-v" + +case $(basename $0) in + download*) + src="$there" + dest="$here" + ;; + upload*) + src="$here" + dest="$there" + ;; + *) + echo "Unknown action \"$0\"" + exit 1 + ;; +esac +case "$0" in + *test) + opt="$opt -n" + ;; + *force) + opt="$opt -W" + ;; +esac + +#rsync -avrtz -e "ssh" --delete --force $opt $src/ $dest +echo rsync -atzv --partial --delete --force $src/ $dest/ diff --git a/download-test b/download-test new file mode 100755 index 0000000..135f873 --- /dev/null +++ b/download-test @@ -0,0 +1,3 @@ +#!/bin/sh + +download --test $@ diff --git a/host-update b/host-update new file mode 100755 index 0000000..a66fc12 --- /dev/null +++ b/host-update @@ -0,0 +1,29 @@ +#!/bin/sh + +usage () { + echo "Usage: $(basename $0) {host}" +} + +termwrapper () { + title="$title $titleopt" + echo $@ + echo xsh --title "Host update" --host $HOST $@ && touch /etc/local-LOCAL/machines/$args + xsh --title "Host update" --host $HOST $@ && touch /etc/local-LOCAL/machines/$args +} + +args='' +argc=0 +while [ $# -gt 0 ]; do + case $1 in + -*) usage; exit 1;; + *) args="$args $1"; argc=$(($argc+1));; + esac + shift +done +set -- $args + +if [ $argc -ne 1 ]; then + usage; exit 1; +fi +HOST=$1 +termwrapper "apt-get update; apt-get upgrade" diff --git a/kernellab b/kernellab new file mode 100755 index 0000000..55e4b37 --- /dev/null +++ b/kernellab @@ -0,0 +1,510 @@ +#!/usr/bin/perl -w +# +# kernellab - manage kernel configs for many machines easily +# Copyright (C) 1999 Tommi Virtanen <tv@havoc.fi> +# +# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +use strict; +use vars qw(@BASEPATH @SOURCES @ALANCOX @MODULES @IMAGES @CONFIG + $TEMPDIR $VERBOSE $DO_CONFIG); + +use vars qw($BUILDDIR $_host_regexp %FLAGS $MAKE_HEADERS $SOURCE_TYPE $PATCH_TYPE $KERNEL_REVISION + $WRITE_CONFIG $WRITE_IMAGE); +use File::Find; +use POSIX qw(strftime); + +my $_programname=$0; +$_programname=~s{^.*/}{}; +sub fail(@) { die "$_programname: @_\n" } +sub info(@) {print "$_programname: info: @_\n" if $VERBOSE} +sub debug(@) {print "$_programname: debug: @_\n" if $VERBOSE>1} + +do "$ENV{HOME}/.kernellab.conf" + or do '/etc/kernellab.conf' + or fail "config error; $@\n"; + +sub find_first_matching(&@) { + my $match = shift; + foreach (@_) { + return $_ if $match->($_); + } + return undef; +} + +$BUILDDIR = $TEMPDIR . '/kernellab.' . time() . '.' . $$; +@BASEPATH = map { append_slash($_) } grep {-d $_} @BASEPATH; +@SOURCES = + map { append_slash($_) } + grep {-d $_} + map { prefix_relative($_, @BASEPATH) } + @SOURCES; +@ALANCOX = + map { append_slash($_) } + grep {-d $_} + map { prefix_relative($_, @BASEPATH) } + @ALANCOX; +@MODULES = + map { append_slash($_) } + grep {-d $_} + map { prefix_relative($_, @BASEPATH) } + @MODULES; +@IMAGES = + map { append_slash($_) } + grep {-d $_} + map { prefix_relative($_, @BASEPATH) } + @IMAGES; +@CONFIG = + map { append_slash($_) } + grep {-d $_} + map { prefix_relative($_, @BASEPATH) } + @CONFIG; +$WRITE_IMAGE = find_first_matching {-w $_} @IMAGES + or fail "cannot find a writable place to store kernel images\n", + "perhaps you should run 'mkdir -p ~/kernellab/images'"; +$WRITE_CONFIG = find_first_matching {-w $_} @CONFIG + or fail "cannot find a writable place to store configs\n", + "perhaps you should run 'mkdir -p ~/kernellab/configs'"; +@BASEPATH and @SOURCES and @ALANCOX and @MODULES and @IMAGES and @CONFIG + or fail "some of the base directories did not exist. Check config"; + +$_host_regexp = '[a-z0-9.-]+'; + +sub usage() { + print <<EOF; +usage: $_programname [options] <host> [<version>[-ac<patchlevel>] [<module>..]] + where options are + -O, --official use official linux-x.x.x sources (default) + -D, --debian use Debian kernel-source-x.x.x sources + -a, --ac use Alan Cox patches (default) + -p, --pre use Linus Thorvalds pre-patches + --ben use Benjamin Herrenschmidt ben patches + --benh use Benjamin Herrenschmidt benh patches + --paulus use Paul Mackerras patches + -c, --configure always run menuconfig + -H, --headers also create a kernel-headers -package + -v, --verbose be more verbose + -h, --help show this help +EOF +} + +sub prefix($@;) { + my ($file)=shift; + return map {$_.$file} @_; +} + +sub prefix_relative($@;) { + my ($file) = shift; + return $file if $file=~m{^[/.]}; + return prefix($file, @_); +} + +sub append_slash($;) { + for (@_) { + return m{ /$ }x ? $_ : $_.'/' + } +} + +sub getdir($;) { + -d $_[0] or return (); + opendir(DIR, $_[0]) or fail "cannot open directory $_[0]; $!"; + my @r = readdir(DIR); + closedir DIR; + return @r; +} + +sub _find_filename(@) { # for filename_* functions + foreach (@_) { return $_ if -e $_ } + return undef; +} + +sub filename_kernel($$;) { + my ($basename, $file) = @_; + _find_filename(prefix($basename . '-' . $file . '.tar.bz2', @SOURCES), + prefix($basename . '-' . $file . '.tar.gz', @SOURCES)); +} + +sub filename_patch($$$;) { + my ($k, $patch, $patchver) = @_; + _find_filename(prefix('patch-' . $k . '-' . $patch . $patchver . '.bz2', @ALANCOX), + prefix('patch-' . $k . '-' . $patch . $patchver . '.gz', @ALANCOX)); +} + +sub filename_module($;) { + _find_filename(prefix($_[0] . '.tar.gz', @MODULES), + prefix($_[0] . '.tar.bz2', @MODULES)); +} + +sub max(@) { + my $max; + foreach (@_) { + $max=$_ if not defined $max or $max<$_; + } + return $max; +} + +sub source_basename($;) { + my ($source) = @_; + my ($basename); + for ($source) { + /^debian$/ and $basename='kernel-source', next; + /^official$/ and $basename='linux', next; + fail "unknown kernel source type \"$source\""; + } + return $basename; +} + +sub latest_kernel($$;) { + my ($basename, $patch) = @_; + my @kernels = + map {/^$basename-(\d+)\.(\d+)\.(\d+)\./; [$_,$1,$2,$3]} + grep {/^$basename-\d+\.\d+\.\d+\.tar\.(?:gz|bz2)$/} + map {getdir $_} @SOURCES; + my $a = max map {$_->[1]} @kernels; + defined $a or fail "cannot determine latest kernel version (1)"; + @kernels = grep {$_->[1] == $a} @kernels; + my $b = max map {$_->[2]} @kernels; + defined $b or fail "cannot determine latest kernel version (2)"; + @kernels = grep {$_->[2] == $b} @kernels; + my $c = max map {$_->[3]} @kernels; + defined $c or fail "cannot determine latest kernel version (3)"; + my $kernel = "$a.$b.$c"; + + my @patches = + map {/^patch-\d+\.\d+\.\d+.-$patch(\d+\w*)\./; [$_,$1]} + grep {/^patch-$a\.$b\.$c-$patch\d+\w*\.(?:gz|bz2)$/} + map {getdir $_} @ALANCOX; + my $patchver = max map {$_->[1]} @patches; + $kernel .= '-' . $patch . $patchver if defined $patchver; + + return $kernel; +} + +sub closest_config($$$;$;) { + my ($host, $kver, $patch, $patchver) = @_; + debug "finding closest config for $host $kver" + . (defined $patchver ? "-$patch$patchver" : ''); + my @configs; + foreach my $confdir (@CONFIG) { + foreach my $conffile (getdir $confdir) { + $conffile =~ + /^config-($_host_regexp)-(\d+)\.(\d+)\.(\d+)(?:-$patch(\d+)\w*)?$/ + or next; + $1 eq $host or next; + push @configs, [$confdir.$conffile, $1,$2,$3,$4,$5]; + } + } + + @configs = sort { #descending + $b->[2] <=> $a->[2] + || + $b->[3] <=> $a->[3] + || + $b->[4] <=> $a->[4] + || + $b->[5] <=> $a->[5] + # rely on (undef<=>0)==(0<=>undef)==0 + } @configs; + + return $configs[0]->[0]; +} + +sub next_revision($$$$;) { + my ($host, $kver, $date, $patch) = @_; + my @revs = + sort {$b<=>$a} + map { $_->[3] } + grep { + $_->[1] eq $host + and $_->[2] eq $date + } + map { + /^kernel-image- + (\d+\.\d+\.\d+(?:-$patch\d+\w*)?)_ # kernel version number + ($_host_regexp)\. # hostname + (\d\d\d\d\d\d\d\d)\. # yyyymmdd + (\d+)_ # revision + .*\.deb$ + /x; + [$1,$2,$3,$4] + } + grep {/^kernel-image-/} + map {getdir "$_/$host"} @IMAGES; + return "$host.$date.".($revs[0]+1) if @revs; + return "$host.$date.1"; +} + +sub extract($;) { + my $cmd; + for ($_[0]) { + /\.bz2$/ and $cmd='/usr/bin/bzip2', next; + /\.gz$/ and $cmd='/bin/gzip', next; + fail "unknown package format, file $_"; + } + system('/bin/tar', '-xf', $_[0], '--use-compress-program', $cmd) == 0 + or fail "unpacking $_[0] failed: $?"; +} + +sub apply_patch($;) { +debug "YOW!"; + my ($file) = @_; +debug "applying patch from file $file"; + my $zcat; + for ($file) { + /\.bz2$/ and $zcat='/usr/bin/bzcat', next; + /\.gz$/ and $zcat='/bin/zcat', next; + fail "unknown patch compression, file $_"; + } + system("$zcat \"$file\" | patch -p1") == 0 + or fail "applying patch $file failed: $?"; + find(sub {/\.rej$/ + and fail "patch $file failed for file $File::Find::name"}, + '.'); +} + +%FLAGS = ( + v => 'verbose', + verbose => sub {$VERBOSE++}, + h => 'help', + help => sub {usage(); exit(0)}, + c => 'configure', + config => 'configure', + configure => sub {$DO_CONFIG++}, + H => 'headers', + headers => sub {$MAKE_HEADERS++}, + O => 'official', + official => sub {$SOURCE_TYPE = 'official'}, + D => 'debian', + debian => sub {$SOURCE_TYPE = 'debian'}, + a => 'ac', + ac => sub {$PATCH_TYPE = 'ac'}, + p => 'pre', + pre => sub {$PATCH_TYPE = 'pre'}, + ben => sub {$PATCH_TYPE = 'ben'}, + benh => sub {$PATCH_TYPE = 'benh'}, + paulus => sub {$PATCH_TYPE = 'paulus'}, + revision => sub {$KERNEL_REVISION = undef}, + ); + +$SOURCE_TYPE = 'official'; +$PATCH_TYPE = 'ac'; +while (@ARGV and $ARGV[0] =~ /^-/) { + local $_ = shift; + s/^-//g; + if (/^-/) { # long opt + s/^-//g; + exists $FLAGS{$_} or usage(), exit(1); + $_=$FLAGS{$_} if not ref $FLAGS{$_}; + &{$FLAGS{$_}}; + } else { + foreach (split //, $_) { + exists $FLAGS{$_} or usage(), exit(1); + $_=$FLAGS{$_} if not ref $FLAGS{$_}; + &{$FLAGS{$_}}; + } + } +} + +my ($host, $version, @modules) = @ARGV; +defined $host and $host =~ /^$_host_regexp$/ or usage(), exit(1); + +my ($srcbasename) = source_basename($SOURCE_TYPE); +$version = latest_kernel($srcbasename, $PATCH_TYPE) if not defined $version; +my ($kernver, $kernver_first, $kernver_last, $patchver) = ($version =~ /^((\d+\.\d+\.)(\d+))(?:-$PATCH_TYPE(\d+\w*))?$/); +defined $kernver or fail "invalid kernel version $version"; +my ($kernfile); +if ($PATCH_TYPE eq 'pre') { + if ($kernver_last gt 0) { + $kernfile=filename_kernel($srcbasename, $kernver_first . ($kernver_last - 1)); + } else { + fail "pre-patched x.x.0 sources not supported in kernellab (can't guess earlier version)"; + } +} else { + $kernfile=filename_kernel($srcbasename, $kernver); +} +defined $kernfile or fail "kernel $kernver not found."; +info "kernel version=$kernver, filename=$kernfile"; +my $patchfile; +if (defined $patchver) { + $patchfile=filename_patch($kernver, $PATCH_TYPE, $patchver); + defined $patchfile or fail "$PATCH_TYPE patch $kernver-$PATCH_TYPE$patchver not found."; + info "$PATCH_TYPE patch $patchver, filename=$patchfile"; +} + +if (@modules) { + foreach (@modules) { + defined filename_module($_) + or fail "module $_ not found."; + } + info "modules=", join(', ', @modules); +} + +info "making build dir"; +mkdir $BUILDDIR, 0755 or fail "cannot mkdir build directory $BUILDDIR; $!"; +chdir $BUILDDIR or fail "cannot chdir to build directory $BUILDDIR; $!"; +info "extracting kernel sources"; +extract($kernfile); +if (-d "kernel-source-$kernver") { + info "creating a symlink from '$kernfile' to 'linux'"; + symlink ("kernel-source-$kernver",'linux') or fail "couldn't symlink 'kernel-source-$kernver' to 'linux'"; +} +-d 'linux' or fail "kernel source didn't unpack in 'linux'"; +chdir 'linux' or fail "cannot chdir to kernel subdir; $!"; + +if (defined $patchfile) { + info "applying $PATCH_TYPE patches"; + apply_patch($patchfile); +} + +# find closest config file, copy to .config +my $config=closest_config($host, $kernver, $PATCH_TYPE, $patchver); +if (defined $config) { #found one + info "using old config $config"; + system('cp', $config, '.config') == 0 + or fail "copying $config to .config failed; $?"; + system('make', 'oldconfig') == 0 + or fail "make oldconfig failed; $?"; +} +else {$DO_CONFIG++} # default settings -> configure + +if ($DO_CONFIG) { + system('make', 'menuconfig') == 0 + or fail "make menuconfig failed; $?"; + -e '.config' + or fail "menuconfig didn't write a config file, exiting.."; +} + +info "storing config"; +system('cp', '.config', + $WRITE_CONFIG . 'config-' . $host . '-' . $version) == 0 + or fail "copying .config to $WRITE_CONFIG failed; $?"; + +info "building kernel..."; +my $revision; +if (defined $KERNEL_REVISION) { + $revision = $KERNEL_REVISION ? "--revision $KERNEL_REVISION" : ""; +} else { + $revision = '--revision 1:'.next_revision($host, $kernver, + strftime('%Y%m%d',localtime()), $PATCH_TYPE); +} +system('fakeroot', '/usr/bin/make-kpkg', "$revision", + 'kernel_image') == 0 + or fail "make-kpkg kernel_image failed; $?"; + +if ($MAKE_HEADERS) { + info "building headers..."; + system('fakeroot', '/usr/bin/make-kpkg', + 'kernel_headers') == 0 + or fail "make-kpkg kernel_headers failed; $?"; +} + +chdir $BUILDDIR or fail "cannot chdir to build directory $BUILDDIR; $!"; + +info "extracting modules"; +#modules have to unpack into modules/<name> +foreach(@modules) { + extract filename_module $_; +} +if (@modules) { + # this check is too many false positives + -d 'modules' or fail "modules didn't unpack in 'modules'"; + + chdir 'linux' or fail "cannot chdir to kernel subdir; $!"; + + info "building modules..."; + $ENV{MODULE_LOC}=$BUILDDIR . '/modules'; +# $ENV{SRCTOP}=$BUILDDIR . '/linux'; +# $ENV{PWD}=$BUILDDIR . '/linux'; + system('fakeroot', '/usr/bin/make-kpkg', 'modules_image') == 0 + or fail "make-kpkg modules_image failed; $?"; +} + +chdir $BUILDDIR or fail "cannot chdir to build directory $BUILDDIR; $!"; +info "cleaning"; +system('rm', '-rf', 'linux', 'modules', 'kernel-source-*'); + +info "moving images to", $WRITE_IMAGE.$host; +-d "$WRITE_IMAGE/$host" + or mkdir "$WRITE_IMAGE/$host", 0755 + or fail "cannot make directory $WRITE_IMAGE/$host; $!"; + +my $image_exists_error = defined($KERNEL_REVISION) + ? "don't build with same revision twice!" + : "this can't happen!"; +foreach (grep {!/^\./} getdir '.') { + fail "$_ exists in $WRITE_IMAGE, $image_exists_error" + if -e "$WRITE_IMAGE/$host/$_"; + system('mv', '-i', $_, "$WRITE_IMAGE/$host/$_") == 0 + or fail "moving images failed on file $_: $!"; +} + +info "final cleaning"; +chdir '/' or fail "cannot chdir out from build dir; $!"; +rmdir $BUILDDIR or fail "cannot remove build dir $BUILDDIR; $!"; + +print "$_programname: Done.\n"; +exit(0); + +__END__ + +=head1 NAME + +kernellab - manage kernel configs for many machines easily + +=head1 SYNOPSIS + +kernellab [options] <host> [<version>[-ac<patchlevel>] [<module>..]] + +=head1 DESCRIPTION + +Kernellab helps you manage kernel configs for many heterogenous +machines. The configs are just stored in their normal format in +/var/state/kernellab/configs/config-<hostname>-<kernversion>[-ac<acver>]. +This and placing the kernel sources in a format accessible to +kernellab allows you to easily build a new kernel for your computers. + +Let's take an example: say you have 20 miscellanous machines working +as routers all over your network, with different ethernet cards and +other kernel options. Say someone discovers a denial of service +-attack in the linux TCP/IP stack. So you wait two hours till Alan Cox +puts out a new -ac42 patch, download this patch and put in to +/var/state/kernellab/alancox/patch-n.n.n-ac42.bz2. Now, all you need +to do to recompile the new, fixed, kernel for all your routers, is + + for a in router1 router2 router3 ...; do kernellab "$a"; done + +=head1 OPTIONS + + -O use official linux-x.x.x sources (default) + -D use Debian kernel-source-x.x.x sources + -a use Alan Cox patches (default) + -p use Linus Thorvalds pre-patches + --ben use Benjamin Herrenschmidt ben patches + --benh use Benjamin Herrenschmidt benh patches + --paulus use Paul Mackerras patches + -c always run make menuconfig + -H also create a kernel-headers -package + -v increase verbosity (can specify many times) + -h show usage + +=head1 BUGS + +This manpage. + +=head1 AUTHOR + +Tommi Virtanen <tv@havoc.fi> + +=cut @@ -0,0 +1,86 @@ +#!/bin/sh + +# Neat little script for easy use of lbxproxy with ssh. +# Based on this: http://www.gelatinous.com/aaron/tips/lbxproxy +# and adapted by Jonas Smedegaard <dr@jones.dk> + +# Changes from original script: +# * Instead of another custom script "remote-frame", simply open a +# terminal and quit lbxproxy on exit. +# * Ssh compression and X forwarding is explicitly enabled. +# * Path to lbxinit is not hardcoded - just place this script somewhere +# in your path. +# * Get rid of "l" and "r" options (more intuitively in my opinion). + +# The following is from the web page: + +# How do I get lbxproxy to work with xauth/ssh? I can't connect. +# +# I kept trying to get lbxproxy to work over ssh, or even just with +# plain xauth. The only way I could make it work was with 'xhost +'. +# Finally I found an article by a Ted Rathkopf that showed me a way to +# make it work. If you are getting access control problems to your X +# server, here's what you need to do. +# +# Instead of just extracting your cookie or attempting to use the ones +# that ssh creates for you, you must get your real xauth key over to the +# target and fudge it so that the display entry is adjusted for the +# proxy (:63 by default). +# +# Example: +# +# On my DSL host, I use 'lbxinit r ' (r is for remote). This causes an +# 'lbxinit l ' on the remote host -- (l is for local). Yeah, there are +# easier ways to do this, but I wanted to have one script I could copy +# around. +# +# [the script itself] +# +# Hey, what's remote-frame? +# +# You need to start some long-running X app in the local section or else +# lbxproxy gets huffy and quits after the first client exits, even +# though the man page says otherwise. So, I open up a frame of my emacs +# on that host. +# +# I turned off compression with -nocomp because ssh does its own stream +# compression. You might need to enable it with the -C argument to ssh. +# +# The last thing I did was make an 'lbx' shell alias that sets my +# DISPLAY environment to :63. +# +# Last modified: 2000/11/17 + +PATH=${PATH}:/usr/X11R6/bin +SCREEN=63 + +# Empty hostname indicates executed on target host +if [ "x$1" = "x" -a $# -ge 3 -a $# -le 4 ]; then + LHOST=$2 + COOKIE=$3 + PRG=$4 + [ "x$PRG" = "x" ] && PRG="/usr/bin/x-terminal-emulator" + + xauth add $LHOST:$SCREEN $COOKIE + xauth add :$SCREEN $COOKIE + + lbxproxy :$SCREEN -nocomp -terminate -compstats > $HOME/.lbxproxy 2>&1 & + export DISPLAY=":63" + exec $PRG +# $PRG + +elif [ $# -ge 1 -a $# -le 3 ]; then + RHOST=$1 + RCOOKIE=`xauth list $DISPLAY | awk '{print $2 " " $3}'` + SSHOPTS="-C -X" + [ "x$3" != "x" ] && SSHOPTS="$SSHOPTS -l $3" +# ssh -f $RHOST bin/lbxinit l $RHOST "'$RCOOKIE'" + ssh $SSHOPTS -f $RHOST lbxinit "''" $RHOST "'$RCOOKIE'" "'$2'" +else + echo "Usage: lbxinit host [prg [uid]]" + echo " (and internally: lbxinit '' host protocol cookie [prg])" + echo + echo "Example: lbxinit an.other.host 'xterm +aw' js" + echo " (where 'js' is the login name on an.other.host)" + exit 1 +fi diff --git a/localezlanguage b/localezlanguage new file mode 100755 index 0000000..e996446 --- /dev/null +++ b/localezlanguage @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +for lang in $@; do + if [ -f $lang.tgz ]; then + echo "output file $lang.tgz already exists - exiting" + exit 1 + fi +done +for lang in $@; do +# find * -type f | grep -v cache | grep "$lang" | sed "s!$lang/.*!$lang/!" | uniq | sort +# find * -type f | grep -v cache | grep "$lang" | tar -czf $lang.tgz --mode 0644 + tar -czf $lang.tgz --mode 0644 `find * -type f | grep -v cache | grep "$lang"` +done diff --git a/localsyncthis b/localsyncthis new file mode 100755 index 0000000..b6a725d --- /dev/null +++ b/localsyncthis @@ -0,0 +1,92 @@ +#!/bin/sh + +# Initial setup +prg=$(basename $0) +copyright="(C) 2000-2002 Jonas Smedegaard <dr@jones.dk>" +V='' +action='' +hosts='' +rsync_opts='-avrtz --delete --force' +ssh_opts='' +localdir='' +remotedir='' + +args='' +while [ $# -gt 0 ]; do + case $1 in + -h|--help) echo "$prg, $copyright + +usage: $prg [<options>] host [path [path...]] + or: $prg [<options>] \"host [host...]\" [path [path...]] +where options are the following: + -v|--verbose Verbose mode + --host Hostname(s) of remote host(s) + -l|--localdir Local base directory (only if path specified) + -r|--remotedir Remote base directory + -p|--port ssh port number + --ssh-opts Arbitrary ssh options + -h|--help This help text + -* Arbitrary rsync options + +--upload mirrors from local dir to remote dir. +--download does the opposite. +If no path specified, current working directory is used." + exit 0 + ;; + -v|--verbose) V=1; rsync_opts="$rsync_opts --progress --stats";; + --download) action=download;; + --upload) action=upload;; + --test|--dry-run) rsync_opts="$rsync_opts --dry-run";; + --force|--whole-file) rsync_opts="$rsync_opts --whole-file";; + --host) hosts="$hosts $2"; shift;; + -l|--localdir) localdir="$2"; shift;; + -r|--remotedir) remotedir="$2"; shift;; + -p|--port) ssh_opts="$ssh_opts -p $2"; shift;; + --ssh-opts) ssh_opts="$ssh_opts $2"; shift;; + -*) rsync_opts="$rsync_opts $1";; + *) args="$args $1";; + esac + shift +done +set -- $args + +if [ -z $hosts ]; then + hosts=$1 + shift +fi +if [ -z $hosts ]; then + echo "$prg error: Hostname missing!" + echo + $0 --help + exit 1 +fi + +if [ "x$1" = "x" ]; then + workdirs=`pwd` + localdir='' +else + workdirs=$@ + fi + +for workdir in $workdirs; do + for host in $hosts; do + here="$localdir$workdir" + there="$host:$remotedir$workdir" + + case $action in + download) + rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here + [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here + ;; + upload) + rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there + [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there + ;; + *) echo "$prg error: You need to specify either --upload or --download!" + echo + $0 --help + exit 1 + ;; + esac + done +done diff --git a/macusers b/macusers new file mode 100755 index 0000000..ac930d2 --- /dev/null +++ b/macusers @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# Written for linux; may have to be modified for your brand of Unix. + +$MAC_PROCESS="afpd"; +$PS_STR="-ef"; +$ASIP_PORT="afpovertcp"; + +# Change to 0 if you don't have lsof +$LSOF=1; + +if ($LSOF == 1 ) +{ + open(LSOF,"lsof -i | grep $ASIP_PORT |"); + + while(<LSOF>) + { + if ($_ !~ /$ASIP_PORT/) + { + next; + } + $_=~/\w+\s+(\d+).*->([\w-]+).*/; + $pid=$1; $host=$2; + $mac{$pid}=$host; + } + + close(LSOF); + print "PID UID Usercode Name Logintime Mac\n"; +} +else +{ + print "PID UID Usercode Name Logintime\n"; +} + +open(PS," ps $PS_STR |") || die "cannot do ps"; + +while(<PS>) +{ + if ($_ !~ /$MAC_PROCESS/ ) + { + next; + } + $_=~ /\s*(\w+)\s+(\d+)\s+(\d+)\s+\d+\s+([\d\w:]+)/; + $user=$1; $pid=$2; $ppid=$3; $time=$4; + if ($ppid != 1) + { + ($t,$t,$uid,$t,$t,$t,$name,$t,$t)=getpwnam($user); + printf "%-8d %-8d %-8s %-20s %-9s %s\n",$pid,$uid,$user,$name,$time,$mac{$pid}; + } +} + +close(PS); diff --git a/make-suexec-for-home b/make-suexec-for-home new file mode 100755 index 0000000..5cffab4 --- /dev/null +++ b/make-suexec-for-home @@ -0,0 +1,37 @@ +#!/bin/bash +#CONFARGS = --target=apache --with-layout=Debian \ +# --enable-suexec --suexec-caller=www-data \ +# --suexec-docroot=/var/www \ +# --suexec-logfile=/var/log/apache/suexec.log \ +# --without-confadjust --without-execstrip \ +# --enable-shared=max --enable-rule=SHARED_CHAIN \ +# --enable-module=most --enable-module=status \ +# --enable-module=log_referer --enable-module=log_agent \ +# --enable-module=auth_db \ +# --activate-module=src/modules/extra/mod_macro.c + +HTTPD_USER="www-data" +LOG_EXEC="/var/log/apache/suexec.log" +DOC_ROOT="/home" + +set -e + +S=/usr/share/doc/apache-common +B=`pwd`/suexec-build + +mkdir $B +#for f in suexec.c suexec.h ap_config.h; do +# zcat $S/$f.gz > $B/$f +#done +zcat $S/suexec.c.gz > $B/suexec.c +#cp suexec.c $B/suexec.c +zcat $S/ap_config.h.gz > $B/ap_config.h +zcat $S/suexec.h.gz > $B/suexec.h.orig + +cat $B/suexec.h.orig | sed \ + -e 's!^\(#define HTTPD_USER\).*$!\1 "www-data"!' \ + -e 's!^\(#define LOG_EXEC\).*$!\1 "/var/log/apache/suexec.log"!' \ + -e 's!^\(#define DOC_ROOT\).*$!\1 "/home"!' \ + > $B/suexec.h + +gcc -lm -lcrypt -ldb1 -ldb -ldl -I/usr/include/apache-1.3 -o $B/suexec $B/suexec.c diff --git a/mksshauth b/mksshauth new file mode 100755 index 0000000..f6b688e --- /dev/null +++ b/mksshauth @@ -0,0 +1,23 @@ +#!/bin/bash + +ssh_version=$1 +host=$2 + +case "$ssh_version" in + 1) + [ -f ~/.ssh/identity.pub ] || ssh-keygen + ssh $host "mkdir -p ~/.ssh && echo `cat ~/.ssh/identity.pub` >> ~/.ssh/authorized_keys" + ;; + 2|dsa) + [ -f ~/.ssh/id_dsa.pub ] || ssh-keygen -t dsa + ssh $host "mkdir -p ~/.ssh && echo `cat ~/.ssh/id_dsa.pub` >> ~/.ssh/authorized_keys2" + ;; + rsa) + [ -f ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa + ssh $host "mkdir -p ~/.ssh && echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/authorized_keys2" + ;; + *) + echo "Usage: $(basename $0) 1|2|dsa|rsa [user@]host" + exit 1 + ;; +esac @@ -0,0 +1,38 @@ +#!/bin/bash + +x='' + +help='' +args='' +argc=0 +while [ $# -gt 0 ]; do + case $1 in + --x|-x) x='1';; + --help|-h) help='1';; + *) args="$args $1"; argc=$(($argc+1));; + esac + shift +done +set -- $args + +usage () { + echo "Usage: $(basename $0) [-x] [{target}]" +} + +if [ "x$1" != "x" ]; then + target=$1 + shift +fi + +[ $# -gt 0 ] && help='1' + +if [ $help ]; then + usage + exit 1 +fi + +prg=/usr/bin/dos +[ $x ] && prg=/usr/bin/xdos +[ -x $prg ] || prg=/usr/bin/xdosemu + +$prg -f ~/$target/.dosemurc diff --git a/papd2cups b/papd2cups new file mode 100755 index 0000000..fa50398 --- /dev/null +++ b/papd2cups @@ -0,0 +1,2 @@ +#!/bin/sh +ps2ps /dev/stdin /dev/stdout | lp $@ diff --git a/parselog b/parselog new file mode 100755 index 0000000..9a7f00e --- /dev/null +++ b/parselog @@ -0,0 +1,217 @@ +#!/usr/bin/perl -w +# +# parselog.pl v1.0.1 +# +# Copyright (C)2000 Mark A. Bentley <bentlema@cs.umn.edu> +# +# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +############################################################################### +# +# This file was last modified: July 26, 2000 +# +# You can download the latest distribution from my web site: +# +# http://www.cs.umn.edu/~bentlema/projects +# +# For comments, suggestions, bug reports, or whatever, you may contact me +# via email: +# +# Mark A. Bentley <bentlema@cs.umn.edu> +# +############################################################################### +# +# +# DESCRIPTION +# +# This script is designed to accept log output from the Apache web server via +# the CustomLog directive. It will create a directory for each virtual host's +# logs, and will create a log file within this directory with the name based on +# the year, month and day. When the day changes, yesturday's log files will be +# closed, and new ones opened for today. +# +# +# USAGE +# +# You will need to create a CustomLog entry in your httpd.conf in the global +# section (not within a virtual host definition) like this: +# +# CustomLog "|/usr/local/bin/parselog" "[ %v %{%Y %m %d}t ] %h %l %u %t \"%r\" %s %b" +# +# The log formats definied within the brackets are absolutely necessary. +# The %v will expand to the virtualhost name, and the %t (with its internal +# format) will expand to the year, month, and day seperated by spaces. If you +# change any of the values within these brackes, you will have to modify the +# perl regular expression within the code below. The code will strip off these +# brackets and everything within and write the remaining common log to the +# appropriate directory and filename. +# +# This script will be fork/exec'ed with root perms if you've started apache as +# root. To be safe you should specify the absolute path to parselog in your +# CustomLog directive. +# +# You will also have to set the LOG_DIR in the configuration section below. +# +# This script will run with root privileges, so be careful if you decide to +# make changes or add functionality. +# + +# +# Configuration +# + +$LOG_DIR = "/var/log/apache"; + +$INPUT_SRC = STDIN; # you shouldn't need to change this. + +$LOG_FILE_PERMS = 0664; +$LOG_FILE_OWNER = "www-data"; +$LOG_FILE_GROUP = "www-data"; +$LOG_DIR_PERMS = 0775; +$LOG_DIR_OWNER = "www-data"; +$LOG_DIR_GROUP = "www-data"; + +$LOG_FILE_UID = ( getpwnam( $LOG_FILE_OWNER ))[2]; +$LOG_FILE_GID = ( getgrnam( $LOG_FILE_GROUP ))[2]; +$LOG_DIR_UID = ( getpwnam( $LOG_DIR_OWNER ))[2]; +$LOG_DIR_GID = ( getgrnam( $LOG_DIR_GROUP ))[2]; + +# +# Initialization +# + +my %HOSTNAME = (); # hash of hostnames we've seen already +my @OPEN_FH = (); # array of open filehandles for each hostname + +# +# Support routines +# + +sub flush { # Takes a filehandle + local($old) = select(shift); + $| = 1; print ""; $| = 0; + select($old); +} + +sub makenote { # Takes a string; + $note = shift; + $mylocaltime = localtime(time()); + print STDERR "[$mylocaltime] $0: ", $note, "\n"; +} + +# +# Main loop +# + +makenote("Starting up... PID: $$"); +makenote("INPUT_SRC = $INPUT_SRC"); + +if ( -d $LOG_DIR ) { + makenote("LOG_DIR = $LOG_DIR"); +} else { + makenote("Fatal Error: $LOG_DIR does not exist!"); + exit( 1 ); +} + + +makenote("Log Directory: " . + "$LOG_DIR_OWNER($LOG_DIR_UID) " . + "$LOG_DIR_GROUP($LOG_DIR_GID) $LOG_DIR_PERMS"); + +makenote("Log Files: " . + "$LOG_FILE_OWNER($LOG_FILE_UID) " . + "$LOG_FILE_GROUP($LOG_FILE_GID) $LOG_FILE_PERMS"); + +$previous_day = "0"; + +while( <$INPUT_SRC> ) { + m/^\[ (\S+) (\d+) (\d+) (\d+) \] (.*)/; # parse the log input here + + $log_hostname = $1; + $log_year = $2; + $log_month = $3; + $log_day = $4; + $log_common = $5; + + $log_pathname = "$LOG_DIR/$log_hostname"; + + # + # Did the day change? + # + + if ( $log_day ne $previous_day ) { + makenote("Day change."); + %HOSTNAME = (); + makenote("HOSTNAME hash reset."); + makenote("OPEN_FH: $#OPEN_FH"); + if ( $#OPEN_FH > 0 ) { + foreach $fh ( @OPEN_FH ) { + makenote("Closing $fh filehandle."); + close( $fh ); + } + } + @OPEN_FH = (); + makenote("OPEN_FH array reset."); + } + + # + # Have we seen this virtual host today? + # + + if ( ! $HOSTNAME{$log_hostname} ) { + + $HOSTNAME{$log_hostname} = 1; # mark host as seen + + # + # create hostname directory within LOG_DIR + # + + if ( ! -e $log_pathname ) { + makenote("mkdir: $log_pathname"); + mkdir( $log_pathname, $LOG_DIR_PERMS ); + chown( $LOG_DIR_UID, $LOG_DIR_GID, $log_pathname ); + chmod( $LOG_DIR_PERMS, $log_pathname ); + } + + # + # open logfile named year.month.day for appending + # using $log_hostname as the filehandle name + # + + my $current_log = "$log_pathname/$log_year.$log_month.$log_day"; + + makenote("open: $current_log"); + open( $log_hostname, ">> $current_log"); + chown( $LOG_FILE_UID, $LOG_FILE_GID, "$current_log" ); + chmod( $LOG_FILE_PERMS, "$current_log" ); + + # + # maintain a list of open filehandles + # + + push @OPEN_FH, $log_hostname; + + } + + # + # Write the log line to the appropriate log file. (Remember that + # the file handle name is the same as the hostname.) + # + + print $log_hostname $log_common, "\n"; + flush( $log_hostname ); + $previous_day = $log_day; +} + @@ -0,0 +1,312 @@ +#!/bin/sh + +# Written by Francois Gouget, fgouget@free.fr +# With many thanks to Daniel Martin and Falk Hueffner for their help + +# How to transfer cookies for root. See the sux_cookie_transfer variable +# for options. Note that use-xauthority may not work if home directories +# are on NFS. In such a case, change the default to copy-cookies. +sux_root_cookie_transfer="c" + + +usage() +{ + echo "usage: `basename $0` [-m|-p|--preserve-environment]" >&2 + echo " [--display display]" >&2 + echo " [--no-cookies|--copy-cookies|--use-xauthority]" >&2 + echo " [--untrusted] [--timeout x]" >&2 + echo " [-] [username [command]]" >&2 + exit 2 +} + + +## +# Process the sux options +sux_su_opts="" +sux_preserve="" +sux_got_minus=0 +# "" -> default, n -> no-cookies, c -> copy-cookies, x -> use-xauthority +sux_cookie_transfer="" +sux_username="" +sux_untrusted="" +sux_timeout="" +while [ $# -gt 0 ] +do + if [ "$sux_got_minus" = "1" ] + then + # Username follows "-" + sux_username="$1" + sux_su_opts="$sux_su_opts $1" + shift + # The remainder is the command to be executed + break + elif [ "$1" = "-" ] + then + # Last option before the username + sux_su_opts="$sux_su_opts $1" + sux_got_minus=1 + shift + elif [ "$1" = "-m" -o "$1" = "-p" -o "$1" = "--preserve-environment" ] + then + sux_preserve="1" + sux_su_opts="$sux_su_opts $1" + shift + elif [ "$1" = "--display" ] + then + if [ $# -lt 2 ] + then + echo "--display takes a display name as an argument" >&2 + usage # exits + fi + export DISPLAY="$2" + shift 2 + elif [ "$1" = "--no-cookies" ] + then + if [ -n "$sux_cookie_transfer" -a "$sux_cookie_transfer" != "n" ] + then + echo "--no-cookies is incompatible with --copy-cookies and --use-xauthority" >&2 + usage # exits + fi + sux_cookie_transfer="n" + shift + elif [ "$1" = "--copy-cookies" ] + then + if [ -n "$sux_cookie_transfer" -a "$sux_cookie_transfer" != "c" ] + then + echo "--copy-cookies is incompatible with --no-cookies and --use-xauthority" >&2 + usage # exits + fi + sux_cookie_transfer="c" + shift + elif [ "$1" = "--use-xauthority" ] + then + if [ -n "$sux_cookie_transfer" -a "$sux_cookie_transfer" != "x" ] + then + echo "--use-xauthority is incompatible with --no-cookies and --copy-cookies" >&2 + usage # exits + fi + sux_cookie_transfer="x" + shift + elif [ "$1" = "--untrusted" ] + then + sux_untrusted="untrusted" + shift + elif [ "$1" = "--timeout" ] + then + if [ $# -lt 2 ] + then + echo "--timeout takes a timeout in seconds" >&2 + usage # exits + fi + sux_timeout="timeout $2" + shift 2 + elif [ "$1" = "-?" ] + then + usage # exits + else + # First non-option is the username + sux_username="$1" + sux_su_opts="$sux_su_opts $1" + shift + # The remainder is the command to be executed + break + fi +done + + +## +# Get rid of the simple case +if [ -z "$DISPLAY" ] +then + # If DISPLAY is not set we can take a shortcut... + if [ -n "$sux_untrusted" -o -n "$sux_timeout" ] + then + echo "--untrusted and --timeout are only supported if DISPLAY is set" >&2 + usage #exits + fi + exec su $sux_su_opts "$@" +fi + + +## +# Do some option checking +if [ -z "$sux_username" ] +then + sux_username="root" +fi +if [ -z "$sux_cookie_transfer" ] +then + if [ "$sux_username" = "root" ] + then + sux_cookie_transfer="$sux_root_cookie_transfer" + else + sux_cookie_transfer="c" + fi +fi +if [ "$sux_cookie_transfer" = "x" -a "$sux_username" != "root" ] +then + echo "Only root can use --use-xauthority" >&2 + usage # exits +fi + + +## +# Create new cookies / retrieve the existing ones if necessary +if [ -n "$sux_untrusted" -o -n "$sux_timeout" ] +then + if [ "$sux_cookie_transfer" != "c" ] + then + echo "--no-cookies/--use-xauthority are incompatible with --untrusted/--timeout" >&2 + usage #exits + fi + + # Yeah, tempfile is a debian-specific command. Workarounds exist for + # other machines. If you do use a workaround, be certain that said + # workaround actually creates the new file, (via touch or similar) or + # xauth (below) will produce a pointless warning message. + sux_tmpfile=`tempfile -p sux` + xauth -q -f $sux_tmpfile generate $DISPLAY . $sux_untrusted $sux_timeout + sux_xauth_data=`xauth -f $sux_tmpfile nlist $DISPLAY` + rm -f $sux_tmpfile +fi + + +## +# Build the command to restore the cookies in the su +if [ "$sux_cookie_transfer" = "c" ] +then + # --copy-cookies case. We copy the cookie(s) using the xauth command. + + # If display is of the form "host:x.y" we may also need to get the + # cookies for "host/unix:x.y". + sux_unix_display=`echo $DISPLAY | sed -e 's#^\([a-zA-Z_.][a-zA-Z_.]*\):#\1/unix:#'` + if [ "$DISPLAY" = "$sux_unix_display" ] + then + sux_unix_display="" + fi + + # Get the cookies if we don't have them already + if [ -z "$sux_xauth_data" ] + then + # Get the cookies. Note that we may need to + sux_xauth_data=`xauth -q nlist $DISPLAY` + if [ -n "$sux_unix_display" ] + then + sux_xauth_data="$sux_xauth_data `xauth -q nlist $sux_unix_display`" + fi + fi + + # We highjack the TERM environment variable to transfer the cookies to the + # other user. We do this so that they never appear on any command line, and + # because TERM appears to be the only environment variable that is not + # reset by su. Then, as long as 'echo' is a shell builtin, these cookies + # will never appear as command line arguments which means noone will be + # able to intercept them (assuming they were safe in the first place). + sux_term="TERM='$TERM'" + # now we can store the script that will restore the cookies on the other + # side of the su, in TERM! + + # Remove the old cookies. They may cause trouble if we transfer only one + # cookie, e.g. an MIT cookie, and there's still a stale XDM cookie hanging + # around. + export TERM="xauth -q remove $DISPLAY 2>/dev/null;" + if [ -n "$sux_unix_display" ] + then + TERM="$TERM xauth -q remove $sux_unix_display;" + fi + + # Note that there may be more than one cookie to transfer, hence + # this loop + sux_i=0 + for sux_str in $sux_xauth_data + do + if [ $sux_i -eq 0 ] + then + TERM="$TERM echo $sux_str" + else + TERM="$TERM $sux_str" + fi + sux_i=`expr $sux_i + 1` + if [ $sux_i -eq 9 ] + then + TERM="$TERM | xauth nmerge - ;" + sux_i=0 + fi + done + sux_xauth_cmd="eval \$TERM;" + sux_xauthority="" +elif [ "$sux_cookie_transfer" = "x" ] +then + # --use-xauthority case. For root we can simplify things and simply + # access the original user's .Xauthority file. + sux_term="" + sux_xauth_cmd="" + if [ -n "$XAUTHORITY" ] + then + sux_xauthority="XAUTHORITY='$XAUTHORITY'" + else + sux_xauthority="XAUTHORITY='$HOME/.Xauthority'" + fi +else + # --no-cookies case. We just transfer $DISPLAY and assume the + # target user already has the necessary cookies + sux_term="" + sux_xauth_cmd="" + sux_xauthority="" +fi + + +## +# Marshall the specified command in an effort to support parameters that +# contain spaces. This should be enough to get commands like +# 'xterm -title "My XTerm"' to work. +sux_cmd="" +if [ $# -gt 0 ] +then + while [ $# -gt 0 ] + do + sux_cmd="$sux_cmd \"$1\"" + shift + done +elif [ "`basename $0`" = "suxterm" ] +then + # Start an xterm, useful for temporary cookies + sux_cmd="xterm" +else + # If no command is specified, start a shell + if [ $# -eq 0 ] + then + if [ "$sux_got_minus" = "1" ] + then + sux_cmd="sh -c \"exec -l \$SHELL\"" + else + sux_cmd="\$SHELL" + fi + fi +fi + + +## +# We would not want the other user to try and use our XAUTHORITY file. He +# wouldn't have the proper access rights anyway... +unset XAUTHORITY + + +## +# --preserve-environment special case +if [ -n "$sux_preserve" -a -n "$sux_xauth_cmd" ] +then + sux_home=`egrep "^$sux_username:" /etc/passwd | cut -d: -f6` + if [ -z "$sux_home" ] + then + echo "WARNING: --preserve-environment has been set, but no good value was found for XAUTHORITY, expect trouble" >&2 + else + export XAUTHORITY="$sux_home/.Xauthority" + fi +fi + + +## +# Execute su +exec su $sux_su_opts -c "$sux_xauth_cmd \ + exec env $sux_xauthority $sux_term DISPLAY='$DISPLAY' $sux_cmd;" @@ -0,0 +1,3 @@ +#!/bin/sh + +localsyncthis --upload $@ diff --git a/upload-force b/upload-force new file mode 100755 index 0000000..1103697 --- /dev/null +++ b/upload-force @@ -0,0 +1,3 @@ +#!/bin/sh + +upload --force $@ diff --git a/upload-test b/upload-test new file mode 100755 index 0000000..066a351 --- /dev/null +++ b/upload-test @@ -0,0 +1,3 @@ +#!/bin/sh + +upload --test $@ @@ -0,0 +1,18 @@ +#!/bin/sh + +ACTION=$1 +USERNAME=$2 + +[ x"$USERNAME" = "x" ] && ACTION='' + +case $ACTION in + add) + /usr/sbin/adduser "$USERNAME" + ;; + remove|del|delete) + /usr/sbin/userdel -r "$USERNAME" + ;; + *) + echo "$0 add|remove <username>" + ;; +esac @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ $# -eq 0 ]; then + xsh - mc +else + if [ $# -eq 1 -a "x$1" = "xsu" ]; then +# xsh - mc su + exec xsh - mc su + else +# xsh $@ mc + exec xsh $@ mc + fi +fi @@ -0,0 +1,4 @@ +#!/bin/sh + +#rxvt +sb -sl 500 -n "Pine" -title "Pine" -e pine & +exec rxvt +sb -sl 500 -n "Pine" -title "Pine" -e pine @@ -0,0 +1,137 @@ +#!/bin/bash + +SCRIPT=$(basename $0) + +function usage () { + echo "Usage: $SCRIPT [--x] [--verbose] [[--su |{user}@]{host}]" +} + +function termwrapper () { + PRG=$@ + title="$title $titleopt" + [ $V ] && echo $PRG + + # mc seem to have a bug separating upper- and lowercase with danish locale +# case $LANG in +# da_*) LANG=da;; +# esac + + if [ "x$PRG" != "x" ]; then +# if [ -z $PRG ]; then +# rxvt +sb -sl 500 -n "$title" -title "$title" -e $PRG & + exec rxvt +sb -sl 500 -n "$title" -title "$title" -e $PRG + else +# rxvt +sb -sl 500 -n "$title" -title "$title" & + exec rxvt +sb -sl 500 -n "$title" -title "$title" + fi +} + +# Initial setup +SU='' +X='' +V='' +SUHACK='' +HOST='' +USER='' +ssh_opts="-t" + +args='' +while [ $# -gt 0 ]; do + case $1 in + -su|su) SU=1;; + -suu|suu) SU=1; SUU=1;; # Become root indirectly through a regular user (same as local user if -u not used) + --user|-u) USER=$2; shift;; # Remote user allowed to switch to root + --x|-x|x) X=1; ssh_opts="$ssh_opts -X";; + --ssh2|-2) ssh_opts="$ssh_opts -2";; + --verbose|-v) V=1; ssh_opts="$ssh_opts -v";; + --port|-p) ssh_opts="$ssh_opts -p $2"; shift;; + --host|-h) HOST=$1;; + -) HOST="localhost";; + -*) usage; exit 1;; + root@*) HOST="$1"; SU=1; SUHACK=1;; + *) args="$args$1 ";; + esac + shift +done +set -- $args + +if [ -z $HOST ]; then + HOST=$1 + shift +fi +if [ -z $HOST ]; then + usage + exit 1 +fi + +prg_base=$1 +shift +prg_opts=$@ + +if [ "$X" -a "$SU" -a ! "$SUHACK" ]; then + args="root@$args" + SUHACK=1 +fi + +titleopt="[$HOST]" +if [ $HOST != "localhost" ]; then + ssh_opts="-C $ssh_opts" +fi + +[ $V ] && prg_opts="$prg_opts; sleep 4" + +## Don't open 2 shells if no program is run - Disabled for now (something wrong with the test...) +#if [ -z $prg_base -a -z $prg_opts -a -z $SUU ]; then +# title="$SCRIPT" +# prg_local='' +# prg_remote='' +#else + if [ -z $prg_base ]; then + title="$SCRIPT" + prg_base='/bin/bash' + else + title="$prg_base" + prg_opts_local="$prg_opts" + prg_opts_remote="$prg_opts" + fi + + # Special cases for specific programs + case $prg_base in + mc) prg_opts_remote="-s -c $prg_opts_remote" # Midnight Commander has an option for slow connections + ;; + esac + + prg_local="$prg_base $prg_opts_local" + if [ $SUU ]; then + prg_remote="echo -n 'Changing to root...: '; su $su_opts -c \"cd; $prg_base $prg_opts_remote\"" + else +# prg_remote="bash -i -c \"$prg_base $prg_opts_remote\"" +# prg_remote="bash -i -c \"test -e /etc/debian_version || export TERM=xterm; $prg_base $prg_opts_remote\"" + prg_remote="bash --login -i -c \"test -e /etc/debian_version || export TERM=xterm; $prg_base $prg_opts_remote\"" +# prg_remote="bash -i -c \"test -e /etc/debian_version || export TERM=xterm; $prg_base $prg_opts_remote\"" + fi +#fi + +if [ ! $SU ]; then + if [ $HOST = "localhost" ]; then + termwrapper $prg_local + else + termwrapper ssh $ssh_opts $HOST $prg_remote + fi +else + if [ "$SUHACK" ]; then +# termwrapper ssh $ssh_opts $HOST su $su_opts -c \"$prg_remote\" + termwrapper ssh $ssh_opts $HOST $prg_remote + else + titleopt="[$HOST root]" + if [ $SUU ]; then + if [ "x$USER" = "x" ]; then + termwrapper ssh $ssh_opts $HOST $prg_remote + else + termwrapper ssh $ssh_opts $USER@$HOST $prg_remote + fi + else + termwrapper ssh $ssh_opts root@$HOST $prg_remote + fi + fi +fi |