ref: 171d78f72e972c8671e39b064e9d1072f3130560
dir: /bin/bag/
#!/bin/rc -e
rfork en
fn usage {>[1=2] echo 'usage:' $usage && exit 'usage'}
usage='bag [-f] file ...'
fn bag {
file = $1
h = `{sha1sum $file | sed 's/(..)(....).*/\1 \2 &/'}
b = $h(1)
f = $b^/^$h(2)
h = $h(3)
if(~ $force yes || ! test -e $bag/$f){
mkdir -p $bag/$b
>>$bag/$f.tag {
echo 'hash:' $h
echo 'file:' $file
echo 'date:' `{date -um}
echo 'tags:' $tags
echo 'note:' $note
}
touch $bag/$f
fcp $file $bag/$f
}
if not
>[1=2] echo already bagged
echo $bagurl/$f
}
if(~ $#bag 0)
bag = /n/bag
if(~ $#bagurl 0)
bagurl = http://a-b.xyz
force = no
tags = ()
note = ()
while(~ $1 -* && ! ~ $1 --){
switch($1){
case -f
force = yes
case -t
shift
tags = ($tags $1)
case -m
shift
note = $1
case *
usage
}
shift
}
if(~ $1 --)
shift
9fs bag
ramfs -u -m /mnt/ram
files = ($*)
if(~ $#files 0){
cat /fd/0 >/mnt/ram/stdin
files = (/mnt/ram/stdin)
}
for(f in $files)
bag $f