#!/bin/sh
#
#Warning: not fully tested.
#
#Place the following line (without the #) in your mail aliases file
#(often /etc/aliases, and run your alias update program)
#
#xchequer: "|/home/xchequer/xchange.sh"
#
#assuming this program is called xchange.sh, and that it is in
#/home/xchequer and that there is a .pgp directory with the keyrings.
#You may also have to play with permissions and do other things to
#properly secure this.
#
#For easy minting, copy and rename this file to minter.sh, uncomment
#the mint section below (and comment the exchange) and add this to
#your alias file as well
#
#mint: "|/home/xchequer/minter.sh"
#
#send any message to mint, and you will get a signed coin
#
#create a new blinded protocoin, and mail the signed coin and the
#blinded protocoin together to xchequer, and you will get back the
#signed blinded coin and the old one will be marked as spent 
#
#And you can also use this to generate titles - you will need to add
#-T (maybe automatically) to issue and exchange titled coins.

export HOME=/home/xchequer
export XCHQ=/usr/local/bin/xchequer
cd $HOME
cat >input$$
formail -r <input$$ >return$$

#####Select one of the following three...

##create a new title
#formail -x Subject <input$$ | sed "s/^ //g" >title$$
#$XCHQ -i 4F56C649 -p cresyspass -t "`cat title$$`" >coin$$ 2>error$$

##mint a new coin
#$XCHQ -i 4F56C649 -p cresyspass -m >coin$$ 2>error$$

#exchange the coin, putting old on spent list
$XCHQ -X -p cresyspass <input$$ >coin$$ 2>error$$

#####

#send the reply
cat return$$ coin$$ error$$ | /usr/lib/sendmail -oem -t -oi

cat coin$$ >>coins.sav
#cat title$$ >>coins.sav

#cat input$$ return$$ coin$$ error$$ >>debuglog
rm -f input$$ return$$ coin$$ error$$ title$$
