forked from idexmai/che
-
Notifications
You must be signed in to change notification settings - Fork 0
/
che.sh
executable file
·161 lines (132 loc) · 3.51 KB
/
che.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
160
161
#!/bin/bash
# Copyright (c) 2012-2016 Codenvy, S.A.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Tyler Jewell - Initial Implementation
#
init_logging() {
BLUE='\033[1;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[38;5;220m'
NC='\033[0m'
# Which che CLI version to run?
DEFAULT_CHE_CLI_VERSION="latest"
CHE_CLI_VERSION=${CHE_CLI_VERSION:-${DEFAULT_CHE_CLI_VERSION}}
# Name used in CLI statements
DEFAULT_CHE_MINI_PRODUCT_NAME="che"
CHE_MINI_PRODUCT_NAME=${CHE_MINI_PRODUCT_NAME:-${DEFAULT_CHE_MINI_PRODUCT_NAME}}
# Turns on stack trace
DEFAULT_CHE_CLI_DEBUG="false"
CHE_CLI_DEBUG=${CHE_CLI_DEBUG:-${DEFAULT_CHE_CLI_DEBUG}}
# Activates console output
DEFAULT_CHE_CLI_INFO="true"
CHE_CLI_INFO=${CHE_CLI_INFO:-${DEFAULT_CHE_CLI_INFO}}
# Activates console warnings
DEFAULT_CHE_CLI_WARN="true"
CHE_CLI_WARN=${CHE_CLI_WARN:-${DEFAULT_CHE_CLI_WARN}}
}
warning() {
if is_warning; then
printf "${YELLOW}WARN:${NC} %s\n" "${1}"
fi
}
info() {
if is_info; then
printf "${GREEN}INFO:${NC} %s\n" "${1}"
fi
}
debug() {
if is_debug; then
printf "\n${BLUE}DEBUG:${NC} %s" "${1}"
fi
}
error() {
printf "${RED}ERROR:${NC} %s\n" "${1}"
}
is_warning() {
if [ "${CHE_CLI_WARN}" = "true" ]; then
return 0
else
return 1
fi
}
is_info() {
if [ "${CHE_CLI_INFO}" = "true" ]; then
return 0
else
return 1
fi
}
is_debug() {
if [ "${CHE_CLI_DEBUG}" = "true" ]; then
return 0
else
return 1
fi
}
has_docker() {
hash docker 2>/dev/null && return 0 || return 1
}
check_docker() {
if ! has_docker; then
error "Error - Docker not found. Get it at https://docs.docker.com/engine/installation/."
return 1;
fi
if ! docker ps > /dev/null 2>&1; then
output=$(docker ps)
error "Error - Docker not installed properly: \n${output}"
return 1;
fi
# Prep script by getting default image
if [ "$(docker images -q alpine 2> /dev/null)" = "" ]; then
info "Pulling image alpine:latest"
docker pull alpine > /dev/null 2>&1
fi
if [ "$(docker images -q appropriate/curl 2> /dev/null)" = "" ]; then
info "Pulling image curl:latest"
docker pull appropriate/curl > /dev/null 2>&1
fi
}
curl () {
docker run --rm appropriate/curl "$@"
}
update_che_cli() {
info "Downloading cli-$CHE_CLI_VERSION"
CLI_DIR=~/."${CHE_MINI_PRODUCT_NAME}"/cli
test -d "${CLI_DIR}" || mkdir -p "${CLI_DIR}"
if [[ "${CHE_CLI_VERSION}" = "latest" ]] || \
[[ "${CHE_CLI_VERSION}" = "nightly" ]] || \
[[ ${CHE_CLI_VERSION:0:1} == "4" ]]; then
GITHUB_VERSION=master
else
GITHUB_VERSION=$CHE_CLI_VERSION
fi
URL=https://raw.githubusercontent.com/eclipse/che/$GITHUB_VERSION/cli.sh
if ! curl --output /dev/null --silent --head --fail "$URL"; then
error "CLI download error. Bad network or version. CLI update works for 5.0.0-M3+."
return 1;
else
curl -sL $URL > ~/."${CHE_MINI_PRODUCT_NAME}"/cli/cli-$CHE_CLI_VERSION.sh
fi
}
init() {
init_logging
check_docker
# Test to see if we have cli_funcs
if [ ! -f ~/."${CHE_MINI_PRODUCT_NAME}"/cli/cli-${CHE_CLI_VERSION}.sh ]; then
update_che_cli
fi
source ~/."${CHE_MINI_PRODUCT_NAME}"/cli/cli-${CHE_CLI_VERSION}.sh
init_global_variables
}
# See: https://sipb.mit.edu/doc/safe-shell/
set -e
set -u
init
parse_command_line "$@"
execute_cli "$@"