From 51a82abad5cd1c98cbfe94cf36fcca7bb30acf01 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sat, 13 Dec 2025 10:10:21 -0500 Subject: Add an auto-sync function to dpw-age --- dpw-age | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'dpw-age') diff --git a/dpw-age b/dpw-age index 3966621..87f5dd9 100755 --- a/dpw-age +++ b/dpw-age @@ -23,6 +23,7 @@ umask "$UMASK" DPW_AGE_DIR="${DPW_AGE_DIR:-$HOME/.dpw-age}" DPW_AGE_KEY="${DPW_AGE_KEY:-$HOME/.dpw-age-key}" DPW_AGE_RECIPIENT_SUFFIX="${DPW_AGE_RECIPIENT_SUFFIX:-.recipients}" +DPW_AGE_AUTO_SYNC="${DPW_AGE_AUTO_SYNC:-NO}" # No user overrides DPW_AGE_RECIPIENTS_FILE="" @@ -36,6 +37,17 @@ _git_commit() { cd "${DPW_AGE_DIR}" git add --all git commit -am "DPW Auto-commit: $1" + _git_sync +} + +# Auto push/pull +_git_sync() { + [ $USE_GIT -eq 0 ] && return + [ "$DPW_AGE_AUTO_SYNC" != "YES" ] && return + cd "${DPW_AGE_DIR}" + git fetch + git merge + git push } _set_age_recipients() { @@ -66,7 +78,6 @@ echo "No '${DPW_AGE_RECIPIENT_SUFFIX}' files found, is '$DPW_AGE_DIR' initialize exit 1 } - # Interface show() { @@ -232,6 +243,7 @@ Where command may be one of: list insert rm + reencrypt init The 'init' command has its own help page. @@ -241,12 +253,18 @@ dpw-age is influnced by the following enviornment variables: DPW_AGE_DIR="${DPW_AGE_DIR}" DPW_AGE_KEY="${DPW_AGE_KEY} DPW_AGE_RECIPIENT_SUFFIX="${DPW_AGE_RECIPIENT_SUFFIX}" +DPW_AGE_AUTO_SYNC="${DPW_AGE_AUTO_SYNC}" PASSWORD_STORE_UMASK="${UMASK}" -If the above are unset, defaults are shown. +If the above are set their values are shown, if unset the defaults are shown. + +Note on DPW_AGE_AUTO_SYNC, if set to "YES" and DPW_AGE_DIR is a git repository +then it will automatically fetch, merge, and push for every action. This +will require you to have set an upstream for the branch you're on. EOF } +if [ -z "$1" ] ; then _help ; exit 1; fi act="$1"; shift case $act in show) show "$@" ;; -- cgit v1.2.3