#!/bin/rc
# unpack file ...
# foo.gz -> foo in case of file.
# foo.tar.gz -> foo in case of dir.
# foo. -> DO NOTHING
# foo -> DO NOTHING
#
# BUG
# - Not debugged except tar format because I rarely use other format.
# more method should be added
#
# coded by Kenar
#
rfork e
fn usage {
echo 'usage: unpack file ...'
exit usage
}
fn error {
echo $*
exit 'not found'
}
if(~ $#* 0) usage
l=()
while (! ~ $#* 0 ){
x = $1
if (test ! -e $x) error file $x not found
f = 1
while(~ $f 1){
l=($l $x)
switch($x){
case *.gz
gunzip $x
x=`{basename $x .gz}
case *.tgz
gunzip $x
x=`{basename $x .tgz}^.tar
case *.tar
a=`{tar -tf $x|sed 1q}
t=`{basename $x .tar}
# I dislike packages that scatter files
# we protect, not perfect though.
if(! ~ $a $t/*){
fs/tarfs $x
# fs/tarfs finishes when all references are gone.
# I wanted to see the result in current acme
# but I don't know how to do. probably impossible.
window -m acme /n/tapefs
l=($l /n/tapefs)
}
if not
tar -Rxf $x
x=$t
case *.bz2
bunzip2 $x
x=`{basename $x .bz2}
case *.tbz
bunzip2 $x
x=`{basename $x .tbz}^.tar
case *.tbz2
bunzip2 $x
x=`{basename $x .tbz2}^.tar
case *
for(f in $l)
if(test -e $f)
ls -ld $f
f=0
}
}
shift
}
|