ctf-tools/bin/manage-tools

164 lines
3.2 KiB
Text
Raw Normal View History

#!/bin/bash -e
function usage()
{
cat <<END
2015-10-25 14:11:28 +00:00
Usage: $(basename $0) [-s] (list|setup|install|uninstall|bin|search) tool
2015-05-11 10:02:14 +00:00
Where:
-s allow running things with sudo (i.e., to install debs)
2015-05-11 10:02:14 +00:00
tool the name of the tool. if "all", does the action on all
tools
Actions:
setup set up the environment (adds ctf-tools/bin to your
\$PATH in .bashrc)
list list all tools (-i: only installed, -u: only
uninstalled)
install installs a tool
uninstall uninstalls a tool
2015-12-10 00:13:34 +00:00
reinstall reinstalls a tool
upgrade upgrades a tool
2015-05-11 10:02:14 +00:00
bin re-links tool binaries into ctf-tools/bin
2015-10-25 14:11:28 +00:00
search search description and name of tools
END
}
2015-05-08 02:27:54 +00:00
ALLOW_SUDO=0
while [[ $1 == -* ]]
do
case $1 in
-s)
ALLOW_SUDO=1
;;
*)
usage
exit
2015-05-08 02:27:54 +00:00
;;
esac
shift
done
ACTION=$1
TOOL=$2
if [ "$TOOL" == "all" ]
then
for t in $($0 list)
do
[ "$ALLOW_SUDO" -eq 1 ] && $0 -s $ACTION $t
[ "$ALLOW_SUDO" -eq 0 ] && $0 $ACTION $t
done
2015-11-30 20:45:39 +00:00
exit 0
elif [ -z "$TOOL" -a "$ACTION" != "list" -a "$ACTION" != "setup" ]
then
usage
exit
fi
cd $(dirname "${BASH_SOURCE[0]}")/..
case $ACTION in
2015-05-08 02:27:54 +00:00
setup)
PACKAGE_REQS="build-essential libtool g++ gcc texinfo curl wget automake autoconf python-dev"
PACKAGE_COUNT=10
2015-05-18 08:39:32 +00:00
if [ $(dpkg -l $PACKAGE_REQS | grep "^ii" | wc -l) -ne $PACKAGE_COUNT ]
then
if [ "$ALLOW_SUDO" -eq 1 ]
then
2015-05-18 08:39:32 +00:00
sudo apt-get -y install $PACKAGE_REQS
else
2015-05-18 08:39:32 +00:00
echo "Please install the following packages: $PACKAGE_REQS"
fi
fi
2015-05-08 02:27:54 +00:00
echo "PATH=\"$PWD/bin:\$PATH\"" >> ~/.bashrc
2015-05-15 23:04:12 +00:00
if [ -e ~/.zshrc ]
then
echo "PATH=\"$PWD/bin:\$PATH\"" >> ~/.zshrc
fi
2015-05-08 02:27:54 +00:00
;;
list)
for t in *
do
[ ! -e "$t/install" ] && continue
echo $t
done
;;
bin)
2015-05-11 10:02:14 +00:00
cd bin
ln -sf ../$TOOL/bin/* .
echo "TOOLS | $TOOL | bin symlinks updated"
cd ..
;;
install)
cd $TOOL
if git status --ignored . | egrep -q 'Untracked|Ignored'
then
echo "TOOLS | $TOOL | appears to already be installed. Uninstall first?"
exit 0
fi
echo "TOOLS | $TOOL | starting install"
2015-05-08 02:27:54 +00:00
[ -x ./install-root -a "$ALLOW_SUDO" -eq 1 ] && sudo ./install-root
./install
echo "TOOLS | $TOOL | install finished"
cd ..
$0 bin $TOOL
;;
uninstall)
cd $TOOL
[ -x ./uninstall ] && ./uninstall
git clean -dffx .
echo "TOOLS | $TOOL | uninstall finished"
cd ..
;;
2015-05-12 20:49:34 +00:00
upgrade)
cd $TOOL
if [ -x ./upgrade ]
then
./upgrade
echo "TOOLS | $TOOL | upgrade complete!"
else
echo "TOOLS | $TOOL | no upgrade script -- reinstalling"
$0 uninstall $TOOL
$0 install $TOOL
fi
;;
2015-12-10 00:13:34 +00:00
reinstall)
$0 uninstall $TOOL
$0 install $TOOL
;;
2015-10-25 14:11:28 +00:00
search)
2015-11-04 07:14:43 +00:00
cat README.md | grep "<\!--tool-->" | sed "s/<\!--[^-]*-->//g" | grep -i "$TOOL"
;;
test)
if ! cat README.md | grep "<\!--tool-->" | grep "| \[$TOOL\](" | grep -q -- "--test--"
then
echo "TOOLS | $TOOL | Tests not enabled."
else
[ "$ALLOW_SUDO" -eq 1 ] && $0 -s install $TOOL
[ "$ALLOW_SUDO" -eq 0 ] && $0 install $TOOL
cd $TOOL
if [ -f ./test ]
then
echo "TOOLS | $TOOL | Running test script."
./test
echo "TOOLS | $TOOL | test script succeeded!"
2015-11-05 03:00:35 +00:00
exit 0
2015-11-04 07:14:43 +00:00
else
echo "TOOLS | $TOOL | Install succeeded. No test script!"
2015-11-05 03:00:35 +00:00
exit 0
2015-11-04 07:14:43 +00:00
fi
fi
2015-10-25 14:11:28 +00:00
;;
*)
echo "TOOLS | ERROR | unknown action $ACTION"
;;
esac