mirror of
https://github.com/zardus/ctf-tools
synced 2024-12-13 14:32:34 +00:00
132 lines
2.4 KiB
Bash
Executable file
132 lines
2.4 KiB
Bash
Executable file
#!/bin/bash -e
|
|
|
|
function usage()
|
|
{
|
|
cat <<END
|
|
Usage: $(basename $0) [-s] (list|setup|install|uninstall|bin) tool
|
|
|
|
Where:
|
|
-s allow running things with sudo (i.e., to install debs)
|
|
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
|
|
}
|
|
|
|
ALLOW_SUDO=0
|
|
while [[ $1 == -* ]]
|
|
do
|
|
case $1 in
|
|
-s)
|
|
ALLOW_SUDO=1
|
|
;;
|
|
*)
|
|
usage
|
|
exit
|
|
;;
|
|
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
|
|
setup)
|
|
PACKAGE_REQS="build-essential libtool g++ gcc texinfo curl wget automake autoconf python-dev"
|
|
PACKAGE_COUNT=10
|
|
if [ $(dpkg -l $PACKAGE_REQS | grep "^ii" | wc -l) -ne $PACKAGE_COUNT ]
|
|
then
|
|
if [ "$ALLOW_SUDO" -eq 1 ]
|
|
then
|
|
sudo apt-get -y install $PACKAGE_REQS
|
|
else
|
|
echo "Please install the following packages: $PACKAGE_REQS"
|
|
fi
|
|
fi
|
|
|
|
echo "PATH=\"$PWD/bin:\$PATH\"" >> ~/.bashrc
|
|
if [ -e ~/.zshrc ]
|
|
then
|
|
echo "PATH=\"$PWD/bin:\$PATH\"" >> ~/.zshrc
|
|
fi
|
|
;;
|
|
list)
|
|
for t in *
|
|
do
|
|
[ ! -e "$t/install" ] && continue
|
|
echo $t
|
|
done
|
|
;;
|
|
bin)
|
|
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"
|
|
[ -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 ..
|
|
;;
|
|
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
|