forked from redhat-developer/s2i-dotnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-imagestreams.sh
executable file
·156 lines (140 loc) · 3.94 KB
/
install-imagestreams.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
#!/usr/bin/env bash
# Stop script on NZEC
set -e
# Stop script if unbound variable found (use ${var:-} if intentional)
set -u
# By default cmd1 | cmd2 returns exit code of cmd2 regardless of cmd1 success
# This is causing it to fail
set -o pipefail
if [ -t 1 ] && command -v tput > /dev/null; then
# see if it supports colors
ncolors=$(tput colors)
if [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
normal="$(tput sgr0 || echo)"
red="$(tput setaf 1 || echo)"
yellow="$(tput setaf 3 || echo)"
fi
fi
say_warning() {
printf "%b\\n" "${yellow:-}Warning: $1${normal:-}"
}
say_err() {
printf "%b\\n" "${red:-}Error: $1${normal:-}" >&2
}
say() {
printf "%b\\n" "${normal:-}$1"
}
machine_has() {
hash "$1" > /dev/null 2>&1
return $?
}
show_help() {
script_name="$(basename "$0")"
echo "OpenShift .NET Core S2I Installer"
echo "Usage: $script_name"
echo " $script_name --rm"
echo " $script_name -h|-?|--help"
echo ""
echo "$script_name is a script for installing/updating/removing .NET S2I streams."
echo ""
echo "Options:"
echo " --i,--imagestreams Installs the imagestreams from the given path."
echo " --n,--namespace Namespace to add imagestreams to. Defaults to current 'oc' project."
echo " Set this to 'openshift' to install globally (requires admin priviledges)."
echo " --rm Remove the image streams."
echo " -?,--?,-h,--help Shows this help message."
}
get_current_namespace() {
local project
if ! project=$(oc project -q 2>&1); then
say_err "Cannot determine current oc namespace."
exit 1
fi
echo "$project"
}
has_dotnet_imagestream() {
local streams;
if ! streams=$(oc get -n "$namespace" is dotnet 2>&1); then
if [[ "$streams" == *"NotFound"* ]]; then
return 1
fi
say_err "Cannot determine if the project already contains dotnet imagestreams."
exit 1
fi
return 0
}
oc_delete()
{
local output;
if ! output=$(oc delete "$@" -n "$namespace" 2>&1); then
if [[ "$output" == *"NotFound"* ]]; then
return 0
fi
say_err "Cannot delete $*: $output"
return 1
fi
return 0
}
namespace=""
imagestreams_url="https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams.json"
remove=false
while [ $# -ne 0 ]
do
name="$1"
case "$name" in
-n|--namespace)
shift
namespace="$1"
;;
-i|--imagestreams)
shift
imagestreams_url="$1"
;;
--rm)
remove=true
;;
-p|--password|-u|--user|-o|--os)
shift
say "The '$name' argument is obsolete and will be ignored. You can remove it from the command line."
;;
-\?|--\?|-h|--help)
script_name="$(basename "$0")"
show_help
exit 0
;;
*)
say_err "Unknown argument \`$name\`"
exit 1
;;
esac
shift
done
# Check prerequisite tools
prereq_ok=true
if ! machine_has "oc"; then
say_err "oc is required to install image streams. Please install oc."
prereq_ok=false
fi
if [ "$prereq_ok" == false ]; then
exit 1
fi
# Remove
if [ "$remove" == "true" ]; then
say "Removing installed image streams."
oc_delete is dotnet | \
oc_delete is dotnet-runtime | \
oc_delete secret redhat-registry-dotnet-install
exit
fi
# Determine namespace
if [ "$namespace" == "" ]; then
namespace=$(get_current_namespace)
fi
# Install/update imagestreams
if has_dotnet_imagestream; then
say "Updating image streams:"
oc replace -n "$namespace" -f "$imagestreams_url"
else
say "Installing image streams:"
oc create -n "$namespace" -f "$imagestreams_url"
fi