2016-06-01 13:00:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -eu -o pipefail
|
|
|
|
# set -x
|
2015-05-07 20:28:40 +00:00
|
|
|
|
2015-05-11 09:56:55 +00:00
|
|
|
function usage()
|
|
|
|
{
|
|
|
|
cat <<END
|
2016-09-23 15:14:34 +00:00
|
|
|
Usage: $(basename $0) [-sv] (list|setup|install|uninstall|bin|search) tool
|
2015-05-11 10:02:14 +00:00
|
|
|
|
2015-05-11 09:56:55 +00:00
|
|
|
Where:
|
2016-02-18 15:10:59 +00:00
|
|
|
-s allow running things with sudo (i.e., to install debs)
|
2016-09-23 15:14:34 +00:00
|
|
|
-v verbose mode. print log while installing
|
2016-10-10 10:13:59 +00:00
|
|
|
-f force certain actions (such as installing over an installed tool)
|
2016-02-18 15:10:59 +00:00
|
|
|
tool the name of the tool. if "all", does the action on all tools
|
2015-05-11 10:02:14 +00:00
|
|
|
|
|
|
|
Actions:
|
2016-02-18 15:10:59 +00:00
|
|
|
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
|
|
|
|
reinstall reinstalls a tool
|
|
|
|
upgrade upgrades a tool
|
|
|
|
bin re-links tool binaries into ctf-tools/bin
|
|
|
|
search search description and name of tools
|
2015-05-11 09:56:55 +00:00
|
|
|
|
|
|
|
END
|
|
|
|
}
|
|
|
|
|
2015-12-10 00:14:03 +00:00
|
|
|
function tool_log()
|
|
|
|
{
|
|
|
|
echo "$(tput setaf 4 2>/dev/null)TOOLS | $TOOL |$(tput sgr0 2>/dev/null) $@"
|
|
|
|
}
|
|
|
|
|
2016-02-18 15:10:59 +00:00
|
|
|
|
|
|
|
function detect_distribution()
|
|
|
|
{
|
2016-11-15 14:25:11 +00:00
|
|
|
if which pacman >/dev/null 2>&1; then
|
2016-02-18 15:10:59 +00:00
|
|
|
echo "archlinux"
|
2016-11-15 14:25:11 +00:00
|
|
|
elif which apt-get >/dev/null 2>&1; then
|
|
|
|
if lsb_release -a 2>/dev/null | grep -i ubuntu >/dev/null 2>&1; then
|
2016-06-06 14:25:06 +00:00
|
|
|
echo "ubuntu"
|
|
|
|
else
|
|
|
|
echo "debian"
|
|
|
|
fi
|
2016-02-18 15:10:59 +00:00
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-02 09:51:59 +00:00
|
|
|
function base_build_setup_debian()
|
2016-02-18 15:10:59 +00:00
|
|
|
{
|
2016-06-02 11:41:29 +00:00
|
|
|
PACKAGE_REQS="build-essential libtool g++ gcc texinfo curl wget automake autoconf python python-dev git subversion unzip virtualenvwrapper"
|
2016-06-01 13:00:45 +00:00
|
|
|
PACKAGE_COUNT=$(echo $PACKAGE_REQS | tr ' ' '\n' | wc -l)
|
|
|
|
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
|
|
|
|
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
|
|
|
|
else
|
|
|
|
TOOL=SETUP tool_log "Certain tools need i386 libraries (enable with 'dpkg --add-architecture i386; apt-get update')."
|
|
|
|
fi
|
|
|
|
fi
|
2016-02-18 15:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function base_build_setup_arch()
|
|
|
|
{
|
2016-06-02 09:51:59 +00:00
|
|
|
PACKAGE_REQS="curl wget python2 python3 git subversion unzip python-virtualenvwrapper"
|
2016-06-01 13:00:45 +00:00
|
|
|
if [ "$ALLOW_SUDO" -eq 1 ]; then
|
2016-06-02 10:11:47 +00:00
|
|
|
sudo pacman -Syu --noconfirm --needed $PACKAGE_REQS
|
|
|
|
sudo pacman -Syu --noconfirm --needed base-devel || true
|
2016-06-01 13:00:45 +00:00
|
|
|
else
|
|
|
|
TOOL=SETUP tool_log "Please install the following packages: $PACKAGE_REQS"
|
|
|
|
fi
|
2016-02-18 15:10:59 +00:00
|
|
|
|
2016-06-01 13:00:45 +00:00
|
|
|
if ! grep "^\[multilib\]$" /etc/pacman.conf >/dev/null; then
|
|
|
|
if [ "$ALLOW_SUDO" -eq 1 ]; then
|
|
|
|
sudo sh -c 'cat >> /etc/pacman.conf' <<EOF
|
2016-02-18 15:10:59 +00:00
|
|
|
|
|
|
|
[multilib]
|
|
|
|
Include = /etc/pacman.d/mirrorlist
|
|
|
|
EOF
|
2016-06-01 13:00:45 +00:00
|
|
|
else
|
|
|
|
TOOL=SETUP tool_log "Certain tools need i386 libraries (enable multilib in /etc/pacman.conf')."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ALLOW_SUDO" -eq 1 ] \
|
|
|
|
&& grep "^\[multilib\]$" /etc/pacman.conf >/dev/null \
|
|
|
|
&& ! sudo pacman -Qk gcc-multilib >/dev/null
|
|
|
|
then
|
|
|
|
sudo pacman -Syy --noconfirm
|
|
|
|
#sudo pacman -Syu --noconfirm multilib-devel
|
|
|
|
# unfortunately we cannot do --noconfirm if we might choose to replace
|
|
|
|
# a package such as gcc with gcc-multilib, therefore this workaround
|
|
|
|
printf "\ny\ny\ny\n" | sudo pacman -Syu multilib-devel
|
|
|
|
fi
|
2016-02-18 15:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function base_build_setup()
|
|
|
|
{
|
2016-04-01 08:46:58 +00:00
|
|
|
case "$1" in
|
|
|
|
"ubuntu")
|
2016-06-02 10:11:47 +00:00
|
|
|
;& # fallthrough
|
2016-06-02 09:51:59 +00:00
|
|
|
"debian")
|
|
|
|
base_build_setup_debian
|
2016-04-01 08:46:58 +00:00
|
|
|
;;
|
|
|
|
"archlinux")
|
|
|
|
base_build_setup_arch
|
2016-06-02 12:11:09 +00:00
|
|
|
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
|
2016-04-01 08:46:58 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
TOOL=SETUP tool_log "Cannot detect or unsupported distribution"
|
|
|
|
esac
|
2016-06-02 12:11:09 +00:00
|
|
|
|
|
|
|
## setup PATH for several shells
|
|
|
|
|
|
|
|
echo "export PATH=\"$PWD/bin:\$PATH\"" >> ~/.bashrc
|
|
|
|
|
|
|
|
if [ -e ~/.zshrc ]
|
|
|
|
then
|
|
|
|
echo "export PATH=\"$PWD/bin:\$PATH\"" >> ~/.zshrc
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e ~/.config/fish/config.fish ]; then
|
|
|
|
echo "set -x PATH $PWD/bin \$PATH " >> ~/.config/fish/config.fish
|
|
|
|
fi
|
|
|
|
|
2016-10-12 15:39:16 +00:00
|
|
|
if [[ ! -e "$PWD/bin/ctf-tools-pip3" ]]; then
|
|
|
|
ln -s "$PWD/bin/ctf-tools-pip" "$PWD/bin/ctf-tools-pip3"
|
|
|
|
fi
|
|
|
|
|
2016-06-02 12:11:09 +00:00
|
|
|
# create the py2 virtualenv
|
2016-06-02 14:31:30 +00:00
|
|
|
"$PWD/bin/ctf-tools-pip" freeze 2>&1 >/dev/null
|
2016-09-21 09:20:39 +00:00
|
|
|
|
|
|
|
# create the py3 virtualenv
|
|
|
|
"$PWD/bin/ctf-tools-pip3" freeze 2>&1 >/dev/null
|
2016-02-18 15:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-02 10:11:47 +00:00
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-02-18 15:10:59 +00:00
|
|
|
|
|
|
|
DISTRI=$(detect_distribution)
|
|
|
|
|
2015-05-08 02:27:54 +00:00
|
|
|
while [[ $1 == -* ]]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-s)
|
2015-12-10 00:24:43 +00:00
|
|
|
export ALLOW_SUDO=1
|
2015-05-08 02:27:54 +00:00
|
|
|
;;
|
2016-10-10 10:13:59 +00:00
|
|
|
-f)
|
|
|
|
export FORCE=1
|
|
|
|
;;
|
2016-09-23 15:14:34 +00:00
|
|
|
-v)
|
|
|
|
export VERBOSE_OUTPUT=1
|
|
|
|
;;
|
2015-05-08 02:27:54 +00:00
|
|
|
*)
|
2015-05-11 09:56:55 +00:00
|
|
|
usage
|
|
|
|
exit
|
2015-05-08 02:27:54 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2016-06-02 14:30:28 +00:00
|
|
|
[[ -z ${ALLOW_SUDO+x} ]] && export ALLOW_SUDO=0
|
2016-10-10 10:13:59 +00:00
|
|
|
[[ -z ${FORCE+x} ]] && export FORCE=0
|
2016-09-23 15:14:34 +00:00
|
|
|
[[ -z ${VERBOSE_OUTPUT+x} ]] && export VERBOSE_OUTPUT=0
|
2015-12-10 00:24:43 +00:00
|
|
|
|
2016-06-02 10:11:47 +00:00
|
|
|
if [[ $# -ge 1 ]]; then
|
|
|
|
ACTION="$1"
|
|
|
|
fi
|
|
|
|
if [[ $# -eq 2 ]]; then
|
|
|
|
TOOL="$2"
|
|
|
|
else
|
|
|
|
TOOL=""
|
|
|
|
fi
|
2015-05-07 20:28:40 +00:00
|
|
|
|
2015-05-11 09:56:55 +00:00
|
|
|
if [ "$TOOL" == "all" ]
|
|
|
|
then
|
|
|
|
for t in $($0 list)
|
|
|
|
do
|
2015-12-10 00:24:43 +00:00
|
|
|
$0 $ACTION $t
|
2015-05-11 09:56:55 +00:00
|
|
|
done
|
2015-05-12 04:48:44 +00:00
|
|
|
elif [ -z "$TOOL" -a "$ACTION" != "list" -a "$ACTION" != "setup" ]
|
2015-05-11 09:56:55 +00:00
|
|
|
then
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2015-05-07 20:28:40 +00:00
|
|
|
cd $(dirname "${BASH_SOURCE[0]}")/..
|
|
|
|
|
|
|
|
case $ACTION in
|
2015-05-08 02:27:54 +00:00
|
|
|
setup)
|
2016-02-04 08:07:08 +00:00
|
|
|
|
2016-04-01 08:46:58 +00:00
|
|
|
base_build_setup "$DISTRI"
|
2015-05-08 02:27:54 +00:00
|
|
|
;;
|
2015-05-07 20:28:40 +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
|
2016-09-21 12:03:01 +00:00
|
|
|
if [ -d ../$TOOL/bin ]; then
|
|
|
|
ln -sf ../$TOOL/bin/* .
|
|
|
|
tool_log "bin symlinks updated"
|
|
|
|
fi
|
2015-05-11 10:02:14 +00:00
|
|
|
cd ..
|
2015-05-07 20:28:40 +00:00
|
|
|
;;
|
|
|
|
install)
|
|
|
|
cd $TOOL
|
2016-10-10 10:13:59 +00:00
|
|
|
if [ "$FORCE" -eq 0 ] && git status --ignored . | egrep -q 'Untracked|Ignored'
|
2015-05-11 07:51:52 +00:00
|
|
|
then
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "appears to already be installed. Uninstall first?"
|
2015-05-11 07:51:52 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2015-05-07 20:28:40 +00:00
|
|
|
|
2015-12-10 00:24:18 +00:00
|
|
|
tool_log "starting install, logging to $PWD/install.log"
|
2015-12-10 00:18:51 +00:00
|
|
|
rm -f install.log
|
2016-06-06 13:11:08 +00:00
|
|
|
|
2016-06-06 14:25:06 +00:00
|
|
|
# first get distri specific dependencies
|
|
|
|
if [[ $(find . -name 'install-root*' | wc -l) -ge 1 ]]; then
|
|
|
|
INSTALL_ROOT_SCRIPT="./install-root-$DISTRI"
|
|
|
|
# use debian install script if we are on ubuntu and no ubuntu
|
|
|
|
# specific install script exists
|
|
|
|
if [[ "$DISTRI" == "ubuntu" \
|
|
|
|
&& ! -x "$INSTALL_ROOT_SCRIPT" \
|
|
|
|
&& -x "./install-root-debian" ]]
|
|
|
|
then
|
|
|
|
INSTALL_ROOT_SCRIPT="./install-root-debian"
|
|
|
|
fi
|
|
|
|
if [[ -x "$INSTALL_ROOT_SCRIPT" && "$ALLOW_SUDO" -eq 1 ]]; then
|
|
|
|
if ! sudo env DISTRI=$DISTRI "$INSTALL_ROOT_SCRIPT" >> install.log 2>&1;
|
|
|
|
then
|
|
|
|
tool_log "INSTALL FAILED"
|
|
|
|
cat install.log >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
tool_log "Warning: make sure build dependencies are installed!"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# execute install script
|
2016-10-12 02:28:46 +00:00
|
|
|
set +e
|
2016-09-23 15:14:34 +00:00
|
|
|
if [ "$VERBOSE_OUTPUT" -eq 1 ]; then
|
2016-11-15 14:25:11 +00:00
|
|
|
DISTRI=$DISTRI ./install 2>&1 | tee -a install.log
|
2016-09-23 15:14:34 +00:00
|
|
|
else
|
2016-11-15 14:25:11 +00:00
|
|
|
DISTRI=$DISTRI ./install >>install.log 2>&1
|
2016-09-23 15:14:34 +00:00
|
|
|
fi
|
2016-10-12 02:28:46 +00:00
|
|
|
INSTALL_FAILED=$?
|
|
|
|
set -e
|
|
|
|
|
2016-10-12 03:41:49 +00:00
|
|
|
if [ "$INSTALL_FAILED" -eq 0 ]; then
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "install finished"
|
|
|
|
else
|
|
|
|
tool_log "INSTALL FAILED"
|
|
|
|
cat install.log >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-05-07 20:28:40 +00:00
|
|
|
|
|
|
|
cd ..
|
|
|
|
$0 bin $TOOL
|
|
|
|
;;
|
|
|
|
uninstall)
|
|
|
|
cd $TOOL
|
|
|
|
|
2016-06-02 14:30:14 +00:00
|
|
|
tool_log "starting uninstall, logging to $PWD/uninstall.log"
|
|
|
|
[ -x ./uninstall ] && ./uninstall >> uninstall.log 2>&1
|
|
|
|
git clean -dffx . >/dev/null 2>&1
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "uninstall finished"
|
2015-05-07 20:28:40 +00:00
|
|
|
|
|
|
|
cd ..
|
|
|
|
;;
|
2015-05-12 20:49:34 +00:00
|
|
|
upgrade)
|
|
|
|
cd $TOOL
|
|
|
|
if [ -x ./upgrade ]
|
|
|
|
then
|
|
|
|
./upgrade
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "upgrade complete!"
|
2015-05-12 20:49:34 +00:00
|
|
|
else
|
2015-12-10 00:14:03 +00:00
|
|
|
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)
|
2016-10-10 10:13:59 +00:00
|
|
|
if [ "$FORCE" -eq 0 ] && ! cat README.md | grep "<\!--tool-->" | grep "| \[$TOOL\](" | grep -q -- "--test--"
|
2015-11-04 07:14:43 +00:00
|
|
|
then
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "Tests not enabled."
|
2015-11-04 07:14:43 +00:00
|
|
|
else
|
2015-12-10 00:24:43 +00:00
|
|
|
$0 install $TOOL
|
2015-11-04 07:14:43 +00:00
|
|
|
|
|
|
|
cd $TOOL
|
|
|
|
if [ -f ./test ]
|
|
|
|
then
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "Running test script."
|
2016-10-12 02:28:46 +00:00
|
|
|
if ! ./test
|
|
|
|
then
|
|
|
|
tool_log "$TOOL test failed!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-12-10 00:14:03 +00:00
|
|
|
tool_log "test script succeeded!"
|
2015-11-04 07:14:43 +00:00
|
|
|
else
|
2015-12-10 00:14:03 +00:00
|
|
|
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
|
|
|
;;
|
2015-05-07 20:28:40 +00:00
|
|
|
*)
|
|
|
|
echo "TOOLS | ERROR | unknown action $ACTION"
|
|
|
|
;;
|
|
|
|
esac
|