-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-templates
executable file
·88 lines (66 loc) · 2.15 KB
/
code-templates
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
#!/usr/bin/env bash
#
# A light wrapper for using the code_templates 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 code_templates tool if it doesn't
# exist, and then calls the latex_templates tool entry point script.
# Information on the code_templates tool can be found at:
# https://github.com/qcr/code_templates
#
# For usage on how to use the code_templates tool run:
# qcr code_templates -h
#
# Author: Ben Talbot
# Version: 0.4.0
#################
### VARIABLES ###
#################
# The URL for this tool's repo
# Used for cloning - Recommend to use SSH
REPO_CLONE_URL="[email protected]:qcr/code_templates"
# Tool name
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=false
#################
### 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 services tool with provided command and arguments
${INSTALL_DIR}/${TOOL_NAME} "${ARGS[@]}"