removed explicit full-upgrade command

This commit is contained in:
Michael Rodler 2017-12-13 14:01:03 +01:00 committed by Yan
parent 36acb6c6fc
commit 8982de556d

View file

@ -2,6 +2,9 @@
set -eu -o pipefail set -eu -o pipefail
# set -x # set -x
CTF_TOOLS_ROOT="$(dirname "${BASH_SOURCE[0]}")/.."
function usage() function usage()
{ {
cat <<END cat <<END
@ -11,7 +14,7 @@ Where:
-s allow running things with sudo (i.e., to install debs) -s allow running things with sudo (i.e., to install debs)
-v verbose mode. print log while installing -v verbose mode. print log while installing
-f force certain actions (such as installing over an installed tool) -f force certain actions (such as installing over an installed tool)
tool the name of the tool. if "all", does the action on all tools tool the name of the tool. if "all", does the action on all (installed) tools
Actions: Actions:
setup set up the environment (adds ctf-tools/bin to your \$PATH in .bashrc) setup set up the environment (adds ctf-tools/bin to your \$PATH in .bashrc)
@ -19,10 +22,9 @@ Actions:
install installs a tool install installs a tool
uninstall uninstalls a tool uninstall uninstalls a tool
reinstall reinstalls a tool reinstall reinstalls a tool
upgrade upgrades a tool upgrade upgrades a tool (use "all" to do a full upgrade of installed tools)
bin re-links tool binaries into ctf-tools/bin bin re-links tool binaries into ctf-tools/bin
search search description and name of tools search search description and name of tools
full-upgrade upgrade all installed tools
END END
} }
@ -188,6 +190,48 @@ function is_tool_installed() {
} }
function full_upgrade() {
TOOL="FULL-UPGRADE" tool_log "Upgrading all installed tools!"
succ=0
fail=0
declare -a failed
installed=$($0 list -i)
TOOL="FULL-UPGRADE" tool_log "Upgrading tools: $installed"
for t in $installed
do
TOOL="FULL-UPGRADE" tool_log "Upgrading tool $t"
if $0 upgrade $t; then
succ=$((succ+1))
else
fail=$((fail+1))
failed[${#failed[@]}]="$t"
fi
done
TOOL="FULL-UPGRADE" tool_log "failed to upgrade ${failed[@]}"
TOOL="FULL-UPGRADE" tool_log "tool full-upgrade stats - sucess=$succ failed=$fail"
}
function verify_tool_sanity() {
if [[ -z "$TOOL" ]]; then
TOOL="$ACTION" tool_log "must provide at least one tool for $ACTION"
usage
exit 1
fi
if [[ "$TOOL" == "all" ]]; then
TOOL="$ACTION" tool_log "can't handle \"all\" magic tool directly!" \
"This is probably a bug you should report."
usage
exit 1
fi
if [[ ! -d "$CTF_TOOLS_ROOT/$TOOL" ]]; then
TOOL="$ACTION" tool_log "invalid tool $TOOL"
exit 1
fi
}
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
usage usage
exit 1 exit 1
@ -229,22 +273,38 @@ else
TOOL="" TOOL=""
fi fi
if [ "$TOOL" == "all" ] # handle the special all tool
if [[ "$TOOL" == "all" ]]
then then
for t in $($0 list) case $ACTION in
do install)
$0 $ACTION $t for t in $($0 list)
done do
elif [ -z "$TOOL" -a "$ACTION" == "full-upgrade" ] $0 $ACTION $t
then done
TOOL="" exit 0
elif [ -z "$TOOL" -a "$ACTION" != "list" -a "$ACTION" != "setup" ] ;;
then bin | uninstall | reinstall)
usage for t in $($0 list -i)
exit do
$0 $ACTION $t
done
exit 0
;;
upgrade)
full_upgrade
exit 0
;;
*)
TOOL="" tool_log "action $ACTION cannot handle the special \"all\" tool"
usage
exit 1
;;
esac
fi fi
cd $(dirname "${BASH_SOURCE[0]}")/.. cd $(dirname "${BASH_SOURCE[0]}")/..
case $ACTION in case $ACTION in
@ -273,6 +333,7 @@ case $ACTION in
done done
;; ;;
bin) bin)
verify_tool_sanity
cd bin cd bin
if [ -d ../$TOOL/bin ]; then if [ -d ../$TOOL/bin ]; then
ln -sf ../$TOOL/bin/* . ln -sf ../$TOOL/bin/* .
@ -281,6 +342,7 @@ case $ACTION in
cd .. cd ..
;; ;;
install) install)
verify_tool_sanity
cd $TOOL cd $TOOL
if [ "$FORCE" -eq 0 ] && is_tool_installed "." if [ "$FORCE" -eq 0 ] && is_tool_installed "."
then then
@ -343,6 +405,7 @@ case $ACTION in
$0 bin $TOOL $0 bin $TOOL
;; ;;
uninstall) uninstall)
verify_tool_sanity
cd $TOOL cd $TOOL
tool_log "starting uninstall, logging to $PWD/uninstall.log" tool_log "starting uninstall, logging to $PWD/uninstall.log"
@ -353,6 +416,11 @@ case $ACTION in
cd .. cd ..
;; ;;
upgrade) upgrade)
if [[ "$TOOL" == "" ]]; then
full_upgrade
exit 0
fi
verify_tool_sanity
cd $TOOL cd $TOOL
if [ -x ./upgrade ] if [ -x ./upgrade ]
then then
@ -364,26 +432,6 @@ case $ACTION in
$0 install $TOOL $0 install $TOOL
fi fi
;; ;;
full-upgrade)
TOOL="FULL-UPGRADE" tool_log "Upgrading all installed tools!"
succ=0
fail=0
declare -a failed
installed=$($0 list -i)
TOOL="FULL-UPGRADE" tool_log "Upgrading tools: $installed"
for t in $installed
do
TOOL="FULL-UPGRADE" tool_log "Upgrading tool $t"
if $0 upgrade $t; then
succ=$((succ+1))
else
fail=$((fail+1))
failed[${#failed[@]}]="$t"
fi
done
TOOL="FULL-UPGRADE" tool_log "failed to upgrade ${failed[@]}"
TOOL="FULL-UPGRADE" tool_log "tool full-upgrade stats - sucess=$succ failed=$fail"
;;
reinstall) reinstall)
$0 uninstall $TOOL $0 uninstall $TOOL
$0 install $TOOL $0 install $TOOL
@ -424,5 +472,7 @@ case $ACTION in
;; ;;
*) *)
echo "TOOLS | ERROR | unknown action $ACTION" echo "TOOLS | ERROR | unknown action $ACTION"
usage
exit 1
;; ;;
esac esac