From: Sky Liu Date: Sun, 27 Jul 2014 22:22:49 +0000 (+0900) Subject: importing shar from NetBSD X-Git-Tag: v3.3.0~95 X-Git-Url: http://zhaoyanbai.com/repos/named.html?a=commitdiff_plain;h=e91d931d7dcfb0796d32e06157c841f1ac5b3b71;p=minix.git importing shar from NetBSD --- diff --git a/commands/Makefile b/commands/Makefile index 282c78d81..767fc4c55 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -22,7 +22,7 @@ SUBDIR= add_route arp ash at backup btrace \ profile progressbar pr_routes ps pwdauth \ ramdisk rarpd rawspeed rcp readclock \ remsync rget rlogin \ - rotate rsh rshd service setup shar \ + rotate rsh rshd service setup \ slip spell sprofalyze sprofdiff srccrc \ svclog svrctl swifi synctree sysenv \ syslogd tcpd tcpdp tcpstat telnet \ diff --git a/commands/shar/Makefile b/commands/shar/Makefile deleted file mode 100644 index f9ddb1248..000000000 --- a/commands/shar/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -PROG= shar -MAN= - -.include diff --git a/commands/shar/shar.c b/commands/shar/shar.c deleted file mode 100644 index 300d65a3e..000000000 --- a/commands/shar/shar.c +++ /dev/null @@ -1,70 +0,0 @@ -/* shar - make a shell archive Author: Michiel Husijes */ - -#include -#include - -static void error(char *progname, char *operation, char *filename); -int main(int argc, char **argv); - -int main(argc, argv) -int argc; -char *argv[]; -{ - int argn; - register int ch; - register FILE *fp; - int exitstatus; - char *filename; - - exitstatus = 0; - for (argn = 1; argn < argc; argn++) { - filename = argv[argn]; - if ((fp = fopen(filename, "r")) == NULL) { - error(argv[0], "opening ", filename); - exitstatus = 1; - } else { - fputs("echo x - ", stdout); - fputs(filename, stdout); - fputs("\nsed '/^X/s///' > ", stdout); - fputs(filename, stdout); - fputs(" << '/'\n", stdout); - while ((ch = getc(fp)) != EOF) { - putchar('X'); - putchar(ch); - while (ch != '\n') { - ch = getc(fp); - if (ch == EOF) break; - putchar(ch); - } - if (ch == EOF) break; - } - fputs("/\n", stdout); - if (ferror(fp)) { - error(argv[0], "reading ", filename); - exitstatus = 1; - } - if (fclose(fp) != 0) { - error(argv[0], "closing ", filename); - exitstatus = 1; - } - if (ferror(stdout)) break; /* lost already */ - } - } - fflush(stdout); - if (ferror(stdout)) { - error(argv[0], "writing ", "stdout"); - exitstatus = 1; - } - return(exitstatus); -} - -static void error(progname, operation, filename) -char *progname; -char *operation; -char *filename; -{ - fputs(progname, stderr); - fputs(": error ", stderr); - fputs(operation, stderr); - perror(filename); -} diff --git a/man/man1/Makefile b/man/man1/Makefile index d7eee4764..c41b16533 100644 --- a/man/man1/Makefile +++ b/man/man1/Makefile @@ -14,8 +14,7 @@ MAN= ash.1 at.1 \ ping.1 playwave.1 prep.1 \ profile.1 ps.1 rcp.1 recwave.1 \ remsync.1 rget.1 rlogin.1 rsh.1 rz.1 \ - shar.1 spell.1 \ - svc.1 svrctl.1 \ + spell.1 svc.1 svrctl.1 \ synctree.1 sysenv.1 sz.1 telnet.1 template.1 \ term.1 termcap.1 tget.1 time.1 \ truncate.1 umount.1 \ diff --git a/man/man1/shar.1 b/man/man1/shar.1 deleted file mode 100644 index 97a92e961..000000000 --- a/man/man1/shar.1 +++ /dev/null @@ -1,44 +0,0 @@ -.TH SHAR 1 -.SH NAME -shar \- shell archiver -.SH SYNOPSIS -\fBshar \fIfile ...\fR -.br -.de FL -.TP -\\fB\\$1\\fR -\\$2 -.. -.de EX -.TP 20 -\\fB\\$1\\fR -# \\$2 -.. -.SH EXAMPLES -.TP 20 -.B shar *.c >s -# Collect C programs in shell archive -.TP 20 -.B sh diff --git a/usr.bin/shar/shar.1 b/usr.bin/shar/shar.1 new file mode 100644 index 000000000..0b07ec864 --- /dev/null +++ b/usr.bin/shar/shar.1 @@ -0,0 +1,101 @@ +.\" $NetBSD: shar.1,v 1.12 2012/03/22 07:58:19 wiz Exp $ +.\" +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)shar.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt SHAR 1 +.Os +.Sh NAME +.Nm shar +.Nd create a shell archive of files +.Sh SYNOPSIS +.Nm +.Ar +.Sh DESCRIPTION +.Nm +writes an +.Xr sh 1 +shell script to the standard output which will recreate the file +hierarchy specified by the command line operands. +Directories will be recreated and must be specified before the +files they contain (the +.Xr find 1 +utility does this correctly). +.Pp +.Nm +is normally used for distributing files by +.Xr ftp 1 +or +.Xr mail 1 . +.Sh EXAMPLES +To create a shell archive of the program +.Xr ls 1 +and mail it to Rick: +.Bd -literal -offset indent +cd ls +shar `find . -print` \&| mail -s "ls source" rick +.Ed +.Pp +To recreate the program directory: +.Bd -literal -offset indent +mkdir ls +cd ls +\&... +\*[Lt]delete header lines and examine mailed archive\*[Gt] +\&... +sh archive +.Ed +.Sh SEE ALSO +.Xr compress 1 , +.Xr mail 1 , +.Xr tar 1 , +.Xr uuencode 1 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.4 . +.Sh BUGS +.Nm +makes no provisions for special types of files or files containing +magic characters. +.Sh SECURITY CONSIDERATIONS +It is easy to insert trojan horses into +.Nm +files. +It is strongly recommended that all shell archive files be examined +before running them through +.Xr sh 1 . +Archives produced using this implementation of +.Nm +may be easily examined with the command: +.Bd -literal -offset indent +egrep -v '^[X#]' shar.file +.Ed diff --git a/usr.bin/shar/shar.sh b/usr.bin/shar/shar.sh new file mode 100644 index 000000000..473507886 --- /dev/null +++ b/usr.bin/shar/shar.sh @@ -0,0 +1,72 @@ +#!/bin/sh - +# +# $NetBSD: shar.sh,v 1.3 2005/06/30 02:36:35 perry Exp $ +# +# Copyright (c) 1990, 1993 +# The Regents of the University of California. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)shar.sh 8.1 (Berkeley) 6/6/93 +# + +if [ $# -eq 0 ]; then + echo 'usage: shar file ...' + exit 1 +fi + +cat << EOF +# This is a shell archive. Save it in a file, remove anything before +# this line, and then unpack it by entering "sh file". Note, it may +# create directories; files and directories will be owned by you and +# have default permissions. +# +# This archive contains: +# +EOF + +for i +do + echo "# $i" +done + +echo "#" + +for i +do + if [ -d $i ]; then + echo "echo c - $i" + echo "mkdir -p $i > /dev/null 2>&1" + else + echo "echo x - $i" + echo "sed 's/^X//' >$i << 'END-of-$i'" + sed 's/^/X/' $i + echo "END-of-$i" + fi +done +echo exit +echo "" + +exit 0