#!/bin/bash

GIFTD=/usr/sbin/giftd

# Try first using X(term)
if [ ! -d ~/.giFT ]; then
  # naive attempt to run only run one instance per user (hopefully).
  LOCKFILE=/var/tmp/gift-setup.${UID}.lock
  echo $$ > $LOCKFILE ||:
  # Try first using X(term), then fallback to console
  if [ ! -z "${DISPLAY}" ]; then 
    xterm -e gift-setup || gift-setup
  else
    gift-setup
  fi
  rm -f $LOCKFILE
fi

# Hopefully we're good to go now
exec ${GIFTD} ${1+"$@"}
