uupick revision 7c478bd95313f5f23a4c958a745db2134aa03244
98N/A#!/bin/sh
98N/A#
98N/A# CDDL HEADER START
98N/A#
98N/A# The contents of this file are subject to the terms of the
98N/A# Common Development and Distribution License, Version 1.0 only
98N/A# (the "License"). You may not use this file except in compliance
98N/A# with the License.
98N/A#
98N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98N/A# or http://www.opensolaris.org/os/licensing.
98N/A# See the License for the specific language governing permissions
98N/A# and limitations under the License.
98N/A#
98N/A# When distributing Covered Code, include this CDDL HEADER in each
98N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
98N/A# If applicable, add the following below this CDDL HEADER, with the
98N/A# fields enclosed by brackets "[]" replaced with your own identifying
98N/A# information: Portions Copyright [yyyy] [name of copyright owner]
98N/A#
98N/A# CDDL HEADER END
98N/A#
98N/A#
98N/A# Copyright 1999 Sun Microsystems, Inc. All rights reserved.
98N/A# Use is subject to license terms.
98N/A#
98N/A#ident "%Z%%M% %I% %E% SMI"
98N/A#
98N/Aexport IFS PATH
98N/AIFS="
98N/A"
98N/APATH="/usr/bin"
212N/A
98N/A# sys: system; user: login name; cdir: current directory;
98N/A# tdir: temporary directory; pu: PUBDIR/receive/user;
98N/Acdir=`pwd`
98N/Adir=""
98N/Aabs=""
156N/Asys=""
156N/Avar=""
156N/Avarto=""
156N/Avarfrom=""
98N/Atrap "exit 1" 1 2 13 15
98N/A
98N/A# mktmpdir - Create a private (mode 0700) temporary directory inside of /tmp
98N/A# for this process's temporary files. We set up a trap to remove the
98N/A# directory on exit (trap 0), and also on SIGHUP, SIGINT, SIGQUIT, and
194N/A# SIGTERM.
98N/A#
98N/Amktmpdir() {
98N/A tmpdir=/tmp/bnu.$$
156N/A trap '/usr/bin/rm -rf $tmpdir' 0 1 2 3 15
98N/A /usr/bin/mkdir -m 700 $tmpdir || exit 1
98N/A}
98N/A
101N/Amktmpdir
98N/A
191N/A# get options
145N/Awhile getopts s: FLAG; do
194N/A case $FLAG in
194N/A s) sys=$OPTARG
207N/A ;;
98N/A ?) gettext "Usage: uupick [-s sysname]\n" 1>&2;
98N/A exit 1
98N/A ;;
98N/A esac
98N/Adone
98N/Ashift `expr $OPTIND - 1`
98N/A
98N/Aif [ $# -gt 0 ]; then
98N/A gettext "Usage: uupick [-s sysname]\n" 1>&2;
98N/Afi
98N/A
98N/Auser=`id | sed -n "/^uid=[0-9]*(\([^)]*\)).*/s//\1/p"`
98N/A
98N/Aif test -z "$user"
98N/Athen gettext "User id required!\n" >&2; exit 1
98N/Afi
98N/A
98N/Apu=/var/spool/uucppublic/receive/$user
98N/Aif test -d $pu -a -s $pu
98N/Athen
98N/A for i in `/usr/bin/ls $pu`
98N/A do
98N/A if test $sys
98N/A then
98N/A if test $sys != $i; then continue; fi
98N/A fi
98N/A if test -d $pu/$i -a -s $pu/$i
98N/A then
98N/A cd $pu/$i
98N/A for j in `/usr/bin/ls -a`
140N/A do
154N/A if test $j = "." -o $j = ".."; then continue; fi
158N/A if test -d $j
161N/A then printf "`gettext 'from system %s: directory %s '`" $i $j
167N/A else printf "`gettext 'from system %s: file %s '`" $i $j
177N/A fi
183N/A while true
183N/A do
98N/A echo '? \c'
98N/A if read cmd dir
98N/A then
98N/A trap ": ;;" 1
98N/A case $cmd in
98N/A d)
98N/A rm -fr $j ; break ;;
98N/A "")
98N/A break ;;
98N/A# options m, a:
98N/A# If dir path begins with a slash, use full path for destination;
98N/A# otherwise, use path relative to current dir;
98N/A# default destination is current dir
98N/A#
98N/A# As files are transferred, put their names in $tmpdir/$$uupick.
98N/A# Only remove those named files from...receive/..dir if cmp
98N/A# verifies transfer took place. then find & remove directories
98N/A# (separate find is necessary because cpio -v doesn't print dir names)
98N/A a|m)
98N/A eval dir="$dir"
98N/A if test $dir
98N/A then abs=`expr "$dir" : '/.*'`
98N/A if test $abs != 0
98N/A then tdir=$dir
98N/A else tdir=$cdir/$dir
98N/A fi
98N/A else
98N/A tdir=$cdir
98N/A fi
98N/A if [ ! -d $tdir -o ! -w $tdir ]; then
98N/A printf "`gettext 'directory %s doesn't exist or isn't writable'`" $tdir >&2
98N/A continue
98N/A fi
98N/A if [ "$cmd" = "a" ]
98N/A then
98N/A find . -depth -print | \
98N/A grep -v '^\.$' > $tmpdir/$$uupick
98N/A level=2
167N/A else
98N/A find $j -depth -print > $tmpdir/$$uupick
98N/A level=1
156N/A fi
98N/A cpio -pdmu $tdir < $tmpdir/$$uupick
98N/A for k in `cat $tmpdir/$$uupick`
98N/A do
98N/A varto="$tdir/$k"
98N/A varfrom="$pu/$i/$k"
171N/A if test -f $varfrom; then
98N/A if cmp $varfrom $varto ; then
98N/A rm -f $varfrom
98N/A else
98N/A printf "`gettext 'file %s not removed'`" $varfrom >&2
98N/A fi
98N/A else
167N/A rmdir $varfrom 2>/dev/null
98N/A fi
194N/A done
98N/A rm -f $tmpdir/$$uupick
98N/A break $level;;
156N/A p)
156N/A if test -d $j
156N/A then find $j -print
98N/A elif test -s $j
98N/A then cat $j
98N/A fi;;
98N/A q)
98N/A break 3;;
98N/A !*)
98N/A ex=`expr "$cmd $dir" : '!\(.*\)'`
98N/A tdir=`pwd`
98N/A cd $cdir
98N/A sh -c "$ex"
98N/A cd $tdir
98N/A echo '!';;
98N/A *)
98N/A gettext "Usage: [d][m dir][a dir][p][q][cntl-d][!cmd][*][new-line]";;
98N/A esac
106N/A trap "exit 1" 1
98N/A else
98N/A break 3
98N/A fi
98N/A done
98N/A done
98N/A fi
98N/A done
194N/Afi
194N/A