-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·159 lines (133 loc) · 3.92 KB
/
start.sh
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh
atput() {
[ -z "$TERM" ] && return 0
eval "tput $@"
}
format() {
echo "$@" | sed "
s/%{bold}/$(atput bold)/g;
s/%{underline}/$(atput smul)/g;
s/%{green}/$(atput setaf 2)/g;
s/%{yellow}/$(atput setaf 3)/g;
s/%{red}/$(atput setaf 1)/g;
s/%{blue}/$(atput setaf 4)/g;
s/%{reset}/$(atput sgr0)/g;
s/%{[a-z]*}//g;
"
}
command_exists() {
which ${@} > /dev/null 2>&1
}
match() {
if [ $# != 2 ]; then return 1; fi
echo "${1}" | grep -qE "${2}"
}
curl_or_wget() {
CURL_BIN="curl"; WGET_BIN="wget"
if command_exists ${CURL_BIN}; then
echo "${CURL_BIN} -sL"
elif command_exists ${WGET_BIN}; then
echo "${WGET_BIN} -qO-"
fi
}
install_or_update_azk() {
echo
${FETCH_CMD} http://www.azk.io/install.sh | bash
}
stop_azk_installation() {
cat <<-EOS
$(format '%{bold}azk%{reset}') installation aborted.
To install azk, just run:
$(format "%{bold}\$ ${FETCH_CMD} http://www.azk.io/install.sh | bash%{reset}")
EOS
exit 4
}
check_azk_installed() {
if ! command_exists $AZK_BIN; then
cat <<-EOS
$(format '%{bold}%{green}Hi!%{reset}') The $( format '%{bold}Run Project button%{reset}') is a feature of $(format '%{bold}azk%{reset}').
$(format '%{bold}azk%{reset}') is an open-source engine to orchestrate development environments.
It seems you don't have $(format "%{bold}$AZK_BIN%{reset}") installed on your machine yet.
EOS
FETCH_CMD=$(curl_or_wget)
if [ -z "${FETCH_CMD}" ]; then
cat <<-EOS
To install $(format "%{bold}$AZK_BIN%{reset}"), please check out our docs at:
$(format '%{bold}%{underline}http://docs.azk.io/en/installation%{reset}')
EOS
exit 1
else
trap stop_azk_installation INT
cat <<-EOS
Installing $(format '%{bold}azk%{reset}') in $(format '%{bold}10 seconds%{reset}').
To prevent its installation, just press CTRL+C now.
EOS
sleep 10
trap - INT
install_or_update_azk
fi
fi
}
azk_is_up_to_date() {
AZK_CURRENT_VERSION=$(azk version | sed -e 's/^azk //; s/^version //; s/,.*//')
AZK_TAGS_URL="https://api.github.com/repos/azukiapp/azk/tags"
AZK_LATEST_VERSION=$( curl -sSL ${AZK_TAGS_URL} | \
grep name | \
head -1 | \
sed 's/[^0-9.]*"v\([0-9.]*\).*",/\1/' )
[ "${AZK_CURRENT_VERSION}" = "${AZK_LATEST_VERSION}" ]
}
skip_azk_update() {
cat <<-EOS
To upgrade $(format '%{bold}azk%{reset}'), just run:
$(format "%{bold}\$ ${FETCH_CMD} http://www.azk.io/install.sh | bash%{reset}")
EOS
SKIP_UPDATE='true'
kill -13 ${SLEEP_PID} > /dev/null 2>&1
}
check_azk_updated() {
if ! azk_is_up_to_date; then
FETCH_CMD=$(curl_or_wget)
if [ ! -z "${FETCH_CMD}" ]; then
trap skip_azk_update INT
cat <<-EOS
$(format "%{bold}azk v${AZK_LATEST_VERSION}%{reset}") is available!
Updating $(format "%{bold}azk%{reset}") in $(format '%{bold}10 seconds%{reset}').
To prevent it, just press CTRL+C now.
EOS
sleep 10 &
SLEEP_PID=$!
wait > /dev/null 2>&1
trap - INT
if [ -z ${SKIP_UPDATE} ]; then
install_or_update_azk
fi
fi
fi
}
check_repo_project() {
HTTPS_REGEX="^https://github.com/[^/]+/[^/]+$"
SSH_REGEX="^[email protected]:[^/]+/[^/]+.git$"
SHORT_REGEX="^[^/]+/[^/]+$"
if ! match ${REPO_PROJECT} "${SHORT_REGEX}|${HTTPS_REGEX}|${SSH_REGEX}"; then
cat <<-EOS
$(format "%{bold}%{yellow}Ops!%{reset}") It seems you haven't copied the whole command.
Please ensure it's complete and try again.
EOS
exit 2
fi
}
AZK_BIN="azk"
REPO_PROJECT="${1}"; shift
check_repo_project
if check_azk_installed && check_azk_updated; then
if match "$(uname -a)" "^Linux\ " && \
! match "$(id -Gn)" "(^|\ )docker(\ |$)" && \
getent group docker > /dev/null 2>&1; then
sg docker -c "azk agent start && echo && azk start -o ${REPO_PROJECT} ${@}"
else
azk agent start && echo && azk start -o ${REPO_PROJECT} ${@}
fi
else
exit 3
fi