#!/bin/bash

# Demonstration voting script for kfingerd.
# Simply copy to /home/finger, rename to name of subject and edit "DESC".
# Copyright (C) 1995 -- Joel Katz
# This file is part of kfingerd-0.03

# Specify what is being voted for or against.
DESC="a c-like syntax"

# Change the word 'secret' below to something secret
RESULTS="secret-"

# Extract our name
NAME=`echo ${0} | cut -f 4 -d "/"`

# Check if results file exists and create if necessary
if test ! -e /home/finger/${RESULTS}${NAME};
then
 >/home/finger/${RESULTS}${NAME};
 chmod go-rw /home/finger/${RESULTS}${NAME};
fi

# Were we given a subname?
if test -z $3
then
  echo You may vote for ${DESC} by fingering \"${NAME}#yes\" or
  echo against ${DESC} by fingering \"${NAME}#no\".
  exit;
fi

# Convert subname to lower case
LONAME=`echo $3 | tr "A-Z" "a-z"`

# Results request?
if test ${LONAME} = results;
then
 echo "Yes votes: "
 cat /home/finger/${RESULTS}${NAME} | cut -f 2 -d " " | grep yes | wc -l
 echo
 echo "No votes: "
 cat /home/finger/${RESULTS}${NAME} | cut -f 2 -d " " | grep no | wc -l
 exit;
fi

# Yes vote?
if test ${LONAME} = yes;
then
 echo Your vote for ${DESC} has been registered.
 echo $1-$2 ${LONAME} >> /home/finger/${RESULTS}${NAME};
 exit;
fi

# No vote?
if test ${LONAME} = no;
then
 echo Your vote against ${DESC} has been registered.
 echo $1\-$2 ${LONAME} >> /home/finger/${RESULTS}${NAME};
 exit;
fi

# nonsense subname
echo You must vote either for or against ${DESC}.
echo Vote \"yes\" by fingering \"${NAME}#yes\" and vote \"no\"
echo by fingering \"${NAME}#no\".
