Last active
October 15, 2019 10:02
-
-
Save trickeydan/30f95f7a84acb97674ad2cd4dc897b71 to your computer and use it in GitHub Desktop.
Script to empty a container using the Student Robotics Inventory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
This seems hilariously overcomplicated versus the much simpler alternative:
git mv path/to/container-dir/*sr* path/to/unknown-dir
Please blame @kierdavis who requested that this script existed.
Also, UX is something the inventory massively lacks. A decent knowledge of bash is a prerequisite for almost any operations with it.
git mv *-sr*
didn't occur to me, but it works pretty well.
An "inventory cookbook" might be a good idea.
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
This seems hilariously overcomplicated versus the much simpler alternative:
git mv path/to/container-dir/*sr* path/to/unknown-dir