PROGNAME=`basename $0` || exit 1 QUIET=0 VERBOSE=1 function fatal { echo "${PROGNAME}:${1:-"unknown error"}" 1>&2 exit 1 } function warning { if [ $QUIET = 0 ]; then echo "${PROGNAME}:warning:$1" 1>&2; fi } function verbose { if [ $VERBOSE = 1 ]; then echo "${PROGNAME}:$1" 1>&2; fi } CONFIGFILE=$HOME/.ccmgrrc if [ -f $CONFIGFILE ]; then . $CONFIGFILE else fatal "configurationfile $CONFIGFILE not found" fi function compare { [ "x$1" = "x$3" ] } function symbol { echo $2 } # needs (verfied) daemon and symbol, some currencies have # special cases function getdifficulty { DIFF=`$1 getdifficulty` if [ "x$2" = "xNVC" -o "x$2" = "xBTB" -o "x$2" = "xCAP" -o "x$2" = "xCGB" ]; then echo $DIFF | tr -d "\n" | cut -f 4 -d ' ' | tr -d , else echo $DIFF fi } function printstatus { D="$HOME/src/$1" if [ ! -x $D ]; then echo "daemon $D not executable ?!?!?" exit 1 fi DIFF=`getdifficulty $D $2` printf "$2: %18.8f %8d %18f %36s %3d\n" \ `$D getbalance | cut -f 1 -d '+'` \ `$D getblockcount` \ $DIFF \ `$D getaccountaddress ""` \ `$D getconnectioncount` } # return 0 als running en 1 als niet function checkrunning { D="$HOME/src/$1" C="$HOME/.$3" # check if the PID in the PID file matches a # process with the correct name PID=`cat $C/$3*.pid 2> /dev/null` if [ "x$PID" = "x" ]; then return 1 fi if [ "x$D" != "x`cat /proc/$PID/cmdline 2> /dev/null`" ]; then # PID does not match return 1 fi return 0 } function start_daemon { D="$HOME/src/$1" if [ ! -x $D ]; then warning "daemon $D not executable ?!?!?" else verbose "starting $2" $D > /dev/null fi } function stop_daemon { D="$HOME/src/$1" if [ ! -x $D ]; then warning "daemon $D not executable ?!?!?" else verbose "stopping $2" $D stop fi } function ccstart { TARGET=$1 for i in "${CCINFO[@]}"; do if compare $TARGET $i || [ "x$TARGET" = "x" ]; then if checkrunning $i; then warning "`symbol $i` is already running" else start_daemon $i fi fi done } function ccstop { TARGET=$1 for i in "${CCINFO[@]}"; do if compare $TARGET $i || [ "x$TARGET" = "x" ]; then if checkrunning $i; then stop_daemon $i else warning "`symbol $i` is not running" fi fi done } function ccinfo { TARGET=$1 for i in "${CCINFO[@]}"; do if compare $TARGET $i || [ "x$TARGET" = "x" ]; then if checkrunning $i; then printstatus $i else warning "`symbol $i` is not running" fi fi done } function rpccall { RPCCOMMAND=$1 shift D="$HOME/src/$1" if [ ! -x $D ]; then echo "daemon $D not executable ?!?!?" exit 1 fi $D $RPCCOMMAND } function ccrpc { TARGET=$1 shift RPCCOMMAND="$@" verbose "TARGET=$TARGET" verbose "RPCCOMMAND=$RPCCOMMAND" for i in "${CCINFO[@]}"; do if compare $TARGET $i; then if checkrunning $i; then rpccall "$RPCCOMMAND" $i else warning "`symbol $i` is not running" fi fi done } function backupwallet { D="$HOME/src/$1" C="$HOME/.$3" if [ ! -x $D ]; then echo "daemon $D not executable ?!?!?" exit 1 fi WALLET=$DIR/wallet.$2.dat if checkrunning $1 $2 $3; then echo -n "$2 exporting wallet..." $D backupwallet $WALLET else echo -n "$2 copying wallet..." cp $C/wallet.dat $WALLET fi echo -n " encrypting wallet..." gpg -e -r $KEY $WALLET echo -n " cleaning up..." shred -u $WALLET echo } function ccbak { DATE=`date +"%Y%m%d%H%M%S"` FILE="cryptocoins$DATE.`hostname`.tar.gz" DIR="$HOME/tmp/cryptocoins$DATE" KEY="0458FCEF" mkdir $DIR cd $DIR if [ ! -f ~/.ssh/ccbak.key ]; then fatal ccbak.key not available fi for i in "${CCINFO[@]}"; do backupwallet $i done gpg --armor --export-secret-keys 0458FCEF > gpg_secret_key echo -n "downloading password database..." wget -q http://penta.snel.it/~rsnel/.pwman.db.gpg echo " checking signature on password file..." if ! gpg -q --verify .pwman.db.gpg; then fatal "signature on password file fails :(" fi cd .. tar -czf $HOME/backup/$FILE cryptocoins$DATE/ rm -f -r cryptocoins$DATE/ for i in "${BACKUP_TARGETS[@]}"; do scp -i ~/.ssh/ccbak.key $HOME/backup/$FILE $i:backup/$FILE done #scp -q -i ~/.ssh/ccbak.key $HOME/backup/$FILE ultra.hvs.snel.it:backup/$FILE #scp -q -i ~/.ssh/ccbak.key $HOME/backup/$FILE parallel.hvs.snel.it:backup/$FILE #scp -q -i ~/.ssh/ccbak.key $HOME/backup/cryptocoins$DATE.tar.gz ysolde.hvs.snel.it:backup/$FILE #scp -q -i ~/.ssh/ccbak.key $HOME/backup/cryptocoins$DATE.tar.gz penta:backup/$FILE #scp -q -i ~/.ssh/ccbak.key $HOME/backup/cryptocoins$DATE.tar.gz rik@d-brane.net:backup/$FILE #scp -q -i ~/.ssh/ccbak.key $HOME/backup/cryptocoins$DATE.tar.gz ekenit.snel.it:backup/$FILE } function ccmgr { for i in "${CCINFO[@]}"; do if checkrunning $i; then echo `symbol $i` running else echo `symbol $i` not running fi done } case $PROGNAME in ccstart) ccstart "$1" ;; ccstop) ccstop "$1" ;; ccinfo) ccinfo "$1" ;; ccrpc) if [ "x$1" = "x" ]; then fatal "argument is required" fi if [ "x$2" = "x" ]; then ccrpc $1 getinfo else ccrpc "$@" fi ;; ccbak) ccbak ;; *) ccmgr ;; esac