xref: /titanic_44/usr/src/cmd/bnu/uupick (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#!/bin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
26*7c478bd9Sstevel@tonic-gate#
27*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate#
29*7c478bd9Sstevel@tonic-gateexport IFS PATH
30*7c478bd9Sstevel@tonic-gateIFS="
31*7c478bd9Sstevel@tonic-gate"
32*7c478bd9Sstevel@tonic-gatePATH="/usr/bin"
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate# sys: system; user: login name;  cdir: current directory;
35*7c478bd9Sstevel@tonic-gate# tdir: temporary directory; pu: PUBDIR/receive/user;
36*7c478bd9Sstevel@tonic-gatecdir=`pwd`
37*7c478bd9Sstevel@tonic-gatedir=""
38*7c478bd9Sstevel@tonic-gateabs=""
39*7c478bd9Sstevel@tonic-gatesys=""
40*7c478bd9Sstevel@tonic-gatevar=""
41*7c478bd9Sstevel@tonic-gatevarto=""
42*7c478bd9Sstevel@tonic-gatevarfrom=""
43*7c478bd9Sstevel@tonic-gatetrap "exit 1" 1 2 13 15
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate# mktmpdir - Create a private (mode 0700) temporary directory inside of /tmp
46*7c478bd9Sstevel@tonic-gate# for this process's temporary files.  We set up a trap to remove the
47*7c478bd9Sstevel@tonic-gate# directory on exit (trap 0), and also on SIGHUP, SIGINT, SIGQUIT, and
48*7c478bd9Sstevel@tonic-gate# SIGTERM.
49*7c478bd9Sstevel@tonic-gate#
50*7c478bd9Sstevel@tonic-gatemktmpdir() {
51*7c478bd9Sstevel@tonic-gate        tmpdir=/tmp/bnu.$$
52*7c478bd9Sstevel@tonic-gate        trap '/usr/bin/rm -rf $tmpdir' 0 1 2 3 15
53*7c478bd9Sstevel@tonic-gate        /usr/bin/mkdir -m 700 $tmpdir || exit 1
54*7c478bd9Sstevel@tonic-gate}
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gatemktmpdir
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate# get options
59*7c478bd9Sstevel@tonic-gatewhile getopts s: FLAG; do
60*7c478bd9Sstevel@tonic-gate	case $FLAG in
61*7c478bd9Sstevel@tonic-gate	s)	sys=$OPTARG
62*7c478bd9Sstevel@tonic-gate		;;
63*7c478bd9Sstevel@tonic-gate	?)	gettext "Usage: uupick [-s sysname]\n" 1>&2;
64*7c478bd9Sstevel@tonic-gate		exit 1
65*7c478bd9Sstevel@tonic-gate		;;
66*7c478bd9Sstevel@tonic-gate	esac
67*7c478bd9Sstevel@tonic-gatedone
68*7c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gateif [ $# -gt 0 ]; then
71*7c478bd9Sstevel@tonic-gate	gettext "Usage: uupick [-s sysname]\n" 1>&2;
72*7c478bd9Sstevel@tonic-gatefi
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gateuser=`id | sed -n "/^uid=[0-9]*(\([^)]*\)).*/s//\1/p"`
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gateif test -z "$user"
77*7c478bd9Sstevel@tonic-gatethen gettext "User id required!\n" >&2; exit 1
78*7c478bd9Sstevel@tonic-gatefi
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gatepu=/var/spool/uucppublic/receive/$user
81*7c478bd9Sstevel@tonic-gateif test -d $pu -a -s $pu
82*7c478bd9Sstevel@tonic-gatethen
83*7c478bd9Sstevel@tonic-gate    for i in `/usr/bin/ls $pu`
84*7c478bd9Sstevel@tonic-gate    do
85*7c478bd9Sstevel@tonic-gate	if test $sys
86*7c478bd9Sstevel@tonic-gate	then
87*7c478bd9Sstevel@tonic-gate	    if test $sys != $i;  then continue;  fi
88*7c478bd9Sstevel@tonic-gate	fi
89*7c478bd9Sstevel@tonic-gate	if test -d $pu/$i -a -s $pu/$i
90*7c478bd9Sstevel@tonic-gate	then
91*7c478bd9Sstevel@tonic-gate	    cd $pu/$i
92*7c478bd9Sstevel@tonic-gate	    for j in `/usr/bin/ls -a`
93*7c478bd9Sstevel@tonic-gate	    do
94*7c478bd9Sstevel@tonic-gate		if test $j = "." -o $j = ".."; then continue; fi
95*7c478bd9Sstevel@tonic-gate		if test -d $j
96*7c478bd9Sstevel@tonic-gate		then printf "`gettext 'from system %s: directory %s '`" $i $j
97*7c478bd9Sstevel@tonic-gate		else printf "`gettext 'from system %s: file %s '`" $i $j
98*7c478bd9Sstevel@tonic-gate		fi
99*7c478bd9Sstevel@tonic-gate		while true
100*7c478bd9Sstevel@tonic-gate		do
101*7c478bd9Sstevel@tonic-gate		    echo '? \c'
102*7c478bd9Sstevel@tonic-gate		    if read cmd dir
103*7c478bd9Sstevel@tonic-gate		    then
104*7c478bd9Sstevel@tonic-gate			trap ": ;;" 1
105*7c478bd9Sstevel@tonic-gate			case $cmd in
106*7c478bd9Sstevel@tonic-gate			d)
107*7c478bd9Sstevel@tonic-gate			    rm -fr $j ; break ;;
108*7c478bd9Sstevel@tonic-gate			"")
109*7c478bd9Sstevel@tonic-gate			    break ;;
110*7c478bd9Sstevel@tonic-gate# options m, a:
111*7c478bd9Sstevel@tonic-gate#	If dir path begins with a slash, use full path for destination;
112*7c478bd9Sstevel@tonic-gate#	otherwise, use path relative to current dir;
113*7c478bd9Sstevel@tonic-gate#	default destination is current dir
114*7c478bd9Sstevel@tonic-gate#
115*7c478bd9Sstevel@tonic-gate#	As files are transferred, put their names in $tmpdir/$$uupick.
116*7c478bd9Sstevel@tonic-gate#	Only remove those named files from...receive/..dir if cmp
117*7c478bd9Sstevel@tonic-gate#	verifies transfer took place. then find & remove directories
118*7c478bd9Sstevel@tonic-gate#	(separate find is necessary because cpio -v doesn't print dir names)
119*7c478bd9Sstevel@tonic-gate			a|m)
120*7c478bd9Sstevel@tonic-gate			    eval dir="$dir"
121*7c478bd9Sstevel@tonic-gate			    if test $dir
122*7c478bd9Sstevel@tonic-gate			    then abs=`expr "$dir" : '/.*'`
123*7c478bd9Sstevel@tonic-gate				if test $abs != 0
124*7c478bd9Sstevel@tonic-gate				then tdir=$dir
125*7c478bd9Sstevel@tonic-gate				else tdir=$cdir/$dir
126*7c478bd9Sstevel@tonic-gate				fi
127*7c478bd9Sstevel@tonic-gate			    else
128*7c478bd9Sstevel@tonic-gate				tdir=$cdir
129*7c478bd9Sstevel@tonic-gate			    fi
130*7c478bd9Sstevel@tonic-gate			    if [ ! -d $tdir -o ! -w $tdir ]; then
131*7c478bd9Sstevel@tonic-gate				printf "`gettext 'directory %s doesn't exist or isn't writable'`" $tdir >&2
132*7c478bd9Sstevel@tonic-gate				continue
133*7c478bd9Sstevel@tonic-gate			    fi
134*7c478bd9Sstevel@tonic-gate			    if [ "$cmd" = "a" ]
135*7c478bd9Sstevel@tonic-gate			    then
136*7c478bd9Sstevel@tonic-gate				find . -depth -print | \
137*7c478bd9Sstevel@tonic-gate				grep -v '^\.$' > $tmpdir/$$uupick
138*7c478bd9Sstevel@tonic-gate				level=2
139*7c478bd9Sstevel@tonic-gate			    else
140*7c478bd9Sstevel@tonic-gate				find $j -depth -print > $tmpdir/$$uupick
141*7c478bd9Sstevel@tonic-gate				level=1
142*7c478bd9Sstevel@tonic-gate			    fi
143*7c478bd9Sstevel@tonic-gate			    cpio -pdmu $tdir < $tmpdir/$$uupick
144*7c478bd9Sstevel@tonic-gate			    for k in `cat $tmpdir/$$uupick`
145*7c478bd9Sstevel@tonic-gate			    do
146*7c478bd9Sstevel@tonic-gate				varto="$tdir/$k"
147*7c478bd9Sstevel@tonic-gate				varfrom="$pu/$i/$k"
148*7c478bd9Sstevel@tonic-gate				if test -f $varfrom; then
149*7c478bd9Sstevel@tonic-gate				    if cmp $varfrom $varto ; then
150*7c478bd9Sstevel@tonic-gate					rm -f $varfrom
151*7c478bd9Sstevel@tonic-gate				    else
152*7c478bd9Sstevel@tonic-gate					printf "`gettext 'file %s not removed'`" $varfrom >&2
153*7c478bd9Sstevel@tonic-gate				    fi
154*7c478bd9Sstevel@tonic-gate				else
155*7c478bd9Sstevel@tonic-gate				    rmdir $varfrom 2>/dev/null
156*7c478bd9Sstevel@tonic-gate				fi
157*7c478bd9Sstevel@tonic-gate			    done
158*7c478bd9Sstevel@tonic-gate			    rm -f $tmpdir/$$uupick
159*7c478bd9Sstevel@tonic-gate			    break $level;;
160*7c478bd9Sstevel@tonic-gate			p)
161*7c478bd9Sstevel@tonic-gate			    if test -d $j
162*7c478bd9Sstevel@tonic-gate			    then find $j -print
163*7c478bd9Sstevel@tonic-gate			    elif test -s $j
164*7c478bd9Sstevel@tonic-gate				then cat $j
165*7c478bd9Sstevel@tonic-gate			    fi;;
166*7c478bd9Sstevel@tonic-gate			q)
167*7c478bd9Sstevel@tonic-gate			    break 3;;
168*7c478bd9Sstevel@tonic-gate			!*)
169*7c478bd9Sstevel@tonic-gate			    ex=`expr "$cmd $dir" : '!\(.*\)'`
170*7c478bd9Sstevel@tonic-gate			    tdir=`pwd`
171*7c478bd9Sstevel@tonic-gate			    cd $cdir
172*7c478bd9Sstevel@tonic-gate			    sh -c "$ex"
173*7c478bd9Sstevel@tonic-gate			    cd $tdir
174*7c478bd9Sstevel@tonic-gate			    echo '!';;
175*7c478bd9Sstevel@tonic-gate			*)
176*7c478bd9Sstevel@tonic-gate			    gettext "Usage: [d][m dir][a dir][p][q][cntl-d][!cmd][*][new-line]";;
177*7c478bd9Sstevel@tonic-gate			esac
178*7c478bd9Sstevel@tonic-gate			trap "exit 1" 1
179*7c478bd9Sstevel@tonic-gate		    else
180*7c478bd9Sstevel@tonic-gate			break 3
181*7c478bd9Sstevel@tonic-gate		    fi
182*7c478bd9Sstevel@tonic-gate		done
183*7c478bd9Sstevel@tonic-gate	    done
184*7c478bd9Sstevel@tonic-gate	fi
185*7c478bd9Sstevel@tonic-gate    done
186*7c478bd9Sstevel@tonic-gatefi
187