#!/bin/sh ######################################################## # This is a shell archive --- shark 0.1.1 --- # # Please remove any lines before this header and # # run sh this-file-name to extract all files. # # 1994 (C) Fernando J G Pereira - fjp@minerva.inesc.pt # ######################################################## echo unsharking shark mkdir shark echo unsharking shark/shark.c cat > shark/shark.c << '\\__END__OF__shark/shark.c__FILE\\' /****************************************************************************** * shark - shell archiver. * * * * This is free software - you are free to use it and distribute it as long as * * this message appears in the source code and archive headers. * * There is no explicit or implicit WARRANTY in the usage of this program. * * You are free to use it at your own risk (including all kinds of possible * * damages). * * * * 15/Feb/94 * * * * Fernando Pereira - fjp@minerva.inesc.pt * ******************************************************************************/ #include #include #include #include #include #include #include #define LINE_SIZE 1024 #define SCAN_SIZE 2048 FILE *arch = stdout; void archive( char *file ); void archive_dir( char* file, struct stat *info ); void archive_file( char* file, struct stat *info ); void archive_link( char *file, struct stat *info ); void archive_char_dev( char *file, struct stat *info ); void archive_block_dev( char *file, struct stat *info ); void archive_pipe( char *file, struct stat *info ); int is_bin( char *file ); int main( int argc, char **argv ) { int i = 1; while( argv[i] && argv[i][0] == '-' ) { switch( argv[i][1] ) { case 'o': ++i; if( argv[i] == 0 ) exit( 1 ); arch = fopen( argv[i], "w" ); fchmod( fileno( arch ), 0755 ); break; case 'h': default: fprintf( stderr, "usage: shark [-o output-file] files\n"); exit( 0 ); } ++i; } fprintf(arch,"#!/bin/sh\n" ); fprintf(arch,"########################################################\n" ); fprintf(arch,"# This is a shell archive --- shark 0.1.1 --- #\n" ); fprintf(arch,"# Please remove any lines before this header and #\n" ); fprintf(arch,"# run sh this-file-name to extract all files. #\n" ); fprintf(arch,"# 1994 (C) Fernando J G Pereira - fjp@minerva.inesc.pt #\n" ); fprintf(arch,"########################################################\n" ); while( i < argc ) archive( argv[i++] ); } void archive( char *file ) { struct stat info; if( lstat( file, &info ) < 0 ) { perror( file ); return; } fprintf( stderr, "sharking %s\n", file ); fprintf( arch, "echo unsharking %s\n", file ); if( S_ISDIR( info.st_mode ) ) archive_dir( file, &info ); else if( S_ISREG( info.st_mode ) ) archive_file( file, &info ); else if( S_ISFIFO( info.st_mode ) ) archive_pipe( file, &info ); else if( S_ISBLK( info.st_mode ) ) archive_block_dev( file, &info ); else if( S_ISCHR( info.st_mode ) ) archive_char_dev( file, &info ); else if( S_ISLNK( info.st_mode ) ) archive_link( file, &info ); else fprintf( stderr, "Unable to shark file: %s\n", file ); } /* We will only be able to store MAX_FILES_OPEN sub-directory levels ... */ void archive_dir( char* file, struct stat *info ) { char path[LINE_SIZE+1]; struct dirent *ent; DIR *dir; if( strcmp( file, "." ) && strcmp( file, ".." ) ) fprintf( arch, "mkdir %s\n", file ); dir = opendir( file ); if( dir == NULL ) { perror( file ); return; } while( ent = readdir( dir ) ) { ent->d_name[ent->d_reclen] = '\0'; if( strcmp( ent->d_name, "." ) && strcmp( ent->d_name, ".." ) ) { sprintf( path, "%s/%s", file, ent->d_name ); archive( path ); } } closedir( dir ); fprintf( arch, "chmod %o %s\n", 07777&info->st_mode, file ); } /* Maybe a Bug: If a text file doesn't end with a '\n', it will be appended */ void archive_file( char* file, struct stat *info ) { char cmd[LINE_SIZE+1]; FILE *fptr; int d, n, lc = '\n'; unsigned char c; if( is_bin( file ) ) { sprintf( cmd, "uuencode %s %s", file, file ); fptr = popen( cmd, "r" ); if( fptr == NULL ) { perror( cmd ); return; } fprintf( arch, "uudecode << '\\\\__END__OF__%s__FILE\\\\'\n", file ); } else { fptr = fopen( file, "r" ); if( fptr == NULL ) { perror( file ); return; } fprintf(arch, "cat > %s << '\\\\__END__OF__%s__FILE\\\\'\n",file,file); } for(;;) { c = getc( fptr ); if( feof( fptr ) ) break; putc( c, arch ); lc = c; } if( lc != '\n' ) putc( '\n', arch ); fprintf( arch, "\\\\__END__OF__%s__FILE\\\\\n", file ); fprintf( arch, "chmod %o %s\n", 07777&info->st_mode, file ); fclose( fptr ); } void archive_pipe( char *file, struct stat *info ) { fprintf( arch, "mknod -m %o %s p\n", file, 07777&info->st_mode ); } void archive_block_dev( char *file, struct stat *info ) { fprintf( arch, "mknod -m %o %s b %d %d\n", 07777&info->st_mode, file, (info->st_rdev&0xff00)>>8, info->st_rdev & 0xff ); } void archive_char_dev( char *file, struct stat *info ) { fprintf( arch, "mknod -m %o %s c %d %d\n", 07777 & info->st_mode, file, (info->st_rdev&0xff00)>>8, info->st_rdev & 0xff ); } void archive_link( char *file, struct stat *info ) { char path[LINE_SIZE+1]; int n; n = readlink( file, path, LINE_SIZE ); if( n <= 0 ) { perror( file ); return; } path[n] = '\0'; fprintf( arch, "ln -s %s %s\n", path, file ); } /*Test if a file is binary: Fails if the first SCAN_SIZE chars are all ASCII.*/ int is_bin( char *file ) { int n, d; char buff[SCAN_SIZE+1]; d = open( file, O_RDONLY ); if( d == -1 ) { perror( file ); return; } n = read( d, buff, SCAN_SIZE ); close( d ); while( --n >= 0 ) if( buff[n] != '\0' && !isascii( buff[n] ) ) return 1; return 0; } \\__END__OF__shark/shark.c__FILE\\ chmod 644 shark/shark.c echo unsharking shark/shark uudecode << '\\__END__OF__shark/shark__FILE\\' begin 755 shark/shark M"P%D```0````$``````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M`````````````````````````````````````````````.A/"P``N"T```"[ M`````,V`HUP+"6"+1"0(HS0+"6`/MP44$```4.A`#```@\0$Z'@,``#H>P$` M`%#HD0,`8%NX`0```,V`Z_>0D)"0D)"0`)"0D'<`=7-A9V4Z('-H87)K(%LM M;R!O=71P=70M9FEL95T@9FEL97,*`",A+V)I;B]S:`H`(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,* M`",@5&AI'1R86-T(&%L;"!F:6QE575E.+?0SH4@@``+X!````@W\$``^$ MEP```(M'!(`X+0^%BP```(U?!(L#BD`!/&AT2SQO=4>#PP1&@SL`=0YJ`>C3 M`0!@D)"0D)"0D&A4````BQ-2Z%\"`&"C!!```&CM`0``4.@W`@!@@\0$4.BN M`0!@@\00ZR60D)"0D&A6````:-0'"6#H10(`8&H`Z(8!`&"0D)"0D)"0D)"0 M@\,$1H,[`'0+BP.`."T/A'C___]H>P```(L5!!```%+H#P(`8&B&````BQ4$ M$```4NC^`0!@:,````"+%000``!2Z.T!`&!H^@```(L5!!```%+HW`$`8(/$ M(&@T`0``BQ4$$```4NC(`0!@:&X!``"+%000``!2Z+7XGL7<-S:&%R:VEN9R`E6![`P$``!75E.+=0B_+00``+D"````_*@` M\Z9T+(MU"+\O!```N0,```#\J`#SIG08BUT(4V@R!```BQT$$```4^CK__]? M@\0,BUT(4^@'!0!@B87X^___@\0$AQ= MPW5U96YC;V1E("5S("5S`'(`=75D96-O9&4@/#P@)UQ<7U]%3D1?7T]&7U\E M6![`@$``!75E.+?0C'A?C[__\*````5^CA`@``@\0$A/_````B9WX^___ZY60D)"0D)"0D)"0D)"0@[WX^___"G0MH000 M``"+4!0Y4!AW&FH*4.@^^?]?@\0(ZQ.0D)"0D)"0D)"0D)"0Q@(*_T`45VC> M!0``BPT$$```4>@,_?]?5XM-#&:+00@E_P\``%!H0@0``(L-!!```%'H[?S_ M7U;H1_S_7XVE[/O__UM>7XGL7<-M:VYO9"`M;2`E;R`E6+50P/MD(04`^V M0A%0BTT(46:+0@@E_P\``%!H[0<``(L-!!```%'H1?S_7XGL7<-M:VYO9"`M M;2`E;R`ECU^_]?B>Q=PVQN("US("5S("5S"@!5B>6! M[`0$``!64XM="&@`!```C;7\^___5E/H)`(`8(/$#(7`?PE3Z!6![`0(``!64XM="&H`4^B.``!@B<:#Q`B#_O]U(%/HO@``8.M)D)"0 MD)"0D)"X`0```.LZD)"0D)"0D)"0:``(``"-A?SW__]05NB"`0!@B<-6Z/+X M_U_K$)"0D)"`O"O\]___`'0"?,1+>?$QP(VE]/?__UM>B>Q=PY"0D%6)Y5.A M>!```(/X_W49,<"#/7P0````=`Z0D)!`@SR%?!````!U]8G#A=MT#Y"0D(L$ MG7@0``#_T$MU](M=_(GL7<.0D)"0D)"0D)"0D)"058GE4[M,$```@SU,$``` M`'0.D)"+`X/#!/_0@SL`=?1HA`D``.B:]_]?BUW\B>Q=PY"0D)"0D)"0D)"0 MD)"0D%6)Y8,]#!````!U#\<%#!````$```#HI?___XGL7<.04[@!````BUPD M",V`A2!L:6YK M960*`)"0D)"0@^PX55=64XML)$R+7"10@SU`$`````^$M````,=$)$0@`/!B M:`8+``#HXO[__X/$!(7`=%N+`XU\)!B^$0L``/RY"@```/.E9J6%P'0<@#@` M=`>00(`X`'7Z*P-0BQM3:@+HV?[__X/$#&HJC40D'%!J`NC(_O__@\0,D&B` M````Z%K^__^#Q`3K\9"0D)"0:%00``!H.!```(M4)%Q2BQM3C40D(%"X`@`` M`(7M?P6X`0```%"+1"1<_]"+5"0L4HM4)"Q2Z+7^__^#Q"#K)HU\)!B^.PL` M`/RY!0```/.EA>U_*VH4C40D'%!J`NA-_O__@\0,A>U_%I"0:@#HW?W__X/$ M!.OTD)"0D)"0D)!;7E]=@\0XPX/L!&:+5"0(9H72=06Z M7UW#D&QI8F,N shark/Makefile << '\\__END__OF__shark/Makefile__FILE\\' shark: shark.c cc -O2 -o shark shark.c strip shark \\__END__OF__shark/Makefile__FILE\\ chmod 644 shark/Makefile echo unsharking shark/shark.lsm cat > shark/shark.lsm << '\\__END__OF__shark/shark.lsm__FILE\\' Begin2 Title = shark - shell archiver Version = 0.1.1 Desc1 = Simple SHELL ARCHIVER: usefull to pack data in news/mail messages desc2 = Stores files, recursive directories, char/block devices, pipes, Desc3 = symbolic links, saves permitions, and auto-uuencodes binary files. Desc4 = The resulting package is shell script that unpackages itself. Desc5 = This is an alfa release - so you must be very carefull ... Author = Fernando J. G. Pereira AuthorEmail = fjp@minerva.inesc.pt Maintainer = Fernando J. G. Pereira MaintEmail = fjp@minerva.inesc.pt Site1 = sunsite.unc.edu Path1 = File1 = shark.sh FileSize1 = 21k Site2 = nic.funet.fi Path2 = File2 = shark.sh FileSize2 = 21k Site3 = Path3 = File3 = FileSize3 = Site4 = Path4 = File4 = FileSize4 = Required1 = Linux Required2 = Required3 = Required4 = CopyPolicy1 = Free CopyPolicy2 = Keywords = shell-archive - shell-scripts Comment1 = Comment2 = Comment3 = Comment4 = RelFiles1 = RelFiles2 = RelFiles3 = Entered = 16/2/94 EnteredBy = fjp CheckedEmail = End \\__END__OF__shark/shark.lsm__FILE\\ chmod 644 shark/shark.lsm chmod 755 shark