3 SCRIPT_NAME
=$
(basename "$0")
4 SCRIPTS_DIR
=$
(dirname "$0")
6 TOOL_NAMES
=(push-all pull-all merge-forward list-tor-branches resquash
)
10 echo "$SCRIPT_NAME [-h] [-n] [-v] [-f] <all|hooks|tools|aliases>"
13 echo " -h: show this help text"
15 echo " -v: verbose mode"
16 echo " -f: force-install even if \$TOR_DEVTOOLS_DIR looks fishy"
19 echo " hooks: install git hooks in this repository."
20 echo " tools: install scripts in \$TOR_DEVTOOLS_DIR"
21 echo " aliases: set up global git aliases for git tools in \$TOR_DEVTOOLS_DIR"
22 echo " all: all of the above."
33 while getopts "hnfv" opt
; do
51 for item
in "${@:$OPTIND}"; do
53 hooks
) INSTALL_HOOKS
=1
55 tools
) INSTALL_TOOLS
=1
57 aliases
) INSTALL_ALIASES
=1
63 *) echo "Unrecognized mode '$item'"
70 if [[ $VERBOSE = 1 ]]; then
88 if [[ $INSTALL_HOOKS = 0 && $INSTALL_TOOLS = 0 && $INSTALL_ALIASES = 0 ]]; then
89 echo "Nothing to do. Try $SCRIPT_NAME -h for a list of commands."
93 if [[ $INSTALL_TOOLS = 1 ||
$INSTALL_ALIASES = 1 ]]; then
94 if [[ -z "$TOR_DEVTOOLS_DIR" ]] ; then
95 fail
"\$TOR_DEVTOOLS_DIR was not set."
97 note
"Checking whether \$TOR_DEVTOOLS_DIR ($TOR_DEVTOOLS_DIR) is a git repo..."
98 GITDIR
=$
(cd "$TOR_DEVTOOLS_DIR" && git rev-parse
--git-dir 2>/dev
/null
)
99 note
"GITDIR is $GITDIR"
100 if [[ -n "$GITDIR" ]] ; then
102 You have asked me to install to \$TOR_DEVTOOLS_DIR ($TOR_DEVTOOLS_DIR).
103 That is inside a git repository, so you might not want to install there:
104 depending on what you pull or push, you might find yourself giving somebody
105 else write access to your scripts. I think you should just use ~/bin or
110 if [[ "$FORCE" = 1 ]] ; then
111 echo "I will install anyway, since you said '-f'."
113 echo "I will not install. You can tell me -f if you are really sure."
121 if [[ ! -d "$SCRIPTS_DIR" ||
! -e "$SCRIPTS_DIR/git-push-all.sh" ]]; then
122 fail
"Couldn't find scripts in '$SCRIPTS_DIR'"
125 if [[ $DRY_RUN = 1 ]]; then
134 # ======================================================================
135 if [[ $INSTALL_HOOKS = 1 ]]; then
136 HOOKS_DIR
=$
(git rev-parse
--git-path hooks
)
138 note
"Looking for hooks directory"
140 if [[ -z "$HOOKS_DIR" ||
! -d "$HOOKS_DIR" ]]; then
141 fail
"Couldn't find git hooks directory."
144 note
"Found hooks directory in $HOOKS_DIR"
146 note
"Installing hooks"
147 for fn
in "$SCRIPTS_DIR"/*.git-hook
; do
148 name
=$
(basename "$fn")
149 $RUN install -b "$fn" "${HOOKS_DIR}/${name%.git-hook}"
154 # ======================================================================
155 if [[ $INSTALL_TOOLS = 1 ]]; then
156 note
"Installing tools."
157 note
"Looking for \$TOR_DEVTOOLS_DIR ($TOR_DEVTOOLS_DIR)"
159 if [[ ! -d "$TOR_DEVTOOLS_DIR" ]]; then
160 note
"Creating directory"
161 $RUN mkdir
-p "$TOR_DEVTOOLS_DIR"
164 note
"Copying scripts"
165 for tool
in "${TOOL_NAMES[@]}"; do
166 $RUN install -b "${SCRIPTS_DIR}/git-${tool}.sh" "${TOR_DEVTOOLS_DIR}/"
170 # ======================================================================
171 if [[ $INSTALL_ALIASES = 1 ]]; then
172 note
"Installing aliases."
173 note
"Looking for \$TOR_DEVTOOLS_DIR ($TOR_DEVTOOLS_DIR)"
175 note
"Checking for ${TOR_DEVTOOLS_DIR}/git-push-all.sh"
176 if [[ ! -x "${TOR_DEVTOOLS_DIR}/git-push-all.sh" ]]; then
177 if [[ $DRY_RUN = 0 ]]; then
178 fail
"Could not find scripts in \$TOR_DEVTOOLS_DIR"
182 note
"Setting aliases"
183 for tool
in "${TOOL_NAMES[@]}"; do
184 $RUN git config
--global "alias.$tool" \
!"${TOR_DEVTOOLS_DIR}/git-${tool}.sh"