ctf-tools/bin/manage-tools

131 lines
2.4 KiB
Text
Raw Normal View History

#!/bin/bash -e
function usage()
{
cat <<END
Usage: $(basename $0) [-s] (list|setup|install|uninstall|bin) 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
bin re-links tool binaries into ctf-tools/bin
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
exit
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)
2015-05-18 07:28:48 +00:00
if [ $(dpkg -l build-essential libtool g++ gcc texinfo curl wget | grep "^ii" | wc -l) -ne 7 ]
then
if [ "$ALLOW_SUDO" -eq 1 ]
then
2015-05-18 07:28:48 +00:00
sudo apt-get install build-essential libtool g++ gcc texinfo curl wget
else
2015-05-18 07:28:48 +00:00
echo "Please install the following packages: build-essential libtool g++ gcc texinfo curl wget"
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
;;
*)
echo "TOOLS | ERROR | unknown action $ACTION"
;;
esac