dots

Personal dotfiles
git clone git://git.gormless.xyz/dots.git
Log | Files | Refs

arc (1038B)


      1 #!/bin/sh -e
      2 
      3 fail() { >&2 echo "$@" exit 1; }
      4 usage() { fail "usage: ${0##*/} <src> <archive>"; }
      5 
      6 test -z "$1" && usage
      7 test -z "$2" && usage
      8 
      9 src=$(readlink -f "$1")
     10 arch="$2"
     11 tree="${arch}.tree.gz"
     12 dgst="${arch}.tree.sha256"
     13 
     14 test -d "$src" || fail "$src: no directory"
     15 test -e "$arch" && fail "$arch: exists"
     16 test -e "$tree" && fail "$tree: exists"
     17 test -e "$dgst" && fail "$dgst: exists"
     18 
     19 # print out $src, its file size and archive's file name
     20 printf '%s %s %s ' "$src" "$(du -sh "$src"|cut -f1)" "$arch"
     21 
     22 # generate the spec file with sha256 hashes for every file
     23 # archive it and generate sha256 hash for the spec itself
     24 mtree -cK sha256digest -p "$src" | gzip   > "$tree"
     25 zcat "$tree"                     | sha256 > "$dgst"
     26 
     27 cd "$src" || fail "$src: no directory"
     28 
     29 # write (-w) gzipped (-z) archive
     30 # in cpio format (-x cpio)
     31 # to the file (-f)
     32 pax -wzx cpio -f "$arch" .
     33 	# TODO
     34 	#
     35 	# to exclude '.*/foo/.*' and '.*bar.*'
     36 	#
     37 	# -'s,.*/foo/.*,,' \
     38 	# -'s,.*bar.*,,' \
     39 
     40 # print out the archive file size
     41 du -sh "$arch" |
     42 cut -f1