-
Notifications
You must be signed in to change notification settings - Fork 1
/
go
executable file
·121 lines (102 loc) · 3.96 KB
/
go
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /usr/bin/env bash
#
# System for creating custom URLs
#
# Allows authenticated users to create and access custom links that redirect to
# arbitrary target URLs.
#
# See .config/env.template for instructions on setting environment variables to
# configure your local development environment.
# The path where your command scripts reside
declare GO_SCRIPTS_DIR="${GO_SCRIPTS_DIR:-scripts}"
# The `GO_SCRIPT_BASH_REPO_URL` tag or branch you wish to use
declare GO_SCRIPT_BASH_VERSION="${GO_SCRIPT_BASH_VERSION:-v1.7.0}"
# The go-script-bash installation directory within your project
declare GO_SCRIPT_BASH_CORE_DIR="${GO_SCRIPT_BASH_CORE_DIR:-${0%/*}/$GO_SCRIPTS_DIR/go-script-bash}"
# The URL of the go-script-bash framework sources
declare GO_SCRIPT_BASH_REPO_URL="${GO_SCRIPT_BASH_REPO_URL:-https://github.com/mbland/go-script-bash.git}"
# URL with the release files
declare GO_SCRIPT_BASH_DOWNLOAD_URL="${GO_SCRIPT_BASH_DOWNLOAD_URL:-${GO_SCRIPT_BASH_REPO_URL%.git}/archive}/$GO_SCRIPT_BASH_VERSION.tar.gz"
# Downloads `GO_SCRIPT_BASH_VERSION` as a tar.gz file and unpacks it.
download_go_script_bash_tarball() {
# GitHub removes the leading 'v' from the archive's output directory.
local unpacked_dir="go-script-bash-${GO_SCRIPT_BASH_VERSION#v}"
local core_dir_parent="${GO_SCRIPT_BASH_CORE_DIR%/*}"
local url="$GO_SCRIPT_BASH_DOWNLOAD_URL"
local protocol="${url%%://*}"
local download_cmd=()
if [[ "$protocol" == "$url" ]]; then
printf 'GO_SCRIPT_BASH_DOWNLOAD_URL has no protocol: %s\n' "$url" >&2
return 1
elif [[ "$(git --version)" =~ windows && "$protocol" == 'file' ]]; then
url="file://$(cygpath -m "${url#file://}")"
fi
if command -v curl >/dev/null; then
download_cmd=(curl -LfsS "$url")
elif command -v fetch >/dev/null; then
download_cmd=(fetch -o - "$url")
elif [[ "$protocol" == 'file' ]] && command -v cat; then
# `wget` can't handle 'file://' urls. Though input redirection would work
# below, this method is consistent with the process substitution logic.
download_cmd=(cat "${url#file://}")
elif command -v wget >/dev/null; then
download_cmd=(wget -O - "$url")
else
printf "Failed to find cURL, wget, or fetch\n" >&2
return 1
fi
if ! command -v tar >/dev/null; then
printf "Failed to find tar\n" >&2
return 1
fi
printf "Downloading framework from '%s'...\n" "$url"
if ! "${download_cmd[@]}" | tar -xzf - ||
[[ "${PIPESTATUS[0]}" -ne '0' ]]; then
printf "Failed to download from '%s'.\n" "$url" >&2
return 1
elif [[ ! -d "$core_dir_parent" ]] && ! mkdir -p "$core_dir_parent" ; then
printf "Failed to create scripts dir '%s'\n" "$core_dir_parent" >&2
rm -rf "$unpacked_dir"
return 1
elif ! mv "$unpacked_dir" "$GO_SCRIPT_BASH_CORE_DIR"; then
printf "Failed to install downloaded directory in '%s'\n" \
"$GO_SCRIPT_BASH_CORE_DIR" >&2
rm -rf "$unpacked_dir"
return 1
fi
printf "Download of '%s' successful.\n\n" "$url"
}
git_clone_go_script_bash() {
printf "Cloning framework from '%s'...\n" "$GO_SCRIPT_BASH_REPO_URL"
if ! git clone --depth 1 -c advice.detachedHead=false \
-b "$GO_SCRIPT_BASH_VERSION" "$GO_SCRIPT_BASH_REPO_URL" \
"$GO_SCRIPT_BASH_CORE_DIR"; then
printf "Failed to clone '%s'; aborting.\n" "$GO_SCRIPT_BASH_REPO_URL" >&2
return 1
fi
printf "Clone of '%s' successful.\n\n" "$GO_SCRIPT_BASH_REPO_URL"
}
if [[ ! -e "$GO_SCRIPT_BASH_CORE_DIR/go-core.bash" ]]; then
if ! download_go_script_bash_tarball; then
printf "Using git clone as fallback\n"
if ! git_clone_go_script_bash; then
exit 1
fi
fi
fi
. "$GO_SCRIPT_BASH_CORE_DIR/go-core.bash" "$GO_SCRIPTS_DIR"
export PATH="node_modules/.bin:$PATH"
if [[ -t 1 || -n "$TRAVIS" ]]; then
_GO_LOG_FORMATTING='true'
fi
. "$_GO_USE_MODULES" 'log'
if [[ -f "$_GO_ROOTDIR/.config/env.local" ]]; then
. "$_GO_ROOTDIR/.config/env.local"
fi
if [[ ! -d "$_GO_ROOTDIR/node_modules" ]]; then
@go.setup_project 'setup'
if [[ "$#" -eq '0' ]]; then
exit
fi
fi
@go "$@"