-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate
89 lines (69 loc) · 2.33 KB
/
template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
#
# A light wrapper for using the <TOOL-NAME> tool via qcr command.
# This is deliberately light, so that users should never
# have to update this script once they have it, but will
# always have access to the latest service tool.
#
# It installs (git clones) the <TOOL-NAME> tool if it doesn't
# exist, and then calls the <TOOL-NAME> tool entry point script.
# Information on the <TOOL-NAME> tool can be found at:
# https://github.com/qcr/<TOOL-NAME>
#
# For usage on how to use the <TOOL-NAME> tool run:
# qcr <TOOL-NAME> -h
#
# Author: James Mount
# Version: 0.2.0
#################
### VARIABLES ###
#################
# The URL for this tool's repo
# Used for cloning - Recommend to use SSH
REPO_CLONE_URL="[email protected]:qcr/<TOOL-NAME>"
# Tool name - name of entry point script in the separate repo.
# The recommendation is the script here in qcr/scripts matches
# the name of the script in the separate repo. However,
# can change TOOL_NAME if they are different.
TOOL_NAME="$(basename $(readlink -f $0))"
# The directory of containing this script
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# The install directory to the tools directory
INSTALL_DIR="$(dirname ${SCRIPT_DIR})/installed-tools/${TOOL_NAME}"
# Private Repo
PRIVATE_REPO=true
#################
### FUNCTIONS ###
#################
############
### MAIN ###
############
# Get arguments passed by qcr script,
# Arguments passed are:
# USE_CACHED
# FORCE_UPDATE_CHECK
# ARGS_TO_TOOL
USE_CACHED="${@:1:1}"
FORCE_UPDATE_CHECK="${@:2:1}"
ARGS=( "${@:3}" )
# Source common
source $(dirname ${SCRIPT_DIR})/common
# Bail if git isn't found
git_command_exists
# Check for SSH access
if [ ${PRIVATE_REPO} == true ]; then
check_for_github_ssh_access
fi
# Install tool, if required
install_tool ${REPO_CLONE_URL} ${INSTALL_DIR} ${TOOL_NAME}
# Check if using cached version or checking for updated
if [ $USE_CACHED == false ]; then
# Check for update if required
tmp=$(should_check_for_update ${INSTALL_DIR} "")
if [ "$tmp" == "1" ] || [ ${FORCE_UPDATE_CHECK} == true ]; then
printf "${INFO}Checking for update to tool '${YELLOW}${TOOL_NAME}${RESET}'\n"
check_cloned_repo_is_latest ${INSTALL_DIR} ${TOOL_NAME}
fi
fi
# Run <TOOL_NAME> tool with provided command and arguments
${INSTALL_DIR}/${TOOL_NAME} "${ARGS[@]}"