Skip to content

Instantly share code, notes, and snippets.

@trickeydan
Last active October 15, 2019 10:02
Show Gist options
  • Save trickeydan/30f95f7a84acb97674ad2cd4dc897b71 to your computer and use it in GitHub Desktop.
Save trickeydan/30f95f7a84acb97674ad2cd4dc897b71 to your computer and use it in GitHub Desktop.
Script to empty a container using the Student Robotics Inventory
#!/usr/bin/env bash
#
# Copyright (c) 2019 Dan Trickey.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
set -o errexit -o nounset -o pipefail
function empty_box() {
unknown_dir=$(readlink -f $1)
if [ ! -d $1 ]; then
echo "UNKNOWN DIR must be a directory"
exit 2
fi
asset_dir=$(readlink -f $(sr inv-findpart $2))
if [ ! -d $asset_dir ]; then
echo "Container must be a directory."
exit 3
fi
files=$(ls $asset_dir)
for file in $files
do
if [ $file != "info" ]; then
echo "Moving $file to $(basename $unknown_dir)"
git mv "$asset_dir/$file" $unknown_dir
fi
done
}
if [ $# -eq 2 ]; then
empty_box $1 $2
exit 0
fi
if [ $# -ne 1 ]; then
echo "Usage: box-unpacker UNKNOWN_LOCATION [ASSET_CODE]"
exit 1
fi
while true; do
read -p "Scan RUB to empty: " rub
empty_box $1 $rub
done
@trickeydan
Copy link
Author

An "inventory cookbook" might be a good idea.

I like this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment