49 lines
1.3 KiB
Plaintext
49 lines
1.3 KiB
Plaintext
|
#!/bin/bash
|
||
|
#
|
||
|
# Removes an item from the inventory
|
||
|
#
|
||
|
# Copyright (C) 2011 Mike Gerwitz
|
||
|
#
|
||
|
# This file is part of gsgp. 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 3 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, see <http://www.gnu.org/licenses/>.
|
||
|
##
|
||
|
|
||
|
mypath=$( dirname $0 )
|
||
|
|
||
|
. "$mypath/common-inv"
|
||
|
|
||
|
if [ $# -lt 1 ]; then
|
||
|
echo "Usage: $0 ITEM"
|
||
|
fi
|
||
|
|
||
|
item_id="$1"
|
||
|
inv_item_file="$( $mypath/getinvpath )/$item_id"
|
||
|
count=$( "$mypath/inv-count" $item_id )
|
||
|
|
||
|
# can't remove an item that's not in the inventory
|
||
|
if [ $count -eq 0 ]; then
|
||
|
echo "$item_id: not in inventory" >&2
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# remove an item from the item inventory
|
||
|
sed -i '1d' "$inv_item_file"
|
||
|
|
||
|
# if all the items have been removed, then remove the file to speed up inventory
|
||
|
# scanning and to keep the filesystem clean
|
||
|
(( count-- ))
|
||
|
if [ $count -eq 0 ]; then
|
||
|
rm "$inv_item_file"
|
||
|
fi
|
||
|
|