64 lines
1.7 KiB
Bash
Executable File
64 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Adds an item to the inventory, given the item tag
|
|
#
|
|
# 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
|
|
|
|
# we should be provided with the item "tag", which identifies the item itself as
|
|
# well as additional metadata
|
|
tag="$1"
|
|
|
|
inv_path=$( $mypath/getinvpath )
|
|
item_path="$mypath/../items"
|
|
item_id=$( inv-item-id "$tag" )
|
|
item_count=$( inv-item-count "$tag" )
|
|
item_file="$item_path/$item_id"
|
|
inv_item_file="$inv_path/$item_id"
|
|
|
|
# use -gt rather than -lt to ensure we'll still fail if $item_count is not an
|
|
# integer
|
|
[ $item_count -gt 0 ] || {
|
|
echo "Item count required" >&2
|
|
exit 1
|
|
}
|
|
|
|
# does the item we're attempting to access actually exist?
|
|
[ -r "$item_file" ] || {
|
|
echo "Item does not exist" >&2
|
|
exit 1
|
|
}
|
|
|
|
# attempt to create the inventory in case it does not exist
|
|
mkdir -p "$inv_path" 2>/dev/null
|
|
|
|
# currently unused
|
|
attr=''
|
|
|
|
# append item(s) to inventory
|
|
for i in $( seq 1 $item_count ); do
|
|
echo "$sttr" >> "$inv_item_file"
|
|
done
|
|
|