Generalize filesystem location variables (closes http://web.monkeysphere.info/bugs...
[monkeysphere.git] / src / monkeysphere
index 59cb3d6ac45764e255fa1135f2eecdee24ca5541..1db4f20ce48fba8670aeb4507d4bed4b9ca0f853 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 # monkeysphere: MonkeySphere client tool
 #
 ########################################################################
 PGRM=$(basename $0)
 
-SHARE=${MONKEYSPHERE_SHARE:-"/usr/share/monkeysphere"}
-export SHARE
-. "${SHARE}/common" || exit 1
+SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
+export SYSSHAREDIR
+. "${SYSSHAREDIR}/common" || exit 1
 
-# date in UTF format if needed
+# UTC date in ISO 8601 format if needed
 DATE=$(date -u '+%FT%T')
 
 # unset some environment variables that could screw things up
@@ -36,7 +36,7 @@ umask 077
 usage() {
     cat <<EOF >&2
 usage: $PGRM <subcommand> [options] [args]
-MonkeySphere client tool.
+Monkeysphere client tool.
 
 subcommands:
  update-known_hosts (k) [HOST]...    update known_hosts file
@@ -63,7 +63,7 @@ gen_subkey(){
     keyExpire=
 
     # get options
-    TEMP=$(getopt -o l:e: -l length:,expire: -n "$PGRM" -- "$@")
+    TEMP=$(PATH="/usr/local/bin:$PATH" getopt -o l:e: -l length:,expire: -n "$PGRM" -- "$@") || failure "getopt failed!  Does your getopt support GNU-style long options?"
 
     if [ $? != 0 ] ; then
        exit 1
@@ -147,7 +147,7 @@ EOF
 )
 
     log verbose "generating subkey..."
-    fifoDir=$(mktemp -d)
+    fifoDir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)
     (umask 077 && mkfifo "$fifoDir/pass")
     echo "$editCommands" | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
 
@@ -210,7 +210,7 @@ You might want to run 'gpg --gen-key'."
 You might want to 'monkeysphere gen-subkey'"
     fi
 
-    workingdir=$(mktemp -d)
+    workingdir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)
     umask 077
     mkfifo "$workingdir/passphrase"
     keysuccess=1
@@ -270,7 +270,7 @@ unset HASH_KNOWN_HOSTS
 unset AUTHORIZED_KEYS
 
 # load global config
-[ -r "${ETC}/monkeysphere.conf" ] && . "${ETC}/monkeysphere.conf"
+[ -r "${SYSCONFIGDIR}/monkeysphere.conf" ] && . "${SYSCONFIGDIR}/monkeysphere.conf"
 
 # set monkeysphere home directory
 MONKEYSPHERE_HOME=${MONKEYSPHERE_HOME:="${HOME}/.monkeysphere"}