ref: f6706e1759c3e16f6f710ac897b7aa1cb5e22fa4
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