#! /bin/sh # Copyright (C) 2005 Nick Urbanik # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. function usage { local prog=$(basename $0) cat <<"EOF" $prog groupname new_time_left where: groupname is a game group such as silly or educational new_time_left is an amount of time left that can be played for that group, such as 1800. If a time is specified that is longer than the limit, then the limit is the actual time that is available for playing. For example, you could have the group educational have 1800 seconds total playing time for today with: $prog educational 1800 To allow the maximum time, you can specify a number that is greater than or equal to the limit for that group. To reduce the time available for playing to the minimum, do $prog educational 0 This will also take care of changing the date to today, to make that limit current. This is the preferred way of changing playing time left. You may need to change the limit before you run this program, with change-game-limits.sh group limit_seconds EOF } if [ "$#" -ne "2" ] then usage exit 1 fi group=$1 timeleft=$2 if $(echo $timeleft|egrep -q '^[0-9]+$') then echo psql -t games --command "select limit_seconds from limits where groupname = '$group';" limit=$(psql -t games --command "select limit_seconds from limits where groupname = '$group';") let 'timeplayed = limit - timeleft' [ "$timeplayed" -lt 0 ] && timeplayed=0 echo psql games --command "update times set group_playing_time = $timeplayed, date = 'today' where groupname = '$group';" if psql games --command "update times set group_playing_time = $timeplayed, date = 'today' where groupname = '$group';" | grep 'UPDATE 1' then psql games --command "select * from times;" fi else echo Need to call this script with a number of seconds to set the group_playing_time to. usage exit 1 fi