File launcher.sh of Package zcash-gui
#!/bin/sh
# commands
cmd_cli=zcash-cli
cmd_daemon=zcashd
cmd_fetch_params=zcash-fetch-params
# settings
confdir=${HOME}/.zcash
conffile=${confdir}/zcash.conf
dialog_caption="ZCash GUI"
jarfile=/usr/share/zcash-gui/ZCashSwingWalletUI.jar
paramdir=${HOME}/.zcash-params
pidfile=${confdir}/${cmd_daemon}.pid
username=${USER}
# setup of params
if [ ! -d ${paramdir} ]
then
kdialog --warningcontinuecancel "ZCash have to be initialized before first use.\n\nInitialization process will be executed in the background and may take some time.\nPlease be patient.\n\nZCash GUI will start immediately after setup has been completed." --title "Setup" --caption "${dialog_caption}"
if [ $? != 0 ]
then
exit 1
fi
fi
${cmd_fetch_params} > /dev/null 2> /dev/null
if [ $? != 0 ]
then
kdialog --error "An error occurred during setup.\n\nPlease check your internet connection and retry." --title "Setup" --caption "${dialog_caption}"
rm -fr ${paramdir}
exit 1
fi
# setup of config
if [ ! -d ${confdir} ]
then
mkdir -p ${confdir}
if [ $? != 0 ]
then
kdialog --error "An error occurred during setup.\n\nYour configuration settings cannot be written to disk." --title "Setup" --caption "${dialog_caption}"
rm -fr ${paramdir}
exit 1
fi
echo "addnode=mainnet.z.cash" > ${conffile}
echo "rpcbind=localhost" >> ${conffile}
echo "rpcuser=username" >> ${conffile}
echo "rpcpassword=$(head -c 32 /dev/urandom | base64)" >> ${conffile}
fi
# start daemon
if [ ! -e ${pidfile} ]
then
${cmd_daemon} -daemon -pid=${pidfile} -datadir=${confdir} -conf=${conffile} > /dev/null
if [ $? != 0 ]
then
kdialog --error "ZCash daemon could not be started.\n\nPlease check your configuration and retry." --title "Startup" --caption "${dialog_caption}"
exit 1
fi
else
cat ${pidfile} | xargs ps > /dev/null
if [ $? != 0 ]
then
kdialog --error "ZCash daemon not alive.\n\nPlease check process, eliminate pid file and try again." --title "Startup" --caption "${dialog_caption}"
exit 1
fi
fi
# start gui
java -jar ${jarfile} > /dev/null
if [ $? != 0 ]
then
kdialog --error "ZCash GUI could not be started.\n\nPlease check your installation and retry." --title "Startup" --caption "${dialog_caption}"
exit 1
fi
# stop daemon
${cmd_cli} stop > /dev/null
if [ $? != 0 ]
then
kdialog --error "ZCash daemon could not be terminated.\n\nPlease check daemon and stop it manually." --title "Termination" --caption "${dialog_caption}"
exit 1
fi