ctf-tools/bin/manage-tools

184 lines
3.6 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
}
function tool_log()
{
echo "$(tput setaf 4 2>/dev/null)TOOLS | $TOOL |$(tput sgr0 2>/dev/null) $@"
}
2015-05-08 02:27:54 +00:00
while [[ $1 == -* ]]
do
case $1 in
-s)
export ALLOW_SUDO=1
2015-05-08 02:27:54 +00:00
;;
*)
usage
exit
2015-05-08 02:27:54 +00:00
;;
esac
shift
done
[ -z "$ALLOW_SUDO" ] && export ALLOW_SUDO=0
ACTION=$1
TOOL=$2
if [ "$TOOL" == "all" ]
then
for t in $($0 list)
do
$0 $ACTION $t
done
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)
2016-02-04 07:30:38 +00:00
PACKAGE_REQS="build-essential libtool g++ gcc texinfo curl wget automake autoconf python-dev git subversion unzip"
PACKAGE_COUNT=$(echo $PACKAGE_REQS | tr ' ' '\n' | wc -l)
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
2016-02-04 08:07:08 +00:00
TOOL=SETUP tool_log "Please install the following packages: $PACKAGE_REQS"
fi
fi
if ! dpkg --print-foreign-architectures | grep -q i386
then
if [ "$ALLOW_SUDO" -eq 1 ]
then
sudo dpkg --add-architecture i386
sudo apt-get update || true
2016-02-04 08:07:08 +00:00
else
TOOL=SETUP tool_log "Certain tools need i386 libraries (enable with 'dpkg --add-architecture i386; apt-get update')."
fi
fi
2015-05-08 02:27:54 +00:00
echo "PATH=\"$PWD/bin:\$PATH\"" >> ~/.bashrc
2016-02-04 08:07:48 +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/* .
tool_log "bin symlinks updated"
2015-05-11 10:02:14 +00:00
cd ..
;;
install)
cd $TOOL
if git status --ignored . | egrep -q 'Untracked|Ignored'
then
tool_log "appears to already be installed. Uninstall first?"
exit 0
fi
tool_log "starting install, logging to $PWD/install.log"
rm -f install.log
[ -x ./install-root -a "$ALLOW_SUDO" -eq 1 ] && sudo ./install-root >> install.log 2>&1
if ./install >>install.log 2>&1
then
tool_log "install finished"
else
tool_log "INSTALL FAILED"
cat install.log >&2
exit 1
fi
cd ..
$0 bin $TOOL
;;
uninstall)
cd $TOOL
[ -x ./uninstall ] && ./uninstall
git clean -dffx .
tool_log "uninstall finished"
cd ..
;;
2015-05-12 20:49:34 +00:00
upgrade)
cd $TOOL
if [ -x ./upgrade ]
then
./upgrade
tool_log "upgrade complete!"
2015-05-12 20:49:34 +00:00
else
tool_log "no upgrade script -- reinstalling"
2015-05-12 20:49:34 +00:00
$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
tool_log "Tests not enabled."
2015-11-04 07:14:43 +00:00
else
$0 install $TOOL
2015-11-04 07:14:43 +00:00
cd $TOOL
if [ -f ./test ]
then
tool_log "Running test script."
2015-11-04 07:14:43 +00:00
./test
tool_log "test script succeeded!"
2015-11-04 07:14:43 +00:00
else
tool_log "Install succeeded. No test script!"
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