-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-dotnetasp.sh
More file actions
125 lines (104 loc) · 4.08 KB
/
setup-dotnetasp.sh
File metadata and controls
125 lines (104 loc) · 4.08 KB
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
#!/usr/bin/env sh
set -e
set -x
HELPERSPATH="/helpers"
HELPERSCACHE="/helperscache"
DESIREDVERSION="${1}"
if [ "${DESIREDVERSION}" = "" ] ; then
DESIREDVERSION="newest"
fi
ARG_CACHEPATH="${2}"
install_dotnetasp()
{
PARTARCH="$1"
DOTNETASPVERSION="$2"
DOTNETCACHEPATH="$3"
#/helpers/wget-with-retries.sh https://dot.net/v1/dotnet-install.sh "/usr/bin/dotnet-install.sh"
#chmod +x /usr/bin/dotnet-install.sh
#/usr/bin/dotnet-install.sh --channel ${DOTNETASPVERSION} --install-dir "${TARGETPATH}" --verbose --runtime aspnetcore
FILENAME="aspnetcore-runtime-${DOTNETASPVERSION}-linux-${PARTARCH}.tar.gz"
DOWNLOADURL="https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/${DOTNETASPVERSION}/${FILENAME}"
LOCALCACHEDIRECTORY="${DOTNETCACHEPATH}"
if [ -z "${LOCALCACHEDIRECTORY}" ] ; then
LOCALCACHEDIRECTORY="/tmp/dotnetcache"
fi
mkdir -p "${LOCALCACHEDIRECTORY}"
LOCALCACHEFILENAME="${LOCALCACHEDIRECTORY}/${FILENAME}"
#if [ ! tar -tzf "${LOCALCACHEFILENAME}" > /dev/null ] ; then
# rm -f "${LOCALCACHEFILENAME}"
#fi
if [ ! -f "${LOCALCACHEFILENAME}" ] ; then
/helpers/wget-with-retries.sh "${DOWNLOADURL}" "${LOCALCACHEFILENAME}"
fi
[ -f "${LOCALCACHEFILENAME}" ]
TARGETPATH="/opt/dotnet"
mkdir -p "${TARGETPATH}"
tar --no-same-owner -xzf "${LOCALCACHEFILENAME}" -C "${TARGETPATH}"
[ -f "${TARGETPATH}/dotnet" ]
[ -d "${TARGETPATH}/shared/Microsoft.AspNetCore.App/${DOTNETASPVERSION}" ]
if echo ":$PATH:" | grep -v -q ":$TARGETPATH:" ; then
PATH="${TARGETPATH}:${PATH}"
fi
dotnet --info
}
fetch_dotnetasp_version()
{
SUPPORT="$1"
LINENUMBER="$2"
/helpers/wget-with-retries.sh https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json - \
| jq -r '.["releases-index"][] | select(."support-phase"=="'"${SUPPORT}"'") | ."latest-runtime"' \
| sort --version-sort --reverse \
| awk -v n=$LINENUMBER 'NR==n'
}
getversion_dotnetasp()
{
PARTARCH="$1"
SUPPORT="$2"
LINENUMBER="$3"
MAXRETRIES=30
COUNTER=0
SUCCESS=0
DOTNETASPVERSION=""
while [ $SUCCESS -eq 0 ] && [ $COUNTER -lt $MAXRETRIES ] ; do
echo "Retry #$COUNTER" >&2
# Try primary support phase
DOTNETASPVERSION="$(fetch_dotnetasp_version "$SUPPORT" "$LINENUMBER")"
# If support is "preview" and nothing found, try "go-live"
if [ -z "$DOTNETASPVERSION" ] && [ "$SUPPORT" = "preview" ]; then
echo "Preview not found, trying go-live..." >&2
DOTNETASPVERSION="$(fetch_dotnetasp_version "go-live" "$LINENUMBER")"
fi
# fallback to active
if [ -z "$DOTNETASPVERSION" ] && [ "$SUPPORT" = "preview" ]; then
echo "Preview not found, trying active..." >&2
DOTNETASPVERSION="$(fetch_dotnetasp_version "active" "$LINENUMBER")"
fi
if [ "${DOTNETASPVERSION}" != "" ] ; then
SUCCESS=1
else
COUNTER=$(( $COUNTER + 1 ))
sleep 5s
fi
done
[ $SUCCESS -eq 1 ]
[ "${DOTNETASPVERSION}" != "" ]
echo "${DOTNETASPVERSION}"
}
#DOTNETASPVERSION=$(apt-cache search dotnet-sdk | awk '{print $1}' | awk -F- '{print $3}' | sort --version-sort | tail -n 1)
#${HELPERSPATH}/apt-retry-install.sh dotnet-runtime-${DOTNETASPVERSION}
ARCHITECTURE="$(dpkg --print-architecture)"
if [ "${ARCHITECTURE}" = "amd64" ] ; then PARTARCH="x64" ; else if [ "${ARCHITECTURE}" = "arm64" ] ; then PARTARCH="arm64" ; fi ; fi
[ "${PARTARCH}" != "" ]
# selecting the version to use -- newest, preview, previous -- todo: 8.0, 9.0, 10.0
if [ "${DESIREDVERSION}" = "preview" ] ; then
DOTNETASPVERSION="$(getversion_dotnetasp ${PARTARCH} preview 1)"
install_dotnetasp "${PARTARCH}" "${DOTNETASPVERSION}" "${ARG_CACHEPATH}"
elif [ "${DESIREDVERSION}" = "newest" ] || [ "${DESIREDVERSION}" = "" ] ; then
DOTNETASPVERSION="$(getversion_dotnetasp ${PARTARCH} active 1)"
install_dotnetasp "${PARTARCH}" "${DOTNETASPVERSION}" "${ARG_CACHEPATH}"
elif [ "${DESIREDVERSION}" = "previous" ] ; then
DOTNETASPVERSION="$(getversion_dotnetasp ${PARTARCH} active 2)"
install_dotnetasp "${PARTARCH}" "${DOTNETASPVERSION}" "${ARG_CACHEPATH}"
else
install_dotnetsdk "${PARTARCH}" "${DESIREDVERSION}" "${ARG_CACHEPATH}"
fi