From: kraehe@bakunin.north.de (Michael Kraehe) Subject: [SOURCE] tpinst Tape-Installation for SLS Date: 1 Apr 1993 14:43:47 GMT
Hy folks,
so for posting this source in a newsgroup, but I've no FTP-Access :-( So
ist my only way to distribute this small thing ! I think it'll help lot
of people who have a SCSI-Tape and wanna switch to a new SLS :-) If you
have FTP-Access, save it on yr favorite server and mail me where it can
be found !
By Michael.
#! /bin/sh
echo tpinst.shar 1.2
echo x - README.tpinst
sed '/^X/s///' > README.tpinst << '/'
XHy folks,
X
Xthis is Tape-Installation for Linux-SLS, it now dont need to patch doinstall
Xor sysinstall, but uses a cheap trick by executing doinst.sh.
X
XHow to make it ?
X
X- First copy SLS-a1 and a2 to disk by rawwrite or dd.
X
X- Format 2 disks (one for the new Kernel, and one for tpinst.)
X
X- Insert a disk for tpinst,
X Do a "make disk". (You need a Linux-Box to compile tarsh.c)
X
X- cd to your SLS-Directory insert a new tape and do a
X tar cvf /dev/rmt0 [abcdtxs]?/*.t??
X
X- Install SLS as usual but insert tpinst-disk instead of a3.
X You'll see a message like :
X Insert tape in SCSI drive !
X Insert the new Tape, and press CR.
X After all, you will be ask to insert b1, answer "q" because
X b? was on the tape :-) and continue as usual !
X
XBy Michael.
/
echo x - Makefile
sed '/^X/s///' > Makefile << '/'
Xa3 : src/usr/bin/tarsh src
X @if [ ! -d a3 ]; then mkdir a3 ; fi
X (cd src; tar cvf - usr install | gzip >../a3/tpinst.tpz)
X touch a3/diska3
X touch a3/install.end
X
Xsrc/usr/bin/tarsh : src/usr/src/tarsh.c
X cc -o src/usr/bin/tarsh src/usr/src/tarsh.c
X
Xdisk : a3
X mformat a:
X mcopy a3/* a:
X
Xshar :
X rm -f src/usr/bin/tarsh
X (shar README.tpinst Makefile; find src -exec shar {} \;) >tpinst.shar
/
# Check directory src
echo Directory src
[ ! -d src ] && mkdir src
# Check directory src/usr
echo Directory src/usr
[ ! -d src/usr ] && mkdir src/usr
# Check directory src/usr/bin
echo Directory src/usr/bin
[ ! -d src/usr/bin ] && mkdir src/usr/bin
echo x - src/usr/bin/tapeinstall
sed '/^X/s///' > src/usr/bin/tapeinstall << '/'
X[ x$INSTROOT = x ] && {
X export INSTROOT=/root
X export INSTTOPDIR=$INSTROOT/install
X export INSTDIR=$INSTTOPDIR/installed
X export INSTSCRDIR=$INSTTOPDIR/scripts
X export INSTSCRIPT=doinst.sh
X export COMPR=gzip
X }
X
X
Xb=`basename $1`
X
Xecho -n "installing $b ... "
X
Xif [ -e $INSTTOPDIR/$INSTSCRIPT ]; then
X rm $INSTTOPDIR/$INSTSCRIPT
Xfi
X
Xecho $b >>$INSTTOPDIR/disks/`dirname $1`
X
Xcase $1 in
X*taz) e=.taz
X (cd $INSTROOT; $COMPR -dc | tar -xvlpf - | sed "/\/$/d" ) > $INSTDIR/`basename $b $e`
X ;;
X*tar.Z) e=.tar.Z
X (cd $INSTROOT; $COMPR -dc | tar -xvlpf - | sed "/\/$/d" ) > $INSTDIR/`basename $b $e`
X ;;
X*tpz) e=.tpz
X (cd $INSTROOT; $COMPR -dc | tar -xvlpf - | sed "/\/$/d" ) > $INSTDIR/`basename $b $e`
X ;;
X*tar) e=.tar
X (cd $INSTROOT; cat | tar -xvlpf - | sed "/\/$/d" ) > $INSTDIR/`basename $b $e`
X ;;
X*disk*) cat > /dev/null;
X ;;
X*) cat > $INSTTOPDIR/$b
X ;;
Xesac
X
Xif [ -f $INSTTOPDIR/$INSTSCRIPT ]; then
X echo -n "fixing ... "
X (cd $INSTROOT; sh $INSTTOPDIR/$INSTSCRIPT -install;)
X mv $INSTTOPDIR/$INSTSCRIPT $INSTSCRDIR/`basename $1 .$2`;
Xfi
X
Xecho done
/
# Check directory src/usr/src
echo Directory src/usr/src
[ ! -d src/usr/src ] && mkdir src/usr/src
echo x - src/usr/src/tarsh.c
sed '/^X/s///' > src/usr/src/tarsh.c << '/'
X/* ---------------------------------------------------------------------
X tarsh.c (c) 91 Michael Koehne
X
X
X Dies ist ein Tar-Extrakter, der fuer jede Datei Prozesse
X erzeugt, welche die Datei als stdin und den Namen als Argument
X bekommen. Ziemlich praktisch wenn auf einem Tape ein Tar
X mit vielen tar's ist :-)
X
X Usage : tarsh /dev/TAPE shell-sript
X lets try a : tarsh /dev/fd0 "wc -c;echo $*"
X
X--------------------------------------------------------------------- */
X
X#include <string.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <fcntl.h>
X#include <errno.h>
X#include <sys/stat.h>
X#include <memory.h>
X
X/* ------------------------------------------------------------------ */
X/* Dieser Header stammt aus Minix von Tannenbaum */
X
X/* The <tar.h> header is used with the tape archiver, tar. */
X
X#ifndef _TAR_H
X#define _TAR_H
X
X#define TBLOCK 512
X#define NAMSIZ 100
X#define PFXSIZ 155
X
X#define TMODLEN 8
X#define TUIDLEN 8
X#define TGIDLEN 8
X#define TSIZLEN 12
X#define TMTMLEN 12
X#define TCKSLEN 8
X
X#define TMAGIC "ustar"
X#define TMAGLEN 6
X#define TVERSION "00"
X#define TVERSLEN 2
X#define TUNMLEN 32
X#define TGNMLEN 32
X#define TDEVLEN 8
X
X#define REGTYPE '0'
X#define AREGTYPE '\0'
X#define LNKTYPE '1'
X#define SYMTYPE '2'
X#define CHRTYPE '3'
X#define BLKTYPE '4'
X#define DIRTYPE '5'
X#define FIFOTYPE '6'
X#define CONTTYPE '7'
X
X#define TSUID 04000
X#define TSGID 02000
X#define TSVTX 01000
X
X#define TUREAD 00400
X#define TUWRITE 00200
X#define TUEXEC 00100
X#define TGREAD 00040
X#define TGWRITE 00020
X#define TGEXEC 00010
X#define TOREAD 00004
X#define TOWRITE 00002
X#define TOEXEC 00001
X
Xstruct Thead {
X char name[NAMSIZ];
X char mode[TMODLEN];
X char uid[TUIDLEN];
X char gid[TGIDLEN];
X char size[TSIZLEN];
X char mtime[TMTMLEN];
X char chksum[TCKSLEN];
X char typeflag;
X char linkname[NAMSIZ];
X char magic[TMAGLEN];
X char version[TVERSLEN];
X char uname[TUNMLEN];
X char gname[TGNMLEN];
X char devmajor[TDEVLEN];
X char devminor[TDEVLEN];
X char prefix[PFXSIZ];
X } ;
X
X#endif /* _TAR_H */
X
Xchar tblock[TBLOCK];
X#define thead ((struct Thead *)tblock)
X
Xint uid,gid;
Xint ndots;
X
X/* ------------------------------------------------------------------ */
X
Xvoid error(s)
Xchar *s;
X{ fprintf(stderr,"Error : %s\n",s);
X fflush(stderr);
X
X exit(0);
X }
X
Xvoid usage()
X{ fprintf(stderr,"tarsh - Tar Extracter to a shell\n");
X fprintf(stderr,"Usage: tarsh DEVICE COMMAND\n");
X
X exit(0);
X }
X
X/* ------------------------------------------------------------------ */
X
X
Xlong otol(s)
Xchar *s;
X{ long val = 0;
X
X while ((*s==' ') || (*s=='\t')) s++;
X while ((*s>='0') && (*s<='8')) {
X val = val*8 + (*s++)-'0';
X }
X return(val);
X }
X
Xchar *ltoo(val,count)
Xlong val;
Xint count;
X{ static char buffer[16];
X
X if (count > 15) count=15;
X
X sprintf(buffer,"%0*.*lo",count,count,val);
X
X return(buffer);
X }
X
Xltoo_patch(p,val,count)
Xchar *p;
Xlong val;
Xint count;
X{ char buffer[32];
X
X if (count > 15) count=15;
X
X sprintf(buffer,"%0*.*lo",count-1,count-1,val);
X
X memcpy(p,buffer,count);
X }
X
X/* ------------------------------------------------------------------ */
X
Xint checksum()
X{ char *ptr;
X int ac;
X
X ptr = thead->chksum;
X while (ptr < thead->chksum+8) *ptr++ = ' ';
X
X ptr = thead->name; ac = 0;
X while (ptr < ((char*)thead)+TBLOCK) ac += (int)(*ptr++);
X
X return ac;
X }
X
X/* ------------------------------------------------------------------ */
X
Xtar_xtract(tar,cmd)
Xchar *cmd,*tar;
X{ int tfd;
X FILE *ofp;
X int nskip;
X long size;
X char pcmd[64];
X
X if ((tfd=open(tar,O_RDONLY)) < 0)
X error("Tar-File kann nicht geoeffnet werden");
X
X while(1) {
X if (read(tfd,thead,TBLOCK) <= 0)
X error("Tar-Header kann nicht gelesen werden");
X
X if (!*thead->name) {
X break;
X }
X
X size=otol(thead->size);
X nskip = (size+TBLOCK-1l)/TBLOCK;
X
X if (thead->typeflag == LNKTYPE) {
X fprintf(stderr,"DTAR:Links werden nicht untersuetzt\n");
X }
X else
X if ((thead->typeflag == REGTYPE)
X || (thead->typeflag == AREGTYPE)) {
X int rws;
X
X sprintf(pcmd,"%s %s",cmd,thead->name);
X ofp=popen(pcmd,"w");
X
X /*
X if (ofp) fprintf(stderr,"Extract to %s \n",pcmd);
X */
X if (!ofp) fprintf(stderr,"Can not open pipe %s \n",pcmd);
X
X while (size>0) {
X if ((rws=read(tfd,thead,TBLOCK)) <= 0)
X error("Tar-Block kann nicht gelesen werden");
X
X if (size > 512) size-=512;
X else { rws=size;
X size=0;
X }
X
X if ((ofp) && (fwrite(thead,rws,1,ofp)<=0)) {
X pclose(ofp);
X ofp=0;
X }
X }
X if (ofp) pclose(ofp);
X }
X else {
X while (nskip--) if (read(tfd,thead,TBLOCK) <= 0)
X error("Tar-Block kann nicht gelesen werden");
X }
X }
X
X fprintf(stderr,"\nEnd of Tar :-)\n\n");
X fflush(stderr);
X close(tfd);
X }
X
X/* ------------------------------------------------------------------ */
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{ char *tcmd,*tar;
X int todo=0;
X
X if (argc!=3) usage();
X tar=argv[1];
X tcmd=argv[2];
X
X fprintf(stderr,"\nTarSh (c) Michael_Kraehe@hb.maus.de\n\n");
X fflush(stderr);
X
X tar_xtract(tar,tcmd);
X }
/
# Check directory src/install
echo Directory src/install
[ ! -d src/install ] && mkdir src/install
echo x - src/install/doinst.sh
sed '/^X/s///' > src/install/doinst.sh << '/'
X#! /bin/bash
X
Xmknod /dev/rmt0 c 9 0
X
Xecho Insert Tape in SCSI-Drive !
Xread KEY
X
Xtarsh /dev/rmt0 tapeinstall
X
Xecho FINISH
/
exit 0