shithub: bin.rc

ref: 0ba323dbdbc78e4c6ccba79028997850d59b5bc6
dir: /bin/bag/

View raw version
#!/bin/rc -e
rfork en

fn bag {
	file = $1
	h = `{sha1sum $file | sed 's/(..)(....).*/\1 \2 &/'}
	b = $h(1)
	f = $b^/^$h(2)
	h = $h(3)
	if(~ $force 1 || ! 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
}

flagfmt = 'f:force,t:tags tags,m:note message'; args = 'file ...'
if(! eval `''{aux/getflags $*}) aux/usage

if(~ $#bag 0)
	bag = /n/bag
if(~ $#bagurl 0)
	bagurl = http://a-b.xyz

ramfs -u -m /mnt/ram
files = ($*)
if(~ $#files 0){
	cat /fd/0 >/mnt/ram/stdin
	files = (/mnt/ram/stdin)
}
9fs bag
for(f in $files)
	bag $f