summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2008-09-12 18:03:40 -0400
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2008-09-12 18:03:40 -0400
commit1343ffb414e74917b4e6f9eed05df035d25be4aa (patch)
tree7644aa07cf044b9e8ddbde22109f333fd3373df3
parent82c97a3d7799dcbd722523f251de8836d5956318 (diff)
more portability fixes: GNU date and BSD date prognosticate differently.
-rw-r--r--src/common48
-rwxr-xr-xsrc/monkeysphere-server7
2 files changed, 52 insertions, 3 deletions
diff --git a/src/common b/src/common
index c8a7db6..48739d9 100644
--- a/src/common
+++ b/src/common
@@ -134,6 +134,54 @@ lock() {
esac
}
+
+# for portability, between gnu date and BSD date.
+# arguments should be: number longunits format
+
+# e.g. advance_date 20 seconds +%F
+advance_date() {
+ local gnutry
+ local number="$1"
+ local longunits="$2"
+ local format="$3"
+ local shortunits
+
+ # try things the GNU way first
+ if date -d "$number $longunits" "$format" >&/dev/null ; then
+ date -d "$number $longunits" "$format"
+ else
+ # otherwise, convert to (a limited version of) BSD date syntax:
+ case "$longunits" in
+ years)
+ shortunits=y
+ ;;
+ months)
+ shortunits=m
+ ;;
+ weeks)
+ shortunits=w
+ ;;
+ days)
+ shortunits=d
+ ;;
+ hours)
+ shortunits=H
+ ;;
+ minutes)
+ shortunits=M
+ ;;
+ seconds)
+ shortunits=S
+ ;;
+ *)
+ # this is a longshot, and will likely fail; oh well.
+ shortunits="$longunits"
+ esac
+ date "-v+${number}${shortunits}" "$format"
+ fi
+}
+
+
# check that characters are in a string (in an AND fashion).
# used for checking key capability
# check_capability capability a [b...]
diff --git a/src/monkeysphere-server b/src/monkeysphere-server
index e590f3c..b96a659 100755
--- a/src/monkeysphere-server
+++ b/src/monkeysphere-server
@@ -545,6 +545,7 @@ publish_server_key() {
gpg_authentication "--keyserver $KEYSERVER --send-keys '0x${fingerprint}!'"
}
+
diagnostics() {
# * check on the status and validity of the key and public certificates
local seckey
@@ -566,7 +567,7 @@ diagnostics() {
curdate=$(date +%s)
# warn when anything is 2 months away from expiration
warnwindow='2 months'
- warndate=$(date +%s -d "$warnwindow")
+ warndate=$(advance_date $warnwindow +%s)
if ! id monkeysphere >/dev/null ; then
echo "! No monkeysphere user found! Please create a monkeysphere system user."
@@ -593,7 +594,7 @@ diagnostics() {
echo "! Host key is expired."
echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
elif (( "$expire" < "$warndate" )); then
- echo "! Host key expires in less than $warnwindow:" $(date -d "$(( $expire - $curdate )) seconds" +%F)
+ echo "! Host key expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
fi
fi
@@ -619,7 +620,7 @@ diagnostics() {
echo "! User ID '$uid' is expired."
# FIXME: recommend a way to resolve this
elif (( "$expire" < "$warndate" )); then
- echo "! User ID '$uid' expires in less than $warnwindow:" $(date -d "$(( $expire - $curdate )) seconds" +%F)
+ echo "! User ID '$uid' expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
# FIXME: recommend a way to resolve this
fi
fi