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