#!/bin/sh -e # # arc - a directory archiver with compression # # https://rgz.ee/bin/arc # Copyright 2018-2019 Roman Zolotarev # fail() { >&2 echo "$@" exit 1; } usage() { fail "usage: ${0##*/} "; } test -z "$1" && usage test -z "$2" && usage src=$(readlink -f "$1") arch="$2" tree="${arch}.tree.gz" dgst="${arch}.tree.sha256" test -d "$src" || fail "$src: no directory" test -e "$arch" && fail "$arch: exists" test -e "$tree" && fail "$tree: exists" test -e "$dgst" && fail "$dgst: exists" # print out $src, its file size and archive's file name printf '%s %s %s ' "$src" "$(du -sh "$src"|cut -f1)" "$arch" # generate the spec file with sha256 hashes for every file # archive it and generate sha256 hash for the spec itself mtree -cK sha256digest -p "$src" | gzip > "$tree" zcat "$tree" | sha256 > "$dgst" cd "$src" || fail "$src: no directory" # write (-w) gzipped (-z) archive # in cpio format (-x cpio) # to the file (-f) pax -wzx cpio -f "$arch" . # TODO # # to exclude '.*/foo/.*' and '.*bar.*' # # -'s,.*/foo/.*,,' \ # -'s,.*bar.*,,' \ # print out the archive file size du -sh "$arch" | cut -f1