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