From: Nathaniel Wesley Filardo Date: Sat, 12 Mar 2022 21:06:50 +0000 (+0000) Subject: cdb: database fron environment by default X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=4e024464739fe314855ef66e797ae45cb23007be;p=csdb cdb: database fron environment by default --- diff --git a/README.rst b/README.rst index f031933..afb18cb 100644 --- a/README.rst +++ b/README.rst @@ -33,12 +33,17 @@ This program requires... Supported Operations #################### +To reduce clutter, many of the examples here rely on ``cdb``'s ability to pull +the default database from the ``$CDB`` environment variable. If that's not what +you want, add ``--db ${DB}`` to the invocation of ``cdb``. + + Initialize A Database ===================== :: - cdb --db ${DB} init + cdb init Observe A Path ============== @@ -46,17 +51,17 @@ Observe A Path Add the checksum of a single path to the database. This will create a new checksum and/or a new path identifier as needed and will bind them together. :: - sha512sum $FILE | cdb --db ${DB} addh + sha512sum $FILE | cdb addh Or, for all files under a path:: - find $DIR -type f -exec sha512sum {} \+ | cdb --db ${DB} addh + find $DIR -type f -exec sha512sum {} \+ | cdb addh If we have a pile of digest files already, each of which contains digests of paths relative to its location, we can generate a database, ``${DB2}`` from them with the assistance of the ``cdb-util digest-relativize`` tool:: - find ${DIR} -type f -name SHA512SUMS -print0 | cdb-util drel --inul | cdb --db ${DB} addh + find ${DIR} -type f -name SHA512SUMS -print0 | cdb-util drel -1 | cdb addh Revalidate A Path Observation ============================= @@ -64,23 +69,23 @@ Revalidate A Path Observation Measure the checksum of a path and confirm that the database already held that observation. Reports unexpected files as well as mis-checksummed contents. :: - sha512sum $FILE | cdb --db ${DB} verh + sha512sum $FILE | cdb verh Or for all files under a path:: - find $DIR -type f -exec sha512sum {} \; | cdb --db ${DB} verh + find $DIR -type f -exec sha512sum {} \; | cdb verh This processing of digest streams is to be preferred to verifying a digest stream as generated by the database, e.g.:: - cdb --db ${DB} look \* | sha512sum -c + cdb look \* | sha512sum -c because the former can be more informative in the case of mismatching digests (specifically, the database can look for other paths that have the reported digest). If it's easier to have the database generate the set of files, that can be done:: - cdb --db ${DB} look \* --format '$u$z' --nul | xargs -0 sha512sum | cdb --db ${DB} verh + cdb look \* --format '$u$z' --nul | xargs -0 sha512sum | cdb verh Add Missing Checksums ===================== @@ -105,7 +110,7 @@ We can then script computing those files' checksums and adding the new reports to the database:: xargs -0 sha512sum > ${DB}.new < ${DB}.new-files0 - cdb --db ${DB} addh < ${DB}.new + cdb addh < ${DB}.new Using diff ---------- @@ -178,7 +183,7 @@ By Existing Paths Indicate that some file contents are to be considered a lesser version of some other contents:: - cdb --db ${DB} addsuper /old/path /new/path + cdb addsuper /old/path /new/path After this command is run, ``domv`` will be willing to remove the ``/old/path`` entry from the database. @@ -205,7 +210,7 @@ to import into the library. Novel hashes, and their new paths, may optionally be recorded as well, to be subsequently added to the database:: find /source/path -type f -exec sha512sum {} \+ | \ - cdb --db ${DB} ingest --target /new/path --prune + cdb ingest --target /new/path --prune This will produce a stream of shell commands to copy files given by ``find`` into the ``/new/path`` directory (using their basename therein). Passing @@ -242,11 +247,11 @@ above:: We can then prepare to prune duplicates and add unique files:: - cdb --db ${DB} ingest --prune --inplace --digest-log ${DB}.new2 < ${DB}.new > ${DB}.prune + cdb ingest --prune --inplace --digest-log ${DB}.new2 < ${DB}.new > ${DB}.prune Add new files to the database with:: - cdb --db ${DB} addh < ${DB}.new2 + cdb addh < ${DB}.new2 Inspect the pruning commands to be run, and then execute them with:: diff --git a/cdb b/cdb index a791c69..5dad445 100755 --- a/cdb +++ b/cdb @@ -190,7 +190,8 @@ local argp = argparse("cdb", "checksum database tool") argp:option("--db --database") :target("database") :args(1) - :description("Indicate primary checksum database") + :default(os.getenv("CDB")) + :description("Indicate primary checksum database (or use $CDB)") -- grouping logic, part 1. Sadly, this needs to run "all at once" but we want -- to define our commands incrementally!