aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-04-27 00:53:42 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-04-27 00:53:42 +1200
commit92ba7c767712c4a9333ba941bd000cc22510c35c (patch)
tree10b1c0d17b88938b066ca80879c590a85536bc9a
parent6bf53e16ad0e2f6018d73ae2c7199c7bece81a30 (diff)
parente89ea53dd788df02554d7c61a8b7f86333cd339e (diff)
downloadparcimini-master.tar.gz
parcimini-master.zip
Merge branch 'release/v0.3.0'HEADv0.3.0master
* release/v0.3.0: Emit log message on exit Send GnuPG diagnostics to stdout for logging Add UMask setting Flesh out logging with timestamps and systemd
-rw-r--r--VERSION2
-rw-r--r--parcimini.bash38
-rw-r--r--parcimini.service3
3 files changed, 32 insertions, 11 deletions
diff --git a/VERSION b/VERSION
index 0ea3a94..0d91a54 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.2.0
+0.3.0
diff --git a/parcimini.bash b/parcimini.bash
index 016f166..8047a79 100644
--- a/parcimini.bash
+++ b/parcimini.bash
@@ -1,5 +1,11 @@
self=parcimini
+# If systemd made us a logs directory, write to files in there
+if [ -n "$LOGS_DIRECTORY" ] ; then
+ dir=${LOGS_DIRECTORY%%:%}
+ exec >>"$dir"/"$self".log
+fi
+
# Base interval between key retrievals from first arg; default 20 mins
interval=${1:-120}
@@ -7,8 +13,20 @@ interval=${1:-120}
hash gpg || exit
hash shuf || exit
+# Define logging function
+logf() {
+ format=$1
+ shift
+ printf "%s: %s: $format" \
+ "$(date +'%FT%T')" "$self" "$@"
+}
+
# Make a temporary file for the key listings, delete on exit
-trap 'rm -f "$list"' EXIT
+cleanup() {
+ logf 'Stopped\n'
+ rm -f -- "$list"
+}
+trap cleanup EXIT
list=$(mktemp) || exit
# Define a function to retrieve all keychain fingerprints
@@ -21,27 +39,27 @@ END { for (key_id in key_ids) print key_id }'
}
# Log process start
-printf >&2 '%s: Started; base interval %u seconds.\n' \
- "$self" "$interval"
+logf 'Started; base interval %u seconds.\n' \
+ "$interval"
# While we're able to write a shuffled key list to the file, refresh all of them
while key_ids | shuf > "$list" ; do
- printf >&2 '%s: Beginning new round; %u key IDs found.\n' \
- "$self" "$(sed '$=;d' "$list")"
+ logf 'Beginning new round; %u key IDs found.\n' \
+ "$(sed '$=;d' "$list")"
# Shuffle list and read each ID
while read -r key_id ; do
# Sleep for a random interval
spell=$((RANDOM % interval + 1))
- printf >&2 '%s: Sleeping for %u seconds...\n' \
- "$self" "$spell"
+ logf 'Sleeping for %u seconds...\n' \
+ "$spell"
sleep "$spell"
# Retrieve key
- printf >&2 '%s: Retrieving key %s...\n' \
- "$self" "$key_id"
- gpg --batch --no-tty --recv-key "$key_id"
+ logf 'Retrieving key %s...\n' \
+ "$key_id"
+ gpg --batch --no-tty --recv-key "$key_id" 2>&1
done < $list
done
diff --git a/parcimini.service b/parcimini.service
index 8e30528..8250fee 100644
--- a/parcimini.service
+++ b/parcimini.service
@@ -3,6 +3,9 @@ Description=GnuPG keychain randomized update
After=network.target
[Service]
+LogsDirectory=%p
+LogsDirectoryMode=0700
+UMask=0077
ExecStart=/usr/local/bin/parcimini
[Install]