ref: e74f570df7843de1c4efbf1bba981e6b96038e33
parent: d79d0cfa5a82102930cba02b847a74696ec17ab8
author: kvik <[email protected]>
date: Sat Feb 22 09:02:13 EST 2020
Add bag(1)
--- /dev/null
+++ b/bin/bag
@@ -1,0 +1,44 @@
+#!/bin/rc -e
+rfork en
+fn usage {>[1=2] echo 'usage:' $usage && exit 'usage'}
+usage='bag [-f] file ...'
+
+fn bag {
+ name = $1
+ h = `{sha1sum $name | sed 's/(..)(....).*/\1 \2/'}
+ b = $h(1)
+ f = $b^/^$h(2)
+ if(~ $force yes || ! test -e $bag/$f){
+ mkdir -p $bag/$b
+ fcp $name $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
+while(~ $1 -* && ! ~ $1 --){
+ switch($1){
+ case -f
+ force = yes
+ case *
+ usage
+ }
+ shift
+}
+if(~ $1 --)
+ shift
+files = ($*)
+if(~ $#files 0){
+ ramfs -u
+ cat /fd/0 >/tmp/bag.tmp
+ files = (/tmp/bag.tmp)
+}
+9fs bag
+for(f in $files)
+ bag $f