Plan 9 from Bell Labs’s /usr/web/sources/contrib/arisawa/misc/pack

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc -e
fn usage { echo 'pack source source ...'}
#
#	GOAL:
#   foo   -> foo.gz       in case of file.
#   foo   -> foo.tgz      in case of dir.
#   foo.tar -> foo.tgz
#   *.gz -> DO NOTHING
#
#   code by Kenar
#

rfork e

fn usage {
	echo 'usage: pack  file ...'
	exit usage
}

fn error {
	echo $*
	exit 'not found'
}

if(~ $#* 0) usage

while (! ~ $#* 0){
	x=$1
	if (test ! -e $x) error file $x not found
	f = 1
	while(~ $f 1){
	switch($x){
	case *.gz *.tgz
		f=0
	case *.tar
		gzip $x
		echo rm $x
		f=0
	case *
		if(test -d $x){
			tar -pcf $x.tar $x
			echo rm -rf $x
			x=$x.tar
		}
		if not{
			gzip $x
			echo rm $x
			f=0
		}
	}
	}
	shift
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.