#!/usr/bin/env bash SCRIPT_NAME=$(basename "$0") SCRIPTS_DIR=$(dirname "$0") TOOL_NAMES=(push-all pull-all merge-forward list-tor-branches) function usage() { echo "$SCRIPT_NAME [-h] [-n] [-v] [-f] " echo echo " flags:" echo " -h: show this help text" echo " -n: dry-run" echo " -v: verbose mode" echo " -f: force-install even if \$TOR_DEVTOOLS_DIR looks fishy" echo echo " modes:" echo " hooks: install git hooks in this repository." echo " tools: install scripts in \$TOR_DEVTOOLS_DIR" echo " aliases: set up global git aliases for git tools in \$TOR_DEVTOOLS_DIR" echo " all: all of the above." } INSTALL_HOOKS=0 INSTALL_TOOLS=0 INSTALL_ALIASES=0 DRY_RUN=0 VERBOSE=0 FORCE=0 while getopts "hnfv" opt; do case "$opt" in h) usage exit 0 ;; n) DRY_RUN=1 ;; v) VERBOSE=1 ;; f) FORCE=1 ;; *) echo usage exit 1 ;; esac done for item in "${@:$OPTIND}"; do case "$item" in hooks) INSTALL_HOOKS=1 ;; tools) INSTALL_TOOLS=1 ;; aliases) INSTALL_ALIASES=1 ;; all) INSTALL_HOOKS=1 INSTALL_TOOLS=1 INSTALL_ALIASES=1 ;; *) echo "Unrecognized mode '$item'" usage exit 1 ;; esac done if [[ $VERBOSE = 1 ]]; then function note() { echo "$@" } else function note() { true } fi function fail() { echo "$@" 1>&2 exit 1 } if [[ $INSTALL_HOOKS = 0 && $INSTALL_TOOLS = 0 && $INSTALL_ALIASES = 0 ]]; then echo "Nothing to do. Try $SCRIPT_NAME -h for a list of commands." exit 0 fi if [[ $INSTALL_TOOLS = 1 || $INSTALL_ALIASES = 1 ]]; then if [[ -z "$TOR_DEVTOOLS_DIR" ]] ; then fail "\$TOR_DEVTOOLS_DIR was not set." fi note "Checking whether \$TOR_DEVTOOLS_DIR ($TOR_DEVTOOLS_DIR) is a git repo..." GITDIR=$(cd "$TOR_DEVTOOLS_DIR" && git rev-parse --git-dir 2>/dev/null) note "GITDIR is $GITDIR" if [[ -n "$GITDIR" ]] ; then cat <