2 # NOTE: Not a script, to be included by scripts
5 BASEDIR=rundir/${TESTNAME}/
9 rm -f ${BASEDIR}cokebank.db
11 # Template configuration (disables door and the coke machine)
12 cat << EOF > ${BASEDIR}cfg_server.conf
13 # AUTOGENERATED Test ${TESTNAME}
15 cokebank_database ${BASEDIR}cokebank.db
16 items_file ${BASEDIR}cfg_items.conf
17 door_serial_port /dev/null
19 coke_modbus_address 0.0.0.0
27 echo "# AUTOGENERATED Test ${TESTNAME}" > ${BASEDIR}cfg_items.conf
28 echo "pseudo 0 0 Test item" >> ${BASEDIR}cfg_items.conf
31 echo "TEST ${TESTNAME}: "$*
34 echo "TEST ${TESTNAME} FAIL: "$*
41 FAIL "Command \`$cmd\` failed"
45 DISPENSE="../dispense -f /dev/null -H localhost -P ${PORT}"
47 LD_LIBRARY_PATH=.. ../dispsrv -f ${BASEDIR}cfg_server.conf --dont-daemonise -d 2 > ${BASEDIR}server.log 2>&1 &
51 if pidof dispsrv | grep ${server_pid} > /dev/null; then
52 LOG "Killing ${server_pid}"
53 kill ${server_pid}; true
55 LOG "Server already terminated"
60 LOG "Server running on PID ${server_pid}"
62 # - Make sure that the server started
63 if ! (echo "" | nc localhost ${PORT}); then
64 LOG "Server not responding on ${PORT}"
65 LOG "Server log contents:"
66 cat ${BASEDIR}server.log
70 if [[ "x$USER" == "xroot" ]]; then
71 FAIL "Running as root"
73 # Ensure that the database doesn't already contain the current user
74 # - 1. Protects against running the test against the production database
75 # - 2. Allows adding the current user as an admin
76 if $DISPENSE acct "${USER}" 2> /dev/null; then
77 FAIL "Database contains '$USER', are you running on production?"
79 # Add the current user as an admin
80 sqlite3 "${BASEDIR}cokebank.db" "INSERT INTO accounts (acct_name,acct_is_admin,acct_uid) VALUES ('${USER}',1,1);"